Indicator and Backtest, same algorithm, Backtest out by a day

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #56988 quote
    capngoggles
    Participant
    New

    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:

    indicator1 = CCI[20]
    once lastpoint = 0
    
    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) THEN
    lastpoint = 1
    ElSIF (c2 AND L0) OR (c2 AND L1) OR (c3 AND L1)THEN
    //SELL AT MARKET
    lastpoint = -1
    ENDIF
    
    return lastpoint,0

    The Backtest code is:

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    once lastpoint = 0
    
    // Conditions to enter long positions
    indicator1 = 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))THEN
    BUY 5000 CASH AT MARKET
    lastpoint = 1
    // Conditions to exit long positions
    ELSIF (c2 AND L0) OR (c2 AND L1) OR (c3 AND L1) THEN
    SELL AT MARKET
    lastpoint = -1
    ENDIF

    Nothing 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.

    [attachment file=”56989″]

    The backtest clearly lags the indicator and the actual indicator by a day.
    Thanks for any assistance you can provide,
    John

    [attachment file=”56990″]

    CCIalgorithmReduced3.pdf Backtest-vs-Indicator-01-Jan-2018-21_49.pdf
    #56992 quote
    Nicolas
    Keymaster
    Master

    Code 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.

    capngoggles thanked this post
    #56997 quote
    capngoggles
    Participant
    New

    Thank 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

    #57008 quote
    robertogozzi
    Moderator
    Master

    Line 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?

    #57139 quote
    capngoggles
    Participant
    New

    Hi 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

    robertogozzi thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Indicator and Backtest, same algorithm, Backtest out by a day


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by capngoggles
8 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/01/2018
Status: Active
Attachments: 2 files
Logo Logo
Loading...