Conditions on number of trades, reversing trade direction

Viewing 15 posts - 1 through 15 (of 38 total)
  • Author
    Posts
  • #203818 quote
    mrbolt
    Participant
    New

    Good day, all! Hope all are doing well. Kindly ask community help on the coding some backtest example for the strategy.

    So, long story short:

    1. I enter with a buy stop to go long, or a sell stop to go short.
    2. I enter with 3 contracts.
    3. Position size: 3 contracts, with profit targets of 1R, 2R, and 3R. Once my first target is hit, my stop loss becomes breakeven.
    4. If I get stopped out on my first signal, I can stop out and reverse (Go long, get stopped, go short or Go short, get stopped, go long) – only 3 attempts per day.

    What I did so far: I can track multitimeframe, open and close positions, but can’t realize how to reverse trade if it fails with one direction, how to count correctly number of attempts, in which timeframe? and how to partially close trade.

    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars = 0
    
    TIMEFRAME(30 seconds, UPDATEONCLOSE)
    
    // No new position is taken after the candlestick that closes 9:45 a.m.
    FinishTime = 143000
    // The market analysis strats at the 30-sec candlestick which closes at 9:00:30 a.m.
    StartTime = 120000
    
    PositionSize = 3
    TickScale = TICKSIZE
    ScaleReward = 1
    PartialCloseCoeff = 3
    CloseQuantity = PositionSize/PartialCloseCoeff
    
    // Some holidays such as the 24th and 31st of December are excluded
    IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) OR (Month = 1 AND Day = 1) OR (DayOfWeek = 0 OR DayOfWeek = 6) OR (Time < StartTime OR Time >= FinishTime) THEN
    TradingDay = 0
    ELSE
    TradingDay = 1
    ENDIF
    
    // We initialize this variable once at the beginning of the trading system.
    //ONCE StartTradingDay = -1
    
    // We initialize this variable once at the beginning of the trading system.
    ONCE StartTradingDay = -1
    
    IF (Time < StartTime AND StartTradingDay <> 0) THEN
    CloseO = 0
    HighO = 0
    LowO = 0
    SellPosition = 0
    StartTradingDay = 0
    
    ELSIF Time = StartTime AND TradingDay = 1 THEN
    //ELSIF Time >= StartTime AND StartTradingDay = 0 AND TradingDay = 1 THEN
    // We store the index of the first bar of the trading day
    IndexStartDay = IntradayBarIndex
    StartTradingDay = 1
    
    CloseO = Close
    HighO = High
    LowO = Low
    RangeOpen = HighO - LowO
    BuyLevel = HighO + TickScale
    SellLevel = LowO - TickScale
    StopLong = LowO - TickScale
    StopShort = HighO + TickScale
    ENDIF
    
    TIMEFRAME(1 seconds, UPDATEONCLOSE)
    
    If IntraDayBarIndex = 0 Then
    TradeONLong = 1
    TradeONShort = 1
    CntLong = 0
    CntShort = 0
    LastTrade = 0
    count = 0
    Endif
    
    IF Time > StartTime AND TradingDay = 1 THEN
    //GRAPH CloseO as "CloseO"
    GRAPH HighO as "HighO"
    GRAPH LowO as "LowO"
    GRAPH RangeOpen as "RangeOpen"
    //GRAPH DayOfWeek as "DayOfWeek"
    //GRAPH StopShort as "StopShort"
    //GRAPH StopLong as "StopLong"
    //GRAPH TickScale as "TickScale"
    
    //
    //GRAPH Time as "Time"
    //GRAPH DayOfWeek as "DayOfWeek"
    //GRAPH UpperLevel as "UpperLevel"
    //GRAPH LowerLevel as "LowerLevel"
    
    IF Close > HighO AND Not LongOnMarket AND CntLong = 0 AND CntShort = 0 THEN
    BUY PositionSize CONTRACTS AT BuyLevel STOP
    //SELLSHORT PositionSize CONTRACTS AT BuyLevel STOP
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    
    //LastTrade = 1
    CntLong = CntLong + 1
    TradeONLong = 0
    count = count + 1
    //GRAPH CntLong as "CntLong"
    ELSIF Close < LowO AND Not SHORTONMARKET AND CntLong = 0 AND CntShort = 0 THEN
    SELLSHORT PositionSize CONTRACTS AT SellLevel STOP
    //BUY PositionSize CONTRACTS AT SellLevel STOP
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    TradeONShort = 0
    //LastTrade = 2
    CntShort = CntShort + 1
    count = count + 1
    //GRAPH CntShort as "CntShort"
    ENDIF
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    
    ENDIF
    
    #203870 quote
    mrbolt
    Participant
    New

    I’ve been trying to code futher and debug, but when I put GRAPH I received an error. I don’t have any problem with internet, with software, but still receiveng this when added such lines in the code and adding Graph.

    
    myCurrentProfit = STRATEGYPROFIT
    
    If myCurrentProfit < 0 then
    GRAPH myCurrentProfit as "myCurrentProfit"
    IF LongOnMarket[1] AND NOT OnMarket THEN
    SELLSHORT PositionSize CONTRACTS AT MARKET
    count = count + 1
    ELSIF ShortOnMarket[1] AND NOT OnMarket THEN
    BUY PositionSize CONTRACTS AT MARKET
    count = count + 1
    ENDIF
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    endif
    Error.png Error.png
    #203872 quote
    GraHal
    Participant
    Master

    Try this as Line 12 to 14 …

    Endif
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    
    #203874 quote
    mrbolt
    Participant
    New

    So, thank you for the reply, I didn’t put all code. Here we go, with what I ended up right now

    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars = 0
    
    TIMEFRAME(45 seconds, UPDATEONCLOSE)
    
    // No new position is taken after the candlestick that closes 9:45 a.m.
    FinishTime = 103000
    // The market analysis strats at the 30-sec candlestick which closes at 9:00:30 a.m.
    StartTime = 100030
    
    PositionSize = 3
    TickScale = TICKSIZE
    ScaleReward = 1
    PartialCloseCoeff = 3
    CloseQuantity = PositionSize/PartialCloseCoeff
    
    // Some holidays such as the 24th and 31st of December are excluded
    IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) OR (Month = 1 AND Day = 1) OR (DayOfWeek = 0 OR DayOfWeek = 6) OR (Time < StartTime OR Time >= FinishTime) THEN
    TradingDay = 0
    ELSE
    TradingDay = 1
    ENDIF
    
    // We initialize this variable once at the beginning of the trading system.
    //ONCE StartTradingDay = -1
    
    // We initialize this variable once at the beginning of the trading system.
    ONCE StartTradingDay = -1
    
    IF (Time < StartTime AND StartTradingDay <> 0) THEN
    CloseO = 0
    HighO = 0
    LowO = 0
    SellPosition = 0
    StartTradingDay = 0
    
    ELSIF Time = StartTime AND TradingDay = 1 THEN
    //ELSIF Time >= StartTime AND StartTradingDay = 0 AND TradingDay = 1 THEN
    // We store the index of the first bar of the trading day
    IndexStartDay = IntradayBarIndex
    StartTradingDay = 1
    
    //ELSIF StartTradingDay = 1 AND Time >= StartTime AND Time <= LimitEntryTime THEN
    //HighClose = Close[1](High)
    CloseO = Close
    HighO = High
    LowO = Low
    RangeOpen = HighO - LowO
    BuyLevel = HighO + TickScale
    SellLevel = LowO - TickScale
    StopLong = LowO - TickScale
    StopShort = HighO + TickScale
    ENDIF
    
    TIMEFRAME(1 seconds, UPDATEONCLOSE)
    
    If IntraDayBarIndex = 0 Then
    TradeONLong = 1
    TradeONShort = 1
    CntLong = 0
    CntShort = 0
    LastTrade = 0
    TradeON = 1
    count = 0
    Endif
    
    IF Time > StartTime AND TradingDay = 1 AND TradeON = 1 AND count <3 THEN
    //GRAPH CloseO as "CloseO"
    //GRAPH HighO as "HighO"
    //GRAPH LowO as "LowO"
    //GRAPH RangeOpen as "RangeOpen"
    //GRAPH DayOfWeek as "DayOfWeek"
    //GRAPH StopShort as "StopShort"
    //GRAPH StopLong as "StopLong"
    //GRAPH TickScale as "TickScale"
    
    
    IF Close > HighO AND Not LongOnMarket AND Not SHORTONMARKET THEN
    BUY PositionSize CONTRACTS AT BuyLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    //SELLSHORT PositionSize CONTRACTS AT BuyLevel STOP
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    
    //LastTrade = 1
    CntLong = CntLong + 1
    TradeONLong = 0
    count = count + 1
    //GRAPH CntLong as "CntLong"
    ELSIF Close < LowO AND Not LongOnMarket AND Not SHORTONMARKET THEN
    SELLSHORT PositionSize CONTRACTS AT SellLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    //BUY PositionSize CONTRACTS AT SellLevel STOP
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    TradeONShort = 0
    //LastTrade = 2
    CntShort = CntShort + 1
    count = count + 1
    //GRAPH CntShort as "CntShort"
    ENDIF
    
    //
    
    myCurrentProfit = STRATEGYPROFIT
    //
    If myCurrentProfit < 0 then
    //GRAPH myCurrentProfit as "myCurrentProfit"
    IF LongOnMarket[1] AND NOT OnMarket THEN
    SELLSHORT PositionSize CONTRACTS AT MARKET
    count = count + 1
    ELSIF ShortOnMarket[1] AND NOT OnMarket THEN
    BUY PositionSize CONTRACTS AT MARKET
    count = count + 1
    ENDIF
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    endif
    
    ENDIF

    What I still don’t get:
    1. How to determine that previous trade had a loss or profit after the close? Strategyprofit and Positionperformance don’t help me, I tried, but failed.
    2. Still have the error with Graph and XML, don’t know why, discovering

    #203885 quote
    GraHal
    Participant
    Master

    thank you for the reply

    My suggestion was in relation to the screenshot of the error you posted above.

    I just ran the code you posted in your last post above and I get no errors at all.

    How to determine that previous trade had a loss or profit after the close?

    Anybody please feel free to help mrbolt on above?

    #203886 quote
    mrbolt
    Participant
    New

    So, the last version, which still doesn’t work properly 🙁

    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars = 0
    
    TIMEFRAME(30 seconds, UPDATEONCLOSE)
    
    // No new position is taken after the candlestick 
    FinishTime = 103000
    // The market analysis strats at the 30-sec candlestick which closes at 9:00:30 a.m.
    StartTime = 100000
    
    PositionSize = 3
    TickScale = TICKSIZE
    ScaleReward = 1
    PartialCloseCoeff = 3
    CloseQuantity = PositionSize/PartialCloseCoeff
    
    // Some holidays such as the 24th and 31st of December are excluded
    IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) OR (Month = 1 AND Day = 1) OR (DayOfWeek = 0 OR DayOfWeek = 6) OR (Time < StartTime OR Time >= FinishTime) THEN
    TradingDay = 0
    ELSE
    TradingDay = 1
    ENDIF
    
    // We initialize this variable once at the beginning of the trading system.
    //ONCE StartTradingDay = -1
    
    // We initialize this variable once at the beginning of the trading system.
    ONCE StartTradingDay = -1
    
    IF (Time < StartTime AND StartTradingDay <> 0) THEN
    CloseO = 0
    HighO = 0
    LowO = 0
    SellPosition = 0
    StartTradingDay = 0
    
    ELSIF Time = StartTime AND TradingDay = 1 THEN
    //ELSIF Time >= StartTime AND StartTradingDay = 0 AND TradingDay = 1 THEN
    // We store the index of the first bar of the trading day
    IndexStartDay = IntradayBarIndex
    StartTradingDay = 1
    
    //ELSIF StartTradingDay = 1 AND Time >= StartTime AND Time <= LimitEntryTime THEN
    //HighClose = Close[1](High)
    CloseO = Close
    HighO = High
    LowO = Low
    RangeOpen = HighO - LowO
    BuyLevel = HighO + TickScale
    SellLevel = LowO - TickScale
    StopLong = LowO - TickScale
    StopShort = HighO + TickScale
    ENDIF
    
    TIMEFRAME(1 seconds, UPDATEONCLOSE)
    
    If IntraDayBarIndex = 0 Then
    TradeONLong = 1
    TradeONShort = 1
    CntLong = 0
    CntShort = 0
    LastTrade = 0
    count = 0
    
    Endif
    
    //GRAPH IntraDayBarIndex as "IntraDayBarIndex"
    
    IF Time > StartTime AND TradingDay = 1 AND count <= 3 THEN
    IF Close > HighO AND count = 0 THEN
    BUY PositionSize CONTRACTS AT BuyLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    //GRAPH LongOnMarket as "LongOnMarket"
    //GRAPH SHORTONMARKET[1] as "SHORTONMARKET[1]"
    //GRAPH LongOnMarket as "LongOnMarket"
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    
    //LastTrade = 1
    CntLong = CntLong + 1
    count = count + 1
    //GRAPH CntLong as "CntLong"
    ELSIF Close < LowO AND count = 0 THEN
    SELLSHORT PositionSize CONTRACTS AT SellLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    //GRAPH SHORTONMARKET as "SHORTONMARKET"
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    //LastTrade = 2
    CntShort = CntShort + 1
    count = count + 1
    ELSIF POSITIONPERF(1) < 0 AND count >= 1 THEN
    //GRAPH count as "count"
    LongPrev = LongOnMarket[1]
    ShortPrev = SHORTONMARKET[1]
    IF LongPrev THEN
    //GRAPH LongPrev as "LongOnMarket[1]"
    //GRAPH 1 as "1"
    //SELLSHORT PositionSize CONTRACTS AT MARKET
    BUY PositionSize CONTRACTS AT MARKET
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    count = count + 1
    ELSIF ShortPrev THEN
    //GRAPH ShortPrev as "SHORTONMARKET[1]"
    //BUY PositionSize CONTRACTS AT MARKET
    SELLSHORT PositionSize CONTRACTS AT MARKET
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    count = count + 1
    ENDIF
    
    ENDIF
    
    ENDIF

    After closing in loss, new trade wasn’t opened.

    #203887 quote
    mrbolt
    Participant
    New

    thank you for the reply

    My suggestion was in relation to the screenshot of the error you posted above.

    I just ran the code you posted in your last post above and I get no errors at all.

    How to determine that previous trade had a loss or profit after the close?

    Anybody please feel free to help <span class=”bbp-author-name”>mrbolt</span> on above?

    So strange, to be honest 🙁 I don’t know why I’m receiving an error with XML when adding block on trying to turn trade direction as well. So, with commented block on new trade direction GRAPH works well.

    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars = 0
    
    TIMEFRAME(30 seconds, UPDATEONCLOSE)
    
    // No new position is taken after the candlestick that closes 9:45 a.m.
    FinishTime = 103000
    // The market analysis strats at the 30-sec candlestick which closes at 10:00:30 a.m.
    StartTime = 100000
    
    PositionSize = 3
    TickScale = TICKSIZE
    ScaleReward = 1
    PartialCloseCoeff = 3
    CloseQuantity = PositionSize/PartialCloseCoeff
    
    // Some holidays such as the 24th and 31st of December are excluded
    IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) OR (Month = 1 AND Day = 1) OR (DayOfWeek = 0 OR DayOfWeek = 6) OR (Time < StartTime OR Time >= FinishTime) THEN
    TradingDay = 0
    ELSE
    TradingDay = 1
    ENDIF
    
    // We initialize this variable once at the beginning of the trading system.
    //ONCE StartTradingDay = -1
    
    // We initialize this variable once at the beginning of the trading system.
    ONCE StartTradingDay = -1
    
    IF (Time < StartTime AND StartTradingDay <> 0) THEN
    CloseO = 0
    HighO = 0
    LowO = 0
    SellPosition = 0
    StartTradingDay = 0
    
    ELSIF Time = StartTime AND TradingDay = 1 THEN
    //ELSIF Time >= StartTime AND StartTradingDay = 0 AND TradingDay = 1 THEN
    // We store the index of the first bar of the trading day
    IndexStartDay = IntradayBarIndex
    StartTradingDay = 1
    
    //ELSIF StartTradingDay = 1 AND Time >= StartTime AND Time <= LimitEntryTime THEN
    //HighClose = Close[1](High)
    CloseO = Close
    HighO = High
    LowO = Low
    RangeOpen = HighO - LowO
    BuyLevel = HighO + TickScale
    SellLevel = LowO - TickScale
    StopLong = LowO - TickScale
    StopShort = HighO + TickScale
    ENDIF
    
    TIMEFRAME(1 seconds, UPDATEONCLOSE)
    
    If IntraDayBarIndex = 0 Then
    TradeONLong = 1
    TradeONShort = 1
    CntLong = 0
    CntShort = 0
    LastTrade = 0
    count = 0
    
    Endif
    
    //GRAPH IntraDayBarIndex as "IntraDayBarIndex"
    
    IF Time > StartTime AND TradingDay = 1 AND count <= 3 THEN
    IF Close > HighO AND count = 0 THEN
    BUY PositionSize CONTRACTS AT BuyLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    GRAPH LongOnMarket as "LongOnMarket"
    //GRAPH SHORTONMARKET[1] as "SHORTONMARKET[1]"
    //GRAPH LongOnMarket as "LongOnMarket"
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    
    //LastTrade = 1
    CntLong = CntLong + 1
    count = count + 1
    //GRAPH CntLong as "CntLong"
    ELSIF Close < LowO AND count = 0 THEN
    SELLSHORT PositionSize CONTRACTS AT SellLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    //GRAPH SHORTONMARKET as "SHORTONMARKET"
    // Definition of the maximum amount to risk per position in case
    // price goes in an unfavorable direction
    //LastTrade = 2
    CntShort = CntShort + 1
    count = count + 1
    //ELSIF POSITIONPERF(1) < 0 AND count >= 1 THEN
    ////GRAPH count as "count"
    //LongPrev = LongOnMarket[1]
    //ShortPrev = SHORTONMARKET[1]
    //IF LongPrev THEN
    ////GRAPH LongPrev as "LongOnMarket[1]"
    ////GRAPH 1 as "1"
    ////SELLSHORT PositionSize CONTRACTS AT MARKET
    //BUY PositionSize CONTRACTS AT MARKET
    //SET TARGET pPROFIT RangeOpen*ScaleReward
    //SET STOP PLOSS RangeOpen
    //count = count + 1
    //ELSIF ShortPrev THEN
    ////GRAPH ShortPrev as "SHORTONMARKET[1]"
    ////BUY PositionSize CONTRACTS AT MARKET
    //SELLSHORT PositionSize CONTRACTS AT MARKET
    //SET TARGET pPROFIT RangeOpen*ScaleReward
    //SET STOP PLOSS RangeOpen
    //count = count + 1
    //ENDIF
    
    ENDIF
    
    ENDIF
    #203945 quote
    GraHal
    Participant
    Master

    So are you all good now?

    If not, make a brief clear statement on what parts / function in the code you need help / a solution?

    #203949 quote
    mrbolt
    Participant
    New

    Thanks for the asking, much appreciated. So, almost all, I’d say.

    Just have two qestions:
    1. What does it mean closing trade like Buy(exit) or Sell(exit)?
    2. Position size: 3 contracts, with profit targets of 1R, 2R, and 3R. Once my first target is hit, my stop loss becomes breakeven. – may you suggest about that, how to tackle it?

    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars = 0
    
    TIMEFRAME(30 seconds, UPDATEONCLOSE)
    
    // No new position is taken after the candlestick that closes 9:45 a.m.
    FinishTime = 103000
    // The market analysis strats at the 30-sec candlestick which closes at 9:00:30 a.m.
    StartTime = 093030
    
    PositionSize = 3
    TickScale = TICKSIZE
    ScaleReward = 1
    PartialCloseCoeff = 3
    CloseQuantity = PositionSize/PartialCloseCoeff
    
    // Some holidays such as the 24th and 31st of December are excluded
    IF (Month = 5 AND Day = 1) OR (Month = 12 AND (Day = 24 OR Day = 25 OR Day = 26 OR Day = 30 OR Day = 31)) OR (Month = 1 AND Day = 1) OR (DayOfWeek = 0 OR DayOfWeek = 6) OR (Time < StartTime OR Time >= FinishTime) THEN
    TradingDay = 0
    ELSE
    TradingDay = 1
    ENDIF
    
    // We initialize this variable once at the beginning of the trading system.
    //ONCE StartTradingDay = -1
    
    // We initialize this variable once at the beginning of the trading system.
    ONCE StartTradingDay = -1
    
    IF (Time < StartTime AND StartTradingDay <> 0) THEN
    CloseO = 0
    HighO = 0
    LowO = 0
    SellPosition = 0
    StartTradingDay = 0
    
    ELSIF Time = StartTime AND TradingDay = 1 THEN
    //ELSIF Time >= StartTime AND StartTradingDay = 0 AND TradingDay = 1 THEN
    // We store the index of the first bar of the trading day
    IndexStartDay = IntradayBarIndex
    StartTradingDay = 1
    
    //ELSIF StartTradingDay = 1 AND Time >= StartTime AND Time <= LimitEntryTime THEN
    //HighClose = Close[1](High)
    CloseO = Close
    HighO = High
    LowO = Low
    RangeOpen = HighO - LowO
    BuyLevel = HighO + TickScale
    SellLevel = LowO - TickScale
    StopLong = LowO - TickScale
    StopShort = HighO + TickScale
    ENDIF
    
    TIMEFRAME(1 seconds, UPDATEONCLOSE)
    
    If IntraDayBarIndex = 0 Then
    TradeONLong = 1
    TradeONShort = 1
    CntLong = 0
    CntShort = 0
    LastTrade = 0
    count = 0
    CntLongExtra = 0
    CntShortExtra = 0
    Endif
    
    //GRAPH CntLong as "CntLong"
    //GRAPH CntShort as "CntShort"
    //GRAPH count as "count"
    //GRAPH CntShortExtra as "CntShortExtra"
    //GRAPH CntLongExtra as "CntLongExtra"
    //GRAPH IntraDayBarIndex as "IntraDayBarIndex"
    
    IF Time > StartTime AND TradingDay = 1 AND count < 3 THEN
    IF Close > HighO AND count = 0 THEN
    BUY PositionSize CONTRACTS AT BuyLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    CntLong = CntLong + 1
    count = count + 1
    ELSIF Close < LowO AND count = 0 THEN
    SELLSHORT PositionSize CONTRACTS AT SellLevel STOP
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    CntShort = CntShort + 1
    count = count + 1
    ENDIF
    
    
    IF POSITIONPERF(1) < 0 AND count >= 1 THEN
    //
    //LongPrev = LongOnMarket[1]
    //ShortPrev = SHORTONMARKET[1]
    IF (CntLong = 1 OR CntLongExtra = 1) AND NOT OnMarket THEN
    count = count + 1
    CntShortExtra = CntShortExtra + 1
    SELLSHORT PositionSize CONTRACTS AT MARKET
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    ELSIF (CntShort = 1 OR CntShortExtra = 1) AND NOT OnMarket THEN
    BUY PositionSize CONTRACTS AT MARKET
    SET TARGET pPROFIT RangeOpen*ScaleReward
    SET STOP PLOSS RangeOpen
    count = count + 1
    CntLongExtra = CntLongExtra + 1
    ENDIF
    
    ENDIF
    
    ENDIF
    
    Sell_Buy_Exit.png Sell_Buy_Exit.png
    #203952 quote
    GraHal
    Participant
    Master

    What does it mean closing trade like Buy(exit) or Sell(exit)?

    To Exit a Buy (i.e a Long trade) we use Sell.

    To Exit a SellShort (i.e. a Short trade) we use ExitShort.

    #203953 quote
    GraHal
    Participant
    Master

    Position size: 3 contracts, with profit targets of 1R, 2R, and 3R. Once my first target is hit, my stop loss becomes breakeven. – may you suggest about that, how to tackle it?

    Am I correct in saying that above is not (currently) in your code (posted above) in any form?

    So you are looking for somebody to post a new snippet which achieves what you ask for above?

    #203954 quote
    mrbolt
    Participant
    New

    Grahal, let me comment:
    1. Ok, about exiting what you mentioned, I understand, I don’t understand why I see such trades in the order list if I have stop loss all the time? I mean I see trades with label “profit” and “loss” and label “exit” appears so rare, but it appears, so, I’m trying understand what it is, may be some glitch in data or something else
    2. In general, it’d be great, but at least I’m seeking some clue how to do it

    #203962 quote
    GraHal
    Participant
    Master

    label “profit” and “loss” and label “exit” appears so rare

    Where are you seeing these labels? A screenshot will help loads.

    #203964 quote
    mrbolt
    Participant
    New

    So, here you go.
    1. You can find in in order list. Because of such “exit” trades I have wrong trade with another direction, you can see it for 21st October. Moreover, the difference is 1 point(?), like spread I put (?).
    2. Also, may you suggest what spread I should put for ES mini futures? I didn’t find yet what does it mean 1 points for backtesting.

    settings.png settings.png
    #203966 quote
    mrbolt
    Participant
    New

    Missed first one.

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

Conditions on number of trades, reversing trade direction


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
mrbolt @mrbolt Participant
Summary

This topic contains 37 replies,
has 4 voices, and was last updated by PeterSt
3 years, 3 months ago.

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