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: 17th May 2024. Market News – Asian and European futures followed Wall Street lower. Economic Indicators & Central Banks:   The Dow topped 40,000 for the first time ever, but was unable to close with that historic handle. Concurrently, the S&P tried for its 24th record high this year but failed too. The rise in Treasury yields after stronger than expected import prices, and a drumbeat from Fed officials that rates need to remain high for longer, encouraged profit taking. Most Asian equity markets and European futures have followed Wall Street lower, after US data dented rate cut hikes. Chinese data showing slowed consumption and a drop in home sales, although industrial production numbers looked relatively robust. Japan’s core consumer inflation slowed for a 2nd month in a row in April from a year earlier, while the core consumer prices index (CPI) is expected to decelerate to 2.2% from 2.6% in March, the lowest level in 3 months, but still at or above the central bank’s 2% target for more than two years. Financial Markets Performance: The USDIndex firmed slightly to 104.518 and up from the day’s nadir of 104.080. But it held a 104 handle for a second straight day. It traded above the 105 level from April 10 until May 15. Silver has surged nearly 25% this year, outpacing Gold and becoming a top-performing commodity, though it remains relatively inexpensive compared to gold. Both metals have hit record highs due to central-bank buying and increased interest in China. USOil is 0.75% higher at $79.23. Market Trends:   All three major US indexes closed slightly in the red after posting all-time highs on Wednesday. The NASDAQ closed with a -0.26% decline, while the S&P500 lost -0.21%, and the Dow was off -0.1% at 39,869. It was a corrective day for Treasuries too. Bonds unwound part of their recent rally that took rates down to the lows since early April. 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 on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Andria Pichidi Market Analyst 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.
    • GOTU Gaotu Techedu stock breakout, https://stockconsultant.com/?GOTU
    • FSLR First Solar stock bull flag breakout watch, https://stockconsultant.com/?FSLR
    • VLO Valero Energy stock attempting to move higher off the 156.97 support area, high trade quality, https://stockconsultant.com/?VLO
    • RCL Royal Caribbean stock top of range breakout watch , https://stockconsultant.com/?RCL
×
×
  • Create New...

Important Information

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