Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

GRANDEUR

Eliminating Repeated Trades

Recommended Posts

Recently, I tried to figure out how one can backtest day-strategy on smaller timeframes in order to eveluate an optimal stoploss. I was given a piece of advice to use a function 'entriestoday(date)<1'. It works fine to me.

Then I tried to implement something similar to an Hour-strategy. I tried to backtest it on 5-min timeframe. But, unfortunately, 'entriestoday(date)<1' doesn't work properly in that case.

Taking into account all written above, please help me to recode the following simple strategy so that I can backtest a stoploss amount:

 

inputs: x(100);

 

buy next bar at h stop;

setstopposition;

setstoploss(x);

 

sell short next bar at l stop;

setstopposition;

setstoploss(x);

 

Thank you in advance!

Share this post


Link to post
Share on other sites
...

Taking into account all written above, please help me to recode the following simple strategy so that I can backtest a stoploss amount:

...

Thank you in advance!

 

 

if you can rewrite the above in the following format, I might be able to give you a hand:

 

1. write out your thoughts ONE logic PER LINE

2. write out your logic ONE action per LINE

3. write out your action ONE sentence per LINE

4. start a NEW LINE for every sentence

Share this post


Link to post
Share on other sites

Sure)

 

There is a 60-min strategy:

Buy at the high of the previous 60-min bar on stop.

Sell at the low of the previous 60-min bar on stop.

Anytime there is an open position, place a stoploss.

That is it.

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

Share this post


Link to post
Share on other sites
Sure)

 

There is a 60-min strategy:

Buy at the high of the previous 60-min bar on stop.

Sell at the low of the previous 60-min bar on stop.

Anytime there is an open position, place a stoploss.

That is it.

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

 

 

h[1] = high of the previous bar

 

EasyLanguage works on bar-by-bar basis; it doesn't matter what is the bar resolution...

Share this post


Link to post
Share on other sites
...

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

 

 

what do you mean by "impossible" ?

 

your stop loss is too small?

it triggers too soon?

not triggered at all?

etc...

Share this post


Link to post
Share on other sites
Sure)

 

There is a 60-min strategy:

Buy at the high of the previous 60-min bar on stop.

Sell at the low of the previous 60-min bar on stop.

Anytime there is an open position, place a stoploss.

That is it.

 

I want to eveluate the best stoploss value.

It's impossible to eveluate it on 60-min bars.

Various stoploss values must be tested on smaller timeframe bars.

What code will let eveluate an optimized stoploss value?

 

You are using a position based stoploss, so if it is set to say $500 and the trade goes against you then it will be stopped when the total position has made $500 loss, regardless of the data compression (time period of bars used).

 

I suspect that what you are trying to do is to set the stoploss to be based upon the price movement expected in the time period (data compression) being used e.g. to base it upon the bar range or the ATR.

 

If that is what you are trying to do then it is probably easier (from a visualisation viewpoint) to use SETSTOPSHARE. This sets the amount per share or contract. The important point is that it does not need to be a fixed amount.

 

You can have an input or variable called, say, SL_AMOUNT. Then you have the code

 

SETSTOPSHARE;

SETSTOPLOSS(SL_AMOUNT);

 

This will set the stop loss per share/contract to be the amount the input or variable contains.

 

So you could set it to ATR

 

SL_AMOUNT = AvgTrueRange(10);

 

 

This would set it to the average true range based on 10 bars for the time interval (data compression) chosen in the plot. In other words the ATR and hence the SL_AMOUNT and hence the stop loss would vary according to the data compression.

 

You could also use an IF statement to set it to specific values based on bar type and interval

 

e;g. IF BARTYPE = 1 AND BARINTERVAL = 10 then SL_AMOUNT = 5;

 

This would set the stop loss amount to 5 for a 10 min intraday bar.

 

 

BARTYPE values are

 

0 = TickBar

1 = Intraday

2 = Daily

3 = Weekly

4 = Monthly

5 = Point & Figure

6 = (reserved)

7 = (reserved)

8 = Kagi

9 = Kase

10 = Line Break

11 = Momentum

12 = Range

13 = Renko

 

Personally however I would recommend using something like a volatility based stopped such as ATR which would automatically select stoploss levels at a basis appropirate to the time interval being traded. You don't have to think about it then.

 

