Back-testing of Demar TD Sequential
Forums › ProRealTime English forum › ProOrder support › Back-testing of Demar TD Sequential
- This topic has 22 replies, 3 voices, and was last updated 2 years ago by jonpt88.
-
-
10/07/2022 at 6:44 PM #202089
Dear all,
As you may know in the pro-real library there is a Demark TD Sequential available: link: https://www.prorealcode.com/prorealtime-indicators/td-sequential-setup/
Well, I have been trying to create a code to back test the Demark TD, but I am not able to create it, i thought (and I would very much appreciate) if any of you here could post the back-test code of a Demark TD simply. Would that be possible? Thank you so much in advance.
10/08/2022 at 4:37 PM #202109Hi @jonpt88
You can do a simple conversion from an indicator to a trading system by removing the “draw elements” and adding buy and sell options
TD Sequential System12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879DefParam CumulateOrders = Falseonce TDSL=0once TDSS=0once BuySetup=0once SellSetup=0Once BuyCountdown=0once SellCountdown=0if close[1]>close[5] and close<close[4] thenbearishflip=1bullishflip=0elsif close[1]<close[5] and close>close[4] thenbullishflip=1bearishflip=0endifif close<close[4] and bearishflip thenTDSL=TDSL+1TDSS=0elsif close>close[4] and bullishflip thenTDSS=TDSS+1TDSL=0endif//if TDSL>0 and TDSL<10 then//drawtext("#TDSL#",barindex,low-10*pipsize) coloured(0,255,0)//endifif TDSL=9 thenL=(low<low[3] and low<low[2]) or (low[1]<low[2] and low[1]<low[3])bearishflip=0TDSL=0BuySetup=1if L then//DRAWARROWUP(barindex,low-20*pipsize) coloured(0,255,0)Buy 1 Contract at Marketendifendifif TDSS>0 and TDSS<10 then//drawtext("#TDSS#",barindex,high+10*pipsize) coloured(255,0,0)endifif TDSS=9 thenS=(high>high[2] and high>high[3]) or (high[1]>high[3] and high[1]>high[2])bullishflip=0TDSS=0SellSetup=1if S then//DRAWARROWDOWN(barindex,high+20*pipsize) coloured(255,0,0)SellShort 1 Contract at Marketendifendifif BuySetup thenif close<=low[2] thenBuyCountdown=BuyCountdown+1//drawtext("#BuyCountdown#",barindex,low-10*pipsize) coloured(0,0,255)endifif BuyCountdown=8 thenBar8=barindexelsif BuyCountdown=13 then // TD Countdown perfection buyif low<=close[barindex-Bar8] then//DRAWARROWUP(barindex,low-20*pipsize) coloured(0,0,255)Buy 1 Contract at MarketendifBuySetup=0BuyCountdown=0endifelsif SellSetup thenif close>=high[2] thenSellCountdown=SellCountdown+1//drawtext("#SellCountdown#",barindex,high+10*pipsize) coloured(0,0,255)endifif SellCountdown=8 thenBar8=barindexelsif SellCountdown=13 then //TD Countdown perfection sellif high>=close[barindex-Bar8] then//DRAWARROWDOWN(barindex,high+20*pipsize) coloured(0,0,255)SellShort 1 Contract at MarketendifSellSetup=0SellCountdown=0endifendif1 user thanked author for this post.
10/08/2022 at 5:19 PM #20211210/08/2022 at 5:37 PM #202113You are always so helpful 🙂 Thank you again! Looks very nice. And, how would that combine with heikin-ashi signals, I mean how would the back test code look like. Looking at the chart looks promising…Apologies, I jus the post was published twice… Sorry for that.
10/08/2022 at 10:47 PM #202124Hi @jonpt88
If you want to use the code with Heikin Ashi, you have to change the following:
Close => HAClose = (Open + High + Low + Close) / 4
Open => HAOpen = (Open[1] + Close[1]) / 2
High => HAHigh = Max(High, Open, Close)
Low => HALow = Low(Low, Open, Close)1 user thanked author for this post.
10/09/2022 at 8:22 AM #202128Hello JS,
Thank you. I think I should have specified better:
What I meant is that:
Demark bullish signal + first (after demark bullish signal) heikin ashi green candle = buy
Demark bearish signal + first (after demark bearish signal) Heikin ashi red candle = sell
Demark bearish signal + first (after demark bearish signal) Heikin ashi red candle = short
Demark bullish signal + first (after demark bullish signal) heikin ash green candle = close short.
10/09/2022 at 12:04 PM #202139Sorry for a second message in a row.
Meanwhile I tried to combine them as I detailed above but I must be doing something wrong as no result appears… Let me clarify, a lot of times the Demark signal coincides with a bearish HA candle. However, what I want to do is back test of Demark as first condition + HA candle = such condition could take days (in daily chart to confirm) but it does not necessarily means that both conditions occur on the same date. If that make sense.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091DefParam CumulateOrders = Falseonce TDSL=0once TDSS=0once BuySetup=0once SellSetup=0Once BuyCountdown=0once SellCountdown=0if close[1]>close[5] and close<close[4] thenbearishflip=1bullishflip=0elsif close[1]<close[5] and close>close[4] thenbullishflip=1bearishflip=0endifif close<close[4] and bearishflip thenTDSL=TDSL+1TDSS=0elsif close>close[4] and bullishflip thenTDSS=TDSS+1TDSL=0endif// Heikin Ashi setuponce xOpen = openxClose = (open + close + high + low) / 4if barindex > 0 thenxOpen = (xOpen + xClose[1]) / 2endifxLow = min(low,min(xClose,xOpen))xHigh = max(high,max(xClose,xOpen))//Bullish = xClose > xOpenBearish = xClose < xOpen//if TDSL>0 and TDSL<10 then//drawtext("#TDSL#",barindex,low-10*pipsize) coloured(0,255,0)//endifif TDSL=9 thenL=(low<low[3] and low<low[2]) or (low[1]<low[2] and low[1]<low[3])bearishflip=0TDSL=0BuySetup=1if L and (Bullish AND Bearish[1])then//DRAWARROWUP(barindex,low-20*pipsize) coloured(0,255,0)Buy 1 Contract at Marketendifendifif TDSS>0 and TDSS<10 then//drawtext("#TDSS#",barindex,high+10*pipsize) coloured(255,0,0)endifif TDSS=9 thenS=(high>high[2] and high>high[3]) or (high[1]>high[3] and high[1]>high[2])bullishflip=0TDSS=0SellSetup=1if S and (Bearish AND Bullish[1]) then//DRAWARROWDOWN(barindex,high+20*pipsize) coloured(255,0,0)SellShort 1 Contract at Marketendifendifif BuySetup thenif close<=low[2] thenBuyCountdown=BuyCountdown+1//drawtext("#BuyCountdown#",barindex,low-10*pipsize) coloured(0,0,255)endifif BuyCountdown=8 thenBar8=barindexelsif BuyCountdown=13 then // TD Countdown perfection buyif low<=close[barindex-Bar8] and (Bullish AND Bearish[1])then//DRAWARROWUP(barindex,low-20*pipsize) coloured(0,0,255)Buy 1 Contract at MarketendifBuySetup=0BuyCountdown=0endifelsif SellSetup thenif close>=high[2] thenSellCountdown=SellCountdown+1//drawtext("#SellCountdown#",barindex,high+10*pipsize) coloured(0,0,255)endifif SellCountdown=8 thenBar8=barindexelsif SellCountdown=13 then //TD Countdown perfection sellif high>=close[barindex-Bar8] and (Bearish AND Bullish[1]) then//DRAWARROWDOWN(barindex,high+20*pipsize) coloured(0,0,255)SellShort 1 Contract at MarketendifSellSetup=0SellCountdown=0endifendif10/09/2022 at 5:14 PM #20221210/09/2022 at 5:26 PM #202213Thank you for being always so helpful, JS.
I was going nuts with the code. I have amended as you suggested but unfortunately I get no equity curve at all now… Is the amended you have suggested valid for the idea as follows:
Demark bullish signal + first (after demark bullish signal) heikin ashi green candle = buy
Demark bearish signal + first (after demark bearish signal) Heikin ashi red candle = sell
Demark bearish signal + first (after demark bearish signal) Heikin ashi red candle = short
Demark bullish signal + first (after demark bullish signal) heikin ash green candle = close short.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091DefParam CumulateOrders = Falseonce TDSL=0once TDSS=0once BuySetup=0once SellSetup=0Once BuyCountdown=0once SellCountdown=0if close[1]>close[5] and close<close[4] thenbearishflip=1bullishflip=0elsif close[1]<close[5] and close>close[4] thenbullishflip=1bearishflip=0endifif close<close[4] and bearishflip thenTDSL=TDSL+1TDSS=0elsif close>close[4] and bullishflip thenTDSS=TDSS+1TDSL=0endif// Heikin Ashi setuponce xOpen = openxClose = (open + close + high + low) / 4if barindex > 0 thenxOpen = (xOpen[1] + xClose[1]) / 2endifxLow = min(low,min(xClose,xOpen))xHigh = max(high,max(xClose,xOpen))//Bullish = xClose > xOpenBearish = xClose < xOpen//if TDSL>0 and TDSL<10 then//drawtext("#TDSL#",barindex,low-10*pipsize) coloured(0,255,0)//endifif TDSL=9 thenL=(low<low[3] and low<low[2]) or (low[1]<low[2] and low[1]<low[3])bearishflip=0TDSL=0BuySetup=1if L and (Bullish AND Bearish[1])then//DRAWARROWUP(barindex,low-20*pipsize) coloured(0,255,0)Buy 1 Contract at Marketendifendifif TDSS>0 and TDSS<10 then//drawtext("#TDSS#",barindex,high+10*pipsize) coloured(255,0,0)endifif TDSS=9 thenS=(high>high[2] and high>high[3]) or (high[1]>high[3] and high[1]>high[2])bullishflip=0TDSS=0SellSetup=1if S and (Bearish AND Bullish[1]) then//DRAWARROWDOWN(barindex,high+20*pipsize) coloured(255,0,0)SellShort 1 Contract at Marketendifendifif BuySetup thenif close<=low[2] thenBuyCountdown=BuyCountdown+1//drawtext("#BuyCountdown#",barindex,low-10*pipsize) coloured(0,0,255)endifif BuyCountdown=8 thenBar8=barindexelsif BuyCountdown=13 then // TD Countdown perfection buyif low<=close[barindex-Bar8] and (Bullish AND Bearish[1])then//DRAWARROWUP(barindex,low-20*pipsize) coloured(0,0,255)Buy 1 Contract at MarketendifBuySetup=0BuyCountdown=0endifelsif SellSetup thenif close>=high[2] thenSellCountdown=SellCountdown+1//drawtext("#SellCountdown#",barindex,high+10*pipsize) coloured(0,0,255)endifif SellCountdown=8 thenBar8=barindexelsif SellCountdown=13 then //TD Countdown perfection sellif high>=close[barindex-Bar8] and (Bearish AND Bullish[1]) then//DRAWARROWDOWN(barindex,high+20*pipsize) coloured(0,0,255)SellShort 1 Contract at MarketendifSellSetup=0SellCountdown=0endifendif10/09/2022 at 10:01 PM #202234I get no equity curve at all now
You don’t state an Instrument or a Timeframe (?), so attached is what I get (with code posted above, no changes) on DJI over 10K bars, TF = 3 min, spread = 5
1 user thanked author for this post.
10/10/2022 at 6:18 AM #202241Hi Grahal,
Thank you for your participation and helpful reply. The equity curve does look promising, indeed.
Unfortunately, I do not get results. I must be doing something wrong. Would you be so kind to post the entire code that you are using?
That would be very much appreciated.
Thank you in advance,
10/10/2022 at 6:29 AM #202242Also I have tried to edit the post and include further comments, but suddenly it was to late and hence I need to write a second post. Meanwhile, I manage to also get an equity curve. However, I am unsure if the strategy is following the following logic:
Demark bullish signal + first (after demark bullish signal) heikin ashi green candle = buy
Demark bearish signal + first (after demark bearish signal) Heikin ashi red candle = sell
Demark bearish signal + first (after demark bearish signal) Heikin ashi red candle = short
Demark bullish signal + first (after demark bullish signal) heikin ash green candle = close short.
—
As said, first signal as a condition of the second signal and not necessarily simultaneously.10/10/2022 at 9:20 AM #20224610/10/2022 at 8:46 PM #202276Thanks, Grahal: To recap:
Only small time frames work. No daily time frame.
I think this why: the long / short etc are triggered only when e.g. green HA coincides with Demark bullish.Nevertheless, the idea is that: first Demark Bullish (as first condition), and then once the HA is green – to trigger the long position. Following this logic –> once the bearish demark (first condition), and once the red heikin ashi to trigger the close and short position, and so on. Instead, from what I see that is not what the code is doing. I read somewhere that to supedite one condition to the other one needs to create a “flag”(?), this exceeds by far my skills (which aare nill -I am total beginner – I am a pre-beginner… I am 0 at this. I did not even understand the flag idea on the training video :(.
Thank you for your understanding and help, of course, only if you deem that I can receive it.
10/10/2022 at 10:07 PM #202277I’m not the best at coding, but I manage to do all I require for myself as I can check it out by backtesting and checking using GRAPH etc.
Above can be time consuming and is best undertaken by the code Author or somebody convinced it is worth the time … i.e. going to make money at the end of all the analysis.
from what I see that is not what the code is doing
You can safely assume that the code will correctly execute as it is correctly written.
GRAPH LongTriggered
Did you do above?
You can then set up the Indicators which are used in the code in order to check it all works as it should.
Here you are, I’ve got you started as to how to do it … see attached! The red arrowhead is pointing at a 1st green HAshi candle following red HAshi candles.
You now set up as attached and also set up the first Demark Bullish (as first condition)?
-
AuthorPosts