missing trade on backtest

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #149849 quote
    ullle73
    Participant
    Senior

    Hi, anyone knows why backtest missing this entry and exit? I even increased spread on backtest to 8 points to see if it would take the trade, but it didnt.

    // Definition of code parameters
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    DEFPARAM preloadbars = 5000
    //Money Management
    MM = 0 // = 0 for optimization
    if MM = 0 then
    positionsize=1
    ENDIF
    if MM = 1 then
    ONCE startpositionsize = 1
    ONCE factor = 6 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
    ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
    ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
    ONCE tier1 = 200 //  IG first tier margin limit
    ONCE maxpositionsize = 2000 //  IG tier 2 margin limit
    ONCE minpositionsize = 1 // enter minimum position allowed
    IF Not OnMarket THEN
    positionsize = startpositionsize + Strategyprofit/(factor*margin)
    ENDIF
    IF Not OnMarket THEN
    IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
    positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 //incorporating tier 2 margin
    ENDIF
    IF Not OnMarket THEN
    if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
    positionsize = minpositionsize //keeps positionsize from going below allowed minimum
    ENDIF
    IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor*margin2)) + tier1 > maxpositionsize then
    positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    
    
    Ctime = time >= 0 and time < 230000
    
    TIMEFRAME(2 hours,updateonclose)
    Period= 460
    inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
    HULLa = weightedaverage[round(sqrt(Period))](inner)
    c1 = HULLa > HULLa[1]
    c2 = HULLa < HULLa[1]
    
    ST1 = SuperTrend[3.5,7]
    c4 = (close < ST1)
    
    ma1 = average[58,4](close)
    c6 = ma1 < ma1[1]
    
    //Stochastic RSI | indicator
    lengthRSI = 7 //RSI period
    lengthStoch = 12 //Stochastic period
    smoothK = 10 //Smooth signal of stochastic RSI
    smoothD = 2 //Smooth signal of smoothed stochastic RSI
    myRSI = RSI[lengthRSI](close)
    MinRSI = lowest[lengthStoch](myrsi)
    MaxRSI = highest[lengthStoch](myrsi)
    StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)
    K = average[smoothK](stochrsi)*100
    D = average[smoothD](K)
    c8 = K<D
    
    TIMEFRAME(30 minutes,updateonclose)
    indicator5 = Average[2](typicalPrice)
    indicator6 = Average[5](typicalPrice)
    c10 = (indicator5 < indicator6)
    
    TIMEFRAME(15 minutes,updateonclose)
    mac = average[40,1](close)
    c11 = mac > mac[1]
    c12 = mac < mac[1]
    
    Periodc= 17
    innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
    HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
    c14 = HULLc < HULLc[1]
    
    TIMEFRAME(10 minutes)
    indicator4 = SuperTrend[2.5,7]
    indicator4a = SAR[0.025,0.025,0.15]
    c22 = (close < indicator4) or (close < indicator4a)
    
    TIMEFRAME(5 minutes)
    //Stochastic RSI | indicator
    lengthRSIa = 11 //RSI period
    lengthStocha = 5 //Stochastic period
    smoothKa = 11 //Smooth signal of stochastic RSI
    smoothDa = 5 //Smooth signal of smoothed stochastic RSI
    myRSIa = RSI[lengthRSIa](close)
    MinRSIa = lowest[lengthStocha](myrsia)
    MaxRSIa = highest[lengthStocha](myrsia)
    StochRSIa = (myRSIa-MinRSIa) / (MaxRSIa-MinRSIa)
    Ka = average[smoothKa](stochrsia)*100
    Da = average[smoothDa](Ka)
    c16 = Ka<Da
    
    Periodb= 21
    innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
    HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
    c19 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]
    c20 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
    
    // Conditions to enter short positions
    IF Ctime and c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c20 and c22 THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    SET STOP %LOSS 1.7
    SET TARGET %PROFIT 2.5
    ENDIF
    
    //================== exit in profit
    If shortonmarket and C11 and c19 and close<positionprice then
    exitshort at market
    endif
    
    //==============exit at loss
    If shortonmarket and c1 and c19 and close>positionprice then
    exitshort at market
    endif
    
    //%trailing stop function
    trailingpercentlong  = .29 // %
    trailingpercentshort = .34 // %
    stepPercentlong = .006
    stepPercentshort = .009
    sensitivity = (low+high+close)/3
    if onmarket then
    trailingstartlong = tradeprice(1)*(trailingpercentlong/100) //trailing will start @trailingstart points profit
    trailingstartshort = tradeprice(1)*(trailingpercentshort/100) //trailing will start @trailingstart points profit
    trailingsteplong = tradeprice(1)*(stepPercentlong/100) //% step to move the stoploss
    trailingstepshort = tradeprice(1)*(stepPercentshort/100) //% step to move the stoploss
    endif
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND sensitivity-tradeprice(1)>=trailingstartlong THEN
    newSL = tradeprice(1)+trailingsteplong
    ENDIF
    //next moves
    IF newSL>0 AND sensitivity-newSL>trailingsteplong THEN
    newSL = newSL+trailingsteplong
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-sensitivity>=trailingstartshort THEN
    newSL = tradeprice(1)-trailingstepshort
    ENDIF
    //next moves
    IF newSL>0 AND newSL-sensitivity>trailingstepshort THEN
    newSL = newSL-trailingstepshort
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    //************************************************************************
    IF shortonmarket and barindex-tradeindex>415 and close>positionprice then
    exitshort at market
    endif
    //=============================================
    if shortonmarket and abs(open-close)<1 and low[1]>low and close-low>16 and close<positionprice then
    exitshort at market
    endif
    //===================================
    myrsiM5=rsi[14](close)
    if myrsiM5>60 and barindex-tradeindex>1 and shortonmarket and close<positionprice then
    exitshort at market
    endif
    
    // ---------   US DAY LIGHT SAVINGS MONTHS      ---------------- //
    mar = month = 3 // MONTH START
    nov = month = 11 // MONTH END
    IF (month > 3 AND month < 11) OR (mar AND day>14) OR (mar AND day-dayofweek>7) OR (nov AND day<=dayofweek AND day<7) THEN
    USDLS=010000
    ELSE
    USDLS=0
    ENDIF
    
    once shortStep = 0
    once openStrongLong = 0
    if not onmarket or (time <= 143000 - USDLS and time >= 210000 - USDLS) then
    shortStep = 0
    openStrongLong = 0
    endif
    
    //detect strong direction for market open
    once rangeOK = 50
    once tradeMin = 500
    IF (time >= 144000 - USDLS) AND (time <= 144000 + tradeMin - USDLS) THEN
    openStrongLong = close > open AND close - open > rangeOK
    ENDIF
    
    once bollperiod = 20
    once bollMAType = 1
    once s = 2
    once BollLevel = 90
    once BollSR = 50
    
    bollMA = average[bollperiod, bollMAType](close)
    STDDEV = STD[bollperiod]
    bollUP = bollMA + s * STDDEV
    bollDOWN = bollMA - s * STDDEV
    IF bollUP = bollDOWN THEN
    bollPercent = 50
    ELSE
    bollPercent = 100 * (close - bollDOWN) / (bollUP - bollDOWN)
    ENDIF
    
    //Market spike up
    IF shortonmarket AND shortStep = 0 AND bollPercent > BollLevel THEN
    shortStep = 1
    ENDIF
    //Market slowly come down
    IF shortonmarket AND shortStep = 1 AND bollPercent < 100 - BollLevel THEN
    shortStep = 2
    ENDIF
    //Market still go back to bullish and supported after strong bull open, exit
    IF shortonmarket AND shortStep = 2 AND bollPercent > BollSR AND openStrongLong THEN
    exitshort at market
    ENDIF
    
    once trendPeriod = 70
    once trendPeriodResume = 30
    once trendGap = 3
    once trendResumeGap = 6
    if not onmarket then
    fullySupported = 0
    endif
    //Market supported in the wrong direction
    IF shortonmarket AND fullySupported = 0 AND summation[trendPeriod](bollPercent > 50) >= trendPeriod - trendGap THEN
    fullySupported = 1
    ENDIF
    
    //Market pull back but continue to be supported
    IF shortonmarket AND fullySupported = 1 AND bollPercent[trendPeriodResume + 1] < 0 AND summation[trendPeriodResume](bollPercent > 50) >= trendPeriodResume - trendResumeGap THEN
    exitshort at market
    ENDIF
    
    //Started real wrong direction
    once strongTrend = 70
    once strongPeriod = 6
    IF shortonmarket and openStrongLong and barindex - tradeindex < 12 and summation[strongPeriod](bollPercent > strongTrend) = strongPeriod then
    exitshort at market
    ENDIF
     
    
    error-1.jpg error-1.jpg
    #149859 quote
    GraHal
    Participant
    Master

    Anything to do with your Daylight Savings settings at Line 183 to 190?

    #149863 quote
    ullle73
    Participant
    Senior

    hmm, dont know. In simple english, what does the code say those lines?

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

missing trade on backtest


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
ullle73 @jonas_rydqvist Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/08/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...