Finally another possibility of course is to set a stop loss based on 1 time interval but to use it in a stategy based on another interval. For example you could have a strategy entered onto a 1 min chart, which uses an ATR taken from a 10 min chart, but that's a whole new thread on multiple data feeds and potentially GVs, ADEs and so on, which I don't want to go into at present.

 

 

Charlton

Share this post


Link to post
Share on other sites

Thank you for your replies!

But it seems to me that you haven't understood what I was asking for. Let me express my question by images. Image.gif?tsid=20091211-133231-9ec08099&forceAttachmentDownload=true

On the first chart there are 60-min bars. And the code for the strategy used is:

buy next bar at h stop;

setstopposition;

setstoploss(500);

sell short next bar at l stop;

setstopposition;

setstoploss(500);

 

On the second chart there are two data feeds: 5-min and 60-min. The code for the strategy is:

buy next bar at h of data2 stop;

setstopposition;

setstoploss(300);

sell short next bar at l of data2 stop;

setstopposition;

setstoploss(300);

 

So I want to trade on 60-min bars but I want also to verify wether my stoplosses are not executed inside 60-min bars.

 

On the third chart is a magnification of chart #2. One can see there that there were several trades inside one 60-min bar that shouldn't take place.

Share this post


Link to post
Share on other sites

Tams, thank you for your reply! But it seems to me, there is still some misunderstanding.

'Position limits' is used when you don't want to make buy #1 and afterwards buy #2, for examle. It doesn't solve the problem in my case: buy #1 then comes a stoploss (so there are no positions at the time), then comes another buy #1 and there comes another stoploss and so on ALL INSIDE ONE 60-MIN BAR.

I want that there would be no more than one buy/sell trade and one cover-trade inside a 60-min bar.

Share this post


Link to post
Share on other sites
Tams, thank you for your reply! But it seems to me, there is still some misunderstanding.

'Position limits' is used when you don't want to make buy #1 and afterwards buy #2, for examle. It doesn't solve the problem in my case: buy #1 then comes a stoploss (so there are no positions at the time), then comes another buy #1 and there comes another stoploss and so on ALL INSIDE ONE 60-MIN BAR.

I want that there would be no more than one buy/sell trade and one cover-trade inside a 60-min bar.

 

 

I would suggest you to draw a flow chart to illustrate your logic.

 

the branches should include ALL THE PERMUTATIONS.

 

324px-LampFlowchart.svg.png

Share this post


Link to post
Share on other sites
Tams, thank you for your reply! But it seems to me, there is still some misunderstanding.

'Position limits' is used when you don't want to make buy #1 and afterwards buy #2, for examle. It doesn't solve the problem in my case: buy #1 then comes a stoploss (so there are no positions at the time), then comes another buy #1 and there comes another stoploss and so on ALL INSIDE ONE 60-MIN BAR.

I want that there would be no more than one buy/sell trade and one cover-trade inside a 60-min bar.

 

If you follow Tams advice of drawing out the logic think about:

 

(a) How you might count whether an initiating trade took place during a bar

(b) How you reset the count to zero when a new bar forms

© How you know if there are currently any open positions in play during this bar

 

 

Charlton

Share this post


Link to post
Share on other sites
Guys, I'm sorry for my incomprehensible style of writing. I thought I expressed myself clearly but seems it was not.

So, here is another attempt of mine.

7f6a3e4ac8fbe6bc14763edc3e87c2eb

 

 

your picture is not showing.

 

you can load the picture directly to TradersLaboratory.

Just click the Manage Attachments button under the Advanced reply window.

Share this post


Link to post
Share on other sites

For TradeStation, get the ebook EasyLanguage Essentials Programmers Guide (free)

 

read up on Look-Inside-Bar-Back-testing (LIBB).

 

 

 

For MultiCharts, use Backtesting Precision. (same function as LIBB)

 

You are back testing on 60 min bars,

and using a finer resolution (e.g. 1 tick data) as back testing precision.

 

 

attachment.php?attachmentid=16585&stc=1&d=1260795941

Backtesting_Precision.gif.8d5de67b56a6a445e83b4515f630b33f.gif

Edited by Tams

Share this post


