Indicator and Backtest, same algorithm, Backtest out by a day
Forums › ProRealTime English forum › ProOrder support › Indicator and Backtest, same algorithm, Backtest out by a day
- This topic has 4 replies, 3 voices, and was last updated 6 years ago by capngoggles.
-
-
01/01/2018 at 11:53 AM #56988
Happy New Year everyone. I was hoping someone can clear my illogical thinking please.
I have a simple algorithm that works as an indicator as expected but when implemented as a backtest it
flags the buy and sell a day later than it should. Its probably my coding or I’ve made an incorrect assumption
but the last thing I want is it flagging a buy when its a sell and visa versa. Also, I dont want to have errors as I refine
from here even on a simple piece of code going forward.
The Indicator code is:Indicator Code1234567891011121314151617181920indicator1 = CCI[20]once lastpoint = 0c1 = (indicator1 crosses over -100)c2 = (indicator1 crosses under 100)c3 = (indicator1 crosses under -100)c4 = (indicator1 crosses over 100)L0 = (lastpoint = 0)L1 = (lastpoint = 1)Lneg1 = (lastpoint = -1)IF (c1 AND L0) OR (c1 AND Lneg1) OR (c4 AND Lneg1) THENlastpoint = 1ElSIF (c2 AND L0) OR (c2 AND L1) OR (c3 AND L1)THEN//SELL AT MARKETlastpoint = -1ENDIFreturn lastpoint,0The Backtest code is:
Backtest code1234567891011121314151617181920212223DEFPARAM CumulateOrders = False // Cumulating positions deactivatedonce lastpoint = 0// Conditions to enter long positionsindicator1 = CCI[20]c1 = (indicator1 crosses over -100)c2 = (indicator1 crosses under 100)c3 = (indicator1 crosses under -100)c4 = (indicator1 crosses over 100)L0 = (lastpoint = 0)L1 = (lastpoint = 1)Lneg1 = (lastpoint = -1)IF ((c1 AND L0) OR (c1 AND Lneg1) OR (c4 AND Lneg1))THENBUY 5000 CASH AT MARKETlastpoint = 1// Conditions to exit long positionsELSIF (c2 AND L0) OR (c2 AND L1) OR (c3 AND L1) THENSELL AT MARKETlastpoint = -1ENDIFNothing too tricky really. Its based on the visual in the attached file and the behaviour can be seen
in the chart dump in the other file.The backtest clearly lags the indicator and the actual indicator by a day.
Thanks for any assistance you can provide,
John01/01/2018 at 12:06 PM #56992Code is read at Close and actions are made at next Open, that’s the behavior of ProBacktest/ProOrder and the reason you think you have such differences between indicators and automatic trading programs.
1 user thanked author for this post.
01/01/2018 at 1:10 PM #56997Thank you Nicolas for your answer and prompt response. I think I understand now.
So I shouldnt use the backtest for identifying buy/sell signals for the next day? I should rely on screeners and indicators?
What about for automated trading, does the signal fire on the indicator? Its a little confusing.
Regards
John
01/01/2018 at 4:19 PM #57008Line 9 of the indicator code will only be true once, when the indicator starts, later it will always be either 1 or -1.
Is that what you want?
01/03/2018 at 3:24 PM #57139Hi roberto,
Yes, this is what I wanted to do originally. 0 is the initial state only. I wanted the transition of state to remain until it changes, so I could see whether I remain in or out without having to hunt back.
I’ve done two versions now, and see advantages both ways.
Thanks for pointing it out,
John
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on