Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar count to exit position is not working as expected

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bar count to exit position is not working as expected

    Hello,

    I am using a bar counter varable in order to exit a position.

    When I backtest the strategy the bars are counted correcty - When I use the strategy in realtime the position is exited a few bars early.

    I suspect the reason this is happening is because I am using Eurex Equity Index Futures trading hours for the strategy - while the futures trade in Extened hours.

    i.e. for some reason bars in realtime are counted in full extended hours and not in the trading hours designed for the strategy.

    Here is part of my code.
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    BarsExitLong = 35;
    BarsExitShort = 15;
    }


    protected override void OnBarUpdate()
    {
    if (IsFlat && (_smaL[2]<=_smaL[1]) && (_smaL[1] > _smaL[0]) )
    {
    int lots;

    barsShort = 0;

    double Ptarget = Close[0] - ProfitMultiplier;

    if (TradingFutures)
    {
    lots = (int) (InitialCapital / 50000);
    shortEntryOrder1 = EnterShort( lots , "S1");
    shortEntryOrder2 = EnterShort( lots , "S2");


    stopPrice = High[0] + StopMultiplier;

    base.SetStopLoss("S1", CalculationMode.Price, stopPrice, false );
    base.SetStopLoss("S2", CalculationMode.Price, stopPrice, false );

    SetProfitTarget("S2", CalculationMode.Price, Ptarget, false);
    }
    if (IsShort)
    {
    barsShort ++;

    if ( (barsShort >= BarsExitShort) && (Close[0] < (Position.AveragePrice - _atr[0]) ) )
    {
    base.ExitShort("STarget" + barsShort, "S1");
    }

    }
    }




    In the photo of the realtime strategy implementation that I attach the exit is after 11 bars. The programming setting is for exit after 15 bars.

    Please advise on why this is happening and how to correct.

    Kind regards

    Ioannis

Latest Posts

Collapse

Topics Statistics Last Post
Started by NullPointStrategies, Yesterday, 05:17 AM
0 responses
62 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
134 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
75 views
0 likes
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
45 views
0 likes
Last Post Deep42
by Deep42
 
Started by TheRealMorford, 03-05-2026, 06:15 PM
0 responses
50 views
0 likes
Last Post TheRealMorford  
Working...
X