Exit not at the end of the bar

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8885 quote
    deleted190722
    Participant
    New

    Hi, does anyone knows why my TS even if has not SL o TP it does some exit in the middle of the bar and not exactly at the start of it?

    Some example in the attached picture… I use IG Market demo account to test. [attachment file=8886]

    The code is the supertrend that I have posted in the library:

     

    //-------------------------------------------------------------------------
    // Codice principale : Supertrend
    //-------------------------------------------------------------------------
    defparam cumulateorders = false
    
    //PARAMETRI VARIABILI
    OraInizio =8
    OraFine = 18
    numerocontratti = 1
    
    //PARAMETRI FISSI
    mm = 10
    BB = 25
    ATRvolaDown = 15
    ATRvolaUp = 25
    ATR = 14
    x = 2.5
    supertrendLow = 3
    SupertrendUp = 10
    
    
    
    
    EMA=exponentialaverage[mm](close)
    BBmiddle= (BollingerUp[BB](close)+BollingerDown[BB](close))/2
    
    
    
    ora=currenthour
    condizioneday= ora > OraInizio and ora < OraFine
    condizionevola= AverageTrueRange[ATRvolaDown](close)>AverageTrueRange[ATRvolaUp](close)
    
    // Condizioni per entrare su posizioni long
    
    IF NOT LongOnMarket and condizioneday and Close < Supertrend[supertrendLow,SupertrendUp] and close > ema and condizionevola THEN
    BUY numerocontratti CONTRACTS AT MARKET
    stopprice=AverageTrueRange[ATR](close)*x
    ENDIF
    
    // Condizioni per uscire da posizioni long
    If LongOnMarket AND Close > Supertrend[supertrendLow,SupertrendUp] and close < BBmiddle and close < EMA THEN
    SELL AT MARKET
    ENDIF
    
    // Condizioni per entrare su posizioni short
    IF NOT ShortOnMarket and condizioneday and Close > Supertrend[supertrendLow,SupertrendUp] and close < ema and condizionevola THEN
    SELLSHORT numerocontratti CONTRACTS AT MARKET
    stopprice=AverageTrueRange[ATR](close)*x
    ENDIF
    
    // Condizioni per uscire da posizioni short
    IF ShortOnMarket AND Close < Supertrend[supertrendLow,SupertrendUp] and close > BBmiddle and close > ema THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stop e target: Inserisci qui i tuoi stop di protezione e profit target
    set stop ploss stopprice
    
    1-1.png 1-1.png
    #8890 quote
    Nicolas
    Keymaster
    Master

    It might be your stoploss that exit trades in a middle of a bar.

    Also you have set your stoploss with pLOSS which need “point” values and not real digit ones like your “stopprice” variable which is set among ATR.

    #8893 quote
    deleted190722
    Participant
    New

    I will try to change the pLOSS but the variable Stopprice cannot change in the middle of a bar. It is the ATR of Hour timeframe. The value of it change at every new bar. Cannot change in the middle of it. In the backtest it works properly…

     

    Thanks for help Nicolas! I always appriciate.

    David

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

Exit not at the end of the bar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/06/2016
Status: Active
Attachments: No files
Logo Logo
Loading...