Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

cumulative delta [bars ago]

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

    cumulative delta [bars ago]

    Dear sir or Madams,

    I'm working on a partial logic for a strategy or indicator and trying this in an isolated script first.
    Basically I want to be able to compare the current cumulative delta close or low with the one from the previous bar in a primary data series and potentially then the previous with the one before that.

    I read up on multiseries and cumulative data and got it somehow working for the current bar but I dont seem to manage to get the data for a .close[1] (assuming that is the "bar ago")
    or the script will just refuse to apply to the chart.

    The line in the script below: "D0 = cumulativeDelta.DeltaClose[0];" I thought is setting the delta close for the current bar to the variable D0.
    Script works as expected.
    As soon as I change the number in the brackets (which I thought is bars ago) the script refuses to apply.
    If you could help me to get to the point where I can say "if the close of the delta of the delta is greater than the close of the delta from the previous bar..."

    I would be very grateful for any pointers.
    Thank you in advance!


    Code:
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class testing : Strategy
    {
    private OrderFlowCumulativeDelta cumulativeDelta;
    private double D0;
    private double D1;
    private double D2;
    private double D3;
    
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "testing";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    AddDataSeries("MNQ 06-22", Data.BarsPeriodType.Second, 15, Data.MarketDataType.Last);
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }
    else if (State == State.DataLoaded)
    {
    cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 0);
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {
    D0 = cumulativeDelta.DeltaClose[0];
    //Print("Delta Close: " + cumulativeDelta.DeltaClose[0]);
    
    }
    else if(BarsInProgress == 1)
    {
    cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count -1, 1);
    }
    
    
    // Set 1
    if (D0 > 0)
    {
    BarBrush = Brushes.Yellow;
    }
    else if (D0 < 0)
    {
    BarBrush = Brushes.Turquoise;
    }
    }
    }
    }

    #2
    Hello _WELD_,

    When using BarsAgo you need to let the script know to wait until you have that much data. For example:
    Code:
    if(CurrentBar < 1) return;
    D0 = cumulativeDelta.DeltaClose[0];
    D1 = cumulativeDelta.DeltaClose[1];
    You are using multiple series so this really should be:

    Code:
    if(CurrentBars[0] < 0 || CurrentBars[1] < 1) return;
    
    if (BarsInProgress == 0)
    {
        D0 = cumulativeDelta.DeltaClose[0];
        D1 = cumulativeDelta.DeltaClose[1];
    }
    Additionally you should reverse the AddDataSeries if you are trying to follow the help guide sample:
    Code:
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    AddDataSeries("MNQ 06-22", Data.BarsPeriodType.Second, 15, Data.MarketDataType.Last);
    With the code you have now the orderflow is being updated incorrectly using the MNQ series. It needs to be BarsInProgress 2 if you do not reverse the AddDataSeries.
    Last edited by NinjaTrader_Jesse; 06-06-2022, 12:44 PM.

    Comment


      #3
      Thank you, Jesse, for the fast response!
      I will get right on it despite a huge Jetlag
      I was just thinking I should delete the MNQ data series because its redundant, when I apply it to a MNQ 15sec chart it already becomes the primary, right?
      That way the tick data becomes the bars InProgress ==1, I really dont need to list the data of the chart that I apply it to, as I understand.
      Thank you for your help!

      Comment


        #4
        Hello _WELD_,

        Yes if you are using a 15 second primary that is redundant, you only need to add additional data in different timeframes or for different instruments. After removing that the sample from the help guide would match the code you have so it should work correctly like that sample.

        Comment


          #5
          Ok I had some trouble at first but then I figured it out, I actually had to use the "required bars to trade" that are set in my script, not just A bar to be loaded, otherwise the script would refuse to be applied.
          if(CurrentBars[0] < 20 || CurrentBars[1] < 20)

          Thank you again, Jesse!
          Last edited by _WELD_; 06-06-2022, 10:34 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          43 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          47 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X