Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Cumulative Delta Indicator in a Strategy

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

    Using Cumulative Delta Indicator in a Strategy

    Hi,

    I’m trying to test a 3-series code in which the 3rd series (BarsPeriodType.Volume, Value=100) will call the “OrderFlowCumulativeDelta” indicator. My idea is to compose a buy condition in which the candle for the cumulative delta for series3 will be green (as part of my buy condition). So, here’s my trial:

    private OrderFlowCumulativeDelta CumulativeDelta100buy;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    //(then typical description)
    FirstSeries = new BarsPeriod(){BarsPeriodType=BarsPeriodType.Volume, Value=3000};
    SecondSeries = new BarsPeriod(){BarsPeriodType=BarsPeriodType.Volume, Value=500};
    ThirdSeries = new BarsPeriod(){BarsPeriodType=BarsPeriodType.Volume, Value=100};
    }
    else if (State == State.Configure)
    {
    AddDataSeries(FirstSeries);
    AddDataSeries(SecondSeries);
    AddDataSeries(ThirdSeries);
    AddDataSeries(Data.BarsPeriodType.Tick, 1); // not quite sure about this step
    }
    else if (State == State.DataLoaded)
    {
    Brush1 = new SolidColorBrush((Color)ColorConverter.ConvertFromS tring("#FFCCCCCC"));
    Brush1.Freeze();
    }
    }
    protected override void OnBarUpdate()
    {
    if (CurrentBars[1] < BarsRequiredToTrade)
    return;
    if (CurrentBars[2] < BarsRequiredToTrade)
    return;
    if (CurrentBars[3] < BarsRequiredToTrade)
    return;


    bool buy_condition_for_seires_1 // easy
    bool buy_condition_for_seires_2 // easy
    bool buy_condition_for_seires_3 // this is where your kind help is graciously needed

    // Here is how I tried to describe buy_condition_for_seires_3
    //
    bool CumulativeDelta100buy = ((OrderFlowCumulativeDelta(BarsArray[3], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaClose[0]) > (OrderFlowCumulativeDelta(BarsArray[3], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Session, 0).DeltaOpen[0]));
    //

    bool buy = buy_condition_for_seires_1 && buy_condition_for_seires_2 && buy_condition_for_seires_3;

    if (buy)
    {
    EnterLong(ContractSize);
    SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
    SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
    }

    My problem seems to be that, for condition#3, it’s not accurate so far where it sometimes forms a red candle (on the cumulative delta on series3) where I need it to be only green ones. Any idea how to rectify this simply?


    Thank you..

    #2
    Hello Abdullah_KSA,

    Thanks for your message.

    With Order Flow indicators, it is important to update that indicator's BarsArray[1] from the hosting scripts single tick data series. In your case, the single tick data series is BarsInProgress == 4.

    You may see our example snippets for how to instantiate an Order Flow Cumulative delta. The only difference in your case is that:

    Code:
    else if (BarsInProgress == 1)
    {
          // We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync
          cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
    }
    Would actually take place on BarsInPorgress == 4.



    As an aside, I see that you are calling the Set methods after EnterLong. Set methods prep NinjaTrader to submit target and stop once an entry order is seen as filled, so it is best to call them with initial levels before your entry method.

    After confirming you have the Update portion added to OnBarUpdate, please using prints to confirm the output from the indicator is what you expect. From there finishing the condition should be straight forward.

    Let us know if there is anything else we can do to help.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X