Problem with timing position opening

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #200094 quote
    Mr.CrniMr.Crni
    Participant
    Average

    Hello PRC Forum

    I have the following problem: my indicator signals me an entry point, but during the backtest the position is opened one bar later. Engulfing requires the evaluation of the 2 past candles, why is no position opened on the 3rd candle but on the 4th candle?

    Indicator:

    SecondToLastCandleHeight = abs(close[2]-open[2])
    LastCandleHeight = abs(close[1]-open[1])
    
    Engulfing = LastCandleHeight > SecondToLastCandleHeight
    
    ShortMarketCondition = DIminus[14](CLOSE[1]) > DIplus[14](CLOSE[1]) AND ADX[14] > 12 AND ADX[14] >= ADX[14][2]
    LongMarketCondition = DIplus[14](CLOSE[1]) > DIminus[14](CLOSE[1]) AND ADX[14] > 12 AND ADX[14] >= ADX[14][2]
    
    EngulfingShort = Engulfing AND CLOSE[2] > OPEN[2] AND CLOSE[1] < OPEN[2] AND ShortMarketCondition
    IF EngulfingShort THEN
    DRAWARROWDOWN(barindex,close) coloured(255,255,0)
    ENDIF
    
    EngulfingLong = Engulfing AND CLOSE[2] < OPEN[2] AND CLOSE[1] > OPEN[2] AND LongMarketCondition
    IF EngulfingLong THEN
    DRAWARROWUP(barindex,close) coloured(0,255,255)
    ENDIF
    
    RETURN EngulfingShort as "EngulfingShort", EngulfingLong as "EngulfingLong", LastCandleHeight as "LastCandleHeight", SecondToLastCandleHeight as "SecondToLastCandleHeight"

    Strategy:

    //Engulfing/DMI
    //MainTime: 1H, SubordinateTime: 5M
    //Cornel Schmid, 03.09.2022
    
    //TERMS AND CONDITIONS
    DEFPARAM PreLoadBars = 300
    DEFPARAM CumulateOrders = true
    Position=1
    
    //ENGULFING
    EngulfingShort, EngulfingLong, LastCandleHeight, SecondToLastCandleHeight = CALL "FR_Engulfing_DMI"
    
    //ENGULFINGRATIO
    EngulfingRatio = (LastCandleHeight/SecondToLastCandleHeight) < MaxRatio
    
    //EXECUTION
    IF Engulfingshort THEN
    SELLSHORT Position PERPOINT AT MARKET
    SET STOP PLOSS StopLossShort
    ENDIF
    
    IF EngulfingLong THEN
    BUY Position PERPOINT AT MARKET
    SET STOP PLOSS StopLossLong
    ENDIF
    
    [REM Trailing Stop, Exitconditions, etc....]

    I have added a picture: Yellow and turquoise arrows = Indicator, Green and red arrows = Strategy

    What is the problem?

    EngulfingStrat_Picture.png EngulfingStrat_Picture.png
    #200103 quote
    JSJS
    Participant
    Master

    This is the normal course of events, when a condition is true (in your indicator), then a position is opened on the Open of the next bar in your trading system.

    #200105 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    It’s because your indicator is lagging by 1 candle.

    Replace all occurrences of [1] with [0], then [2]  with [1].

    #200459 quote
    Mr.CrniMr.Crni
    Participant
    Average

    Thank you Roberto! It works

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Problem with timing position opening


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mr.Crni @mr-crni Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Mr.CrniMr.Crni
4 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/03/2022
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...