Link to post
Share on other sites
Tams, I am using Multicharts but I don't see the 'Backtesting Precision' tab in my 'Strategy Properties'.

Maybe, this tab appeared in a new version? I have 5.0 Beta.

 

 

.......... time to upgrade !

Share this post


Link to post
Share on other sites

I' m sorry for delays in my replies. I got a newer version of MultiCharts. It's become much easier with that new feature but it's not all obvious though. It doesn't work properly with some of my strategies. Now I'm trying to figure it all out for myself.

Tams, thank you very much for your help!

Share this post


Link to post
Share on other sites
I' m sorry for delays in my replies. I got a newer version of MultiCharts. It's become much easier with that new feature but it's not all obvious though. It doesn't work properly with some of my strategies. Now I'm trying to figure it all out for myself.

Tams, thank you very much for your help!

 

 

.......... you are welcome !

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Topics

  • Posts

    • Date: 22nd November 2024.   BTC flirts with $100K, Stocks higher, Eurozone PMI signals recession risk.   Asia & European Sessions:   Geopolitical risks are back in the spotlight on fears of escalation in the Ukraine-Russia after Russia reportedly used a new ICBM to retaliate against Ukraine’s use of US and UK made missiles to attack inside Russia. The markets continue to assess the election results as President-elect Trump fills in his cabinet choices, with the key Treasury Secretary spot still open. The Fed’s rate path continues to be debated with a -25 bp December cut seen as 50-50. Earnings season is coming to an end after mixed reports, though AI remains a major driver. Profit taking and rebalancing into year-end are adding to gyrations too. Wall Street rallied, led by the Dow’s 1.06% broadbased pop. The S&P500 advanced 0.53% and the NASDAQ inched up 0.03%. Asian stocks rose after  Nvidia’s rally. Nikkei added 1% to 38,415.32 after the Tokyo inflation data slowed to 2.3% in October from 2.5% in the prior month, reaching its lowest level since January. The rally was also supported by chip-related stocks tracked Nvidia. Overnight-indexed swaps indicate that it’s certain the Reserve Bank of New Zealand will cut its policy rate by 50 basis points on Nov. 27, with a 22% chance of a 75 basis points reduction. European stocks futures climbed even though German Q3 GDP growth revised down to 0.1% q/q from the 0.2% q/q reported initially. Cryptocurrency market has gained approximately $1 trillion since Trump’s victory in the Nov. 5 election. Recent announcement for the SEC boosted cryptos. Chair Gary Gensler will step down on January 20, the day Trump is set to be inaugurated. Gensler has pushed for more protections for crypto investors. MicroStrategy Inc.’s plans to accelerate purchases of the token, and the debut of options on US Bitcoin ETFs also support this rally. Trump’s transition team has begun discussions on the possibility of creating a new White House position focused on digital asset policy.     Financial Markets Performance: The US Dollar recovered overnight and closed at 107.00. Bitcoin currently at 99,300,  flirting with a run toward the 100,000 level. The EURUSD drifts below 1.05, the GBPUSD dips to June’s bottom at 1.2570, while USDJPY rebounded to 154.94. The AUDNZD spiked to 2-year highs amid speculation the RBNZ will cut the official cash rate by more than 50 bps next week. Oil surged 2.12% to $70.46. Gold spiked to 2,697 after escalation alerts between Russia and Ukraine. Heightened geopolitical tensions drove investors toward safe-haven assets. Gold has surged by 30% this year. Haven demand balanced out the pressure from a strong USD following mixed US labor data. Silver rose 0.9% to 31.38, while palladium increased by 0.9% to 1,040.85 per ounce. Platinum remained unchanged. Always trade with strict risk management. Your capital is the single most important aspect of your trading business.   Please note that times displayed based on local time zone and are from time of writing this report.   Click HERE to access the full HFM Economic calendar.   Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding of how markets work. Click HERE to register for FREE!   Click HERE to READ more Market news. Andria Pichidi HFMarkets Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • A few trending stocks at support BAM MNKD RBBN at https://stockconsultant.com/?MNKD
    • BMBL Bumble stock watch, pull back to 7.94 support area with high trade quality at https://stockconsultant.com/?BMBL
    • LUMN Lumen Technologies stock watch, pull back to 7.43 support area with bullish indicators at https://stockconsultant.com/?LUMN
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.