Why is this strategy not well calculated? – solved

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #48732 quote
    pieroim
    Participant
    Average

    Solved… a stupid mistake.. pardon..

    This is a very simple strategy for better understanding programming with PRT. But the backtest gives me strange results .. what I’m doing of wrong?

    //Stategy: Ichim
    
    
    Defparam CUMULATEORDERS = False
    once prevdirection = 0 //1 = buy, 2 = sell
    possize = 1
    stoploss = 0.0100 //points 0.0010 10 pips
    profitto = 0.0100
     
    //indicators---------------------------------------------------------------------------------
    
    T = 9 //Tenkan-Sen Period (9)
    I = 26 //Chikou-Span Period (26)
    K = 52 //Kijun-Sen Period (52)
    
    TS = (highest[T](high)+lowest[T](low))/2 //Tenkan-Sen
    KS = (highest[I](high)+lowest[I](low))/2 //Kijun-Sen
    SA = (TS[I]+KS[I])/2 //Senkou-Span A
    SB = (highest[K](high[I])+lowest[K](low[I]))/2 //Senkou-Span B
    
    //end of indicators--------------------------------------------------------------------------
    
    //Signals------------------------------------------------------------------------------------
    
    //Kumo parameters
    kumoUP      =0
    kumoDOWN    =0
    if SA[0]>SB[0] then
    kumoUP=SA[0]
    kumoDOWN=SB[0]
    else
    kumoUP=SB[0]
    kumoDOWN=SA[0]
    endif
    
    //mini price trend
    primo  = (high[3]+low[3])/2
    ultimo = (high[0]+low[0])/2
    spread = pointsize*2
    miniTrPr= ultimo-primo
    miniTrPr= miniTrPr/spread
    //end of signals------------------------------------------------------------------------------------
    
    //Orders--------------------------------------------------------------------------------------------
    
    if prevdirection = 2 or prevdirection = 0 then
    if countofposition = 0 and entrataAquisto = 0 and entrataVendita = 0 and open[0]>kumoUP and close[0]>open[0] and miniTrPr>5 then
    Buy possize contracts at market
    set target profit profitto// profit in points
    SET STOP LOSS stoploss
    entrataAquisto = 1
    prevdirection = 1
    endif
    endif
    if prevdirection = 1 or prevdirection = 0 then
    if countofposition = 0 and entrataVendita = 0 and entrataAquisto = 0 and close[0]<kumoDOWN and close[0]<open[0] and miniTrPr<-5 then
    Sellshort possize contracts at market
    set target profit profitto// profit in points
    SET STOP LOSS stoploss
    entrataVendita = 1
    prevdirection = 2
    endif
    endif
    
    //End of orders-------------------------------------------------------------------------------------
    
    //Exit Conditions-----------------------------------------------------------------------------------
    
    if entrataAquisto = 1 and open[0]>kumoDOWN and open[0]<kumoUP and close[0]>kumoDOWN and close[0]<kumoUP then
    Sell at market
    endif
    if entrataVendita = 1 and open[0]>kumoDOWN and open[0]<kumoUP and close[0]>kumoDOWN and close[0]<kumoUP then
    exitshort at market
    endif
    
    IF NOT ShortOnMarket THEN
    entrataVendita = 0
    ENDIF
    IF NOT LongOnMarket THEN
    entrataAquisto = 0
    ENDIF
    
    if (open[0]>kumoDOWN and open[0]<kumoUP) and (close[0]>kumoDOWN and close[0]<kumoUP) then
    prevdirection = 0
    endif
    
    graph entrataVendita coloured (255,0,0) as "vendita"
    //graph entrataAquisto coloured (255,0,0) as "aquisto"
    graph prevdirection coloured (255,0,0) as "prevdirection"
    graph kumoUP coloured (0,255,0) as "kumoUP"
    graph kumoDOWN coloured (0,255,0) as "kumoDOWN"
    graph miniTrPr coloured (0,255,0) as "miniTrPr"
    
    //Exit of exit conditions---------------------------------------------------------------------------
    ichimoku8.jpg ichimoku8.jpg
    #48760 quote
    pieroim
    Participant
    Average

    Not Solved… entrataAquisto would be on 1 in the picture…

    IF NOT ShortOnMarket THEN
         entrataVendita = 0
    ENDIF
    IF NOT LongOnMarket THEN
          entrataAquisto = 0
    ENDIF
    ichimoku9.jpg ichimoku9.jpg
    #48763 quote
    Nicolas
    Keymaster
    Master

    If you have no long position opened, then ‘entrataAquisto’ is set to 0. This value is set at bar Close and only visible in next bars, so when you set it to 1, you will only see it, at first at next bar open.

    #48773 quote
    pieroim
    Participant
    Average

    Ok Nicolas, but in picture that I attached, you can see that the variable woud be to 1 in the bars after the bar where a long position is opened.

    The backtest in the graph gives me 0 valute..

    #48775 quote
    Nicolas
    Keymaster
    Master

    I do not know what’s wrong, but maybe this is something that could help: create a boolean variable that use NOT SHORTONMARKET as its own test.

    not-shortonmarket.jpg not-shortonmarket.jpg
    #48806 quote
    pieroim
    Participant
    Average

    Thank’s Nicolas, very strange behavior of PRT backtest..

    However, your suggestion has led me to the solution..

    I replaced:

    IF NOT ShortOnMarket THEN
         entrataVendita = 0
    ENDIF
    IF NOT LongOnMarket THEN
          entrataAquisto = 0
    ENDIF

    simply with:

    entrataVendita = ShortOnMarket
    entrataAquisto = LongOnMarket

    Now all works great!

    Thank’s

    Piero

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

Why is this strategy not well calculated? – solved


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
pieroim @pieroim Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by pieroim
8 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/09/2017
Status: Active
Attachments: 3 files
Logo Logo
Loading...