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

    • ADMA Adma Biologics stock, watch for a range breakout, target 26 area at https://stockconsultant.com/?ADMA
    • URI United Rentals stock, nice rally off 829 support area, watch for top of range breakout at https://stockconsultant.com/?URI
    • Date: 27th November 2024. S&P500 at its 52nd new peak for 2024; USD Firmer, Kiwi & Yen Up. Asia & European Sessions: Wall Street rallied into the close with the S&P500 and Dow registering more record highs with the S&P500 climbing 0.57% to 6045, its 52nd new peak for 2024. The Dow rose 0.28% to 44,860.3 for its 46th record of the year. The NASDAQ advanced 0.63%. Trump named Jamieson Greer as the US Trade Representative and Kevin Hassett to direct the National Economic Council. Greer was intimately involved in Trump’s first-term trade policy decisions. President Biden announced Israel and Hezbollah have reached a cease fire. Over the next 60 days the Lebanese army and state security will take control of their own territory and Israel will gradually withdraw its forces. FOMC minutes: Minutes from the Fed’s latest policy meeting revealed officials leaning toward a cautious approach to future rate cuts. All agreed to cut the rate by -25 bps and nearly all thought risks between achieving employment and inflation goals were “roughly in balance.” Upside risks to the inflation outlook were little changed, and while inflation had eased, it remained elevated. The implied December rate continues to hover around a 50-50 bet as we await the PCE price data Wednesday and the crucial jobs report on December 6. The January 2025 rate is priced for a total of 20 bps in cuts, with -75 bps by January 2026. RBNZ cut its cash rate by 50 bps, yet the Kiwi gained as traders analyzed the central bank’s rate outlook and the governor’s remarks. Chinese government approved a 500 billion yuan ($69 billion) bond quota, enabling two state-owned asset managers to issue bonds for funding projects aimed at spurring economic growth. Today: US inflation and economic growth may provide clues to the Federal Reserve’s next policy move. Financial Markets Performance: The USDIndex has dropped to currently 106.459. The Yen climbed with USDJPY pulling back to 151.82, while NZDUSD jumped to 0.5900 despite the RBNZ’s 50 bps rate cut. Oil prices stabilized at $68.84, with optimism over delayed OPEC+ output increases balancing the reduced geopolitical risk stemming from the ceasefire. Gold rebounds to 2653.54, with next Resistance at 2660-2664. 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.
    • RBLX Roblox stock, pull back to 49.2 gap support area at https://stockconsultant.com/?RBLX
    • UHS Universal Health Services stock, nice rally off the 197 support area, from Stocks to Watch at https://stockconsultant.com/?UHS
×
×
  • Create New...

Important Information

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