Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy with 1 Bar of Delay

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

    Strategy with 1 Bar of Delay

    Hi Guys,


    I've been developing a Strategy that uses Cumulative Delta, but the positions have been made 1 with 1 Bar of Delay, as image shows:

    Click image for larger version

Name:	image.png
Views:	143
Size:	160.0 KB
ID:	1264707
    Entries should be done after a negative delta followed by a positive delta, but it's been taking place 1 bar late after the confirmation.


    The code:


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Delta01Test";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;



    }
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Tick, 1);


    }
    else if (State == State.DataLoaded)
    {
    VolumeDelta1 = VolumeDelta(Close, Brushes.Red, Brushes.LimeGreen, Brushes.Black, 1, false, 0, false);
    VolumeDelta1.Plots[0].Brush = Brushes.Transparent;
    VolumeDelta1.Plots[1].Brush = Brushes.Transparent;
    VolumeDelta1.Plots[2].Brush = Brushes.Transparent;
    VolumeDelta1.Plots[3].Brush = Brushes.Orange;
    AddChartIndicator(VolumeDelta1);
    MySeriesDeltaL = new Series<double>(this);
    MySeriesDeltaS = new Series<double>(this);
    }
    }


    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 2)
    return;


    // Set Delta 1 (Long)

    if ((IsFirstTickOfBar)
    && (Times[0][0].TimeOfDay >= Hora_Inicio.TimeOfDay)
    && (Times[0][0].TimeOfDay < Hora_Fin.TimeOfDay)
    // && (Position.MarketPosition == MarketPosition.Flat)
    )
    { MySeriesDeltaL[1] = VolumeDelta1.DeltaClose[1];


    if ( MYCONTIDIONS1)

    { ACTIONS1}

    else if (MYCONDITIONS2)

    { EnterLong(NumContracts);
    Print("Long Position Delta");
    }

    else
    { ACTIONS3}




    What must I done to solve it?


    Thanks in advance
    Attached Files

    #2
    Hello Jorge Mendieta,

    Use Calculate.OnEachTick or .OnPriceChange.

    Below is a link to a forum post that discusses.
    https://forum.ninjatrader.com/forum/...bar#post782992

    In historical, this will also require 1-tick intra-bar granularity and TickReplay.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello Chelsea,

      I am using Calculate.OnEachTick as you can see in the code. I'm working in realtime.

      Comment


        #4
        Hello Jorge Mendieta,

        Please confirm that you have implemented 1-tick intra-bar granularity and that you have TickReplay enabled before continuing.

        Please provide a screenshot of the Strategy Performance -> strategy name -> Real-time, to confirm these are orders submitted in real-time and are not historical.
        https://ninjatrader.com/support/help...tegyFromAChart

        My thoughts are, the orders are historical. Historical data and orders are processed before real-time, even when enabling the strategy in real-time.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea.

          Unfortunately I disabled my strategy before generate the Strategy Performance screenshot, but be sure that the entries in the image were entries from yesterday.

          The tick data series was already in my code, buy I don't have TickReplay activated, Is it totally necesary? I´d prefer doesn´t use it.



          Comment


            #6
            Hello Jorge Mendieta,

            Yes, this is necessary and was advised in post # 2.

            If TickReplay is not enabled, barsAgo [0] will reference a completely different bar in historical.

            Further, any orders must be submitted to the BarsInProgress of the 1 tick series.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks Chelsea, I've activated the TickReplay, but now the Delta's values that have been storage in my own series is 0, as you can see in the print screenshot:

              Click image for larger version

Name:	image.png
Views:	130
Size:	6.9 KB
ID:	1265137

              What's wrong in this case?

              Tnx.​

              Comment


                #8
                Hello Jorge Mendieta,

                The VolumeDelta would be a custom 3rd party indicator that is not created by NinjaTrader.
                Unfortunately, I would not have any insight into the inner workings of this indicator or if this is designed to work with TickReplay.

                From here it may be necessary to do some debugging and investigating to understand the behavior.

                I made a test script you might find helpful that prints the order of BarsInProgress for a hosted indicator that adds a 1 tick series.
                This example shows the host receiving values from the hosted indicator for every tick intra-bar, albeit one bar update behind.

                Note, that for ticks that have the same timestamp, TickReplay processes these all at once.
                Attached Files
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello Chelsea, thanks for your collaboration.

                  I've been doing many test and found that my strategy works fine with TickReplay enable, but changing the: MaximumBarsLookBack = MaximumBarsLookBack.Infitine to MaximumBarsLookBack.TwoHundredFiftySix;

                  Everything is fine now!, thank you a lot.

                  JorgeE

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  71 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  143 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  76 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  47 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  51 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X