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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    61 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