Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Calling cumulativeDelta second instrument

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

    Calling cumulativeDelta second instrument

    I have read multiinstrument samples and also cumulativeDelta help. I have tried many combinations and no one works.

    I am trying to code an strategy that uses cumulativeDelta from NQ and also from a secondary serie as MNQ. The lines would be:

    public class NQ60ORMNQ : Strategy
    {
    private OrderFlowCumulativeDelta cumulativeDelta;
    private OrderFlowCumulativeDelta cumulativeDelta1;

    ......

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    DeltaLimit = 75;
    DeltaLimit2 = 115;
    ......

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    AddDataSeries("MNQ 12-20", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
    }
    else if (State == State.DataLoaded)
    {
    cumulativeDelta = OrderFlowCumulativeDelta(CumulativeDeltaType.BidAs k, CumulativeDeltaPeriod.Bar, 0);
    cumulativeDelta1 = OrderFlowCumulativeDelta(BarsArray[4], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0);
    }
    protected override void OnBarUpdate()

    if (BarsInProgress == 1 && BarsInProgress == 2)
    {
    cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
    cumulativeDelta1.Update(cumulativeDelta1.BarsArray[2].Count - 1, 1);
    }

    // Set 1
    if (cumulativeDelta.DeltaHigh[1] > DeltaLimit || cumulativeDelta1.DeltaHigh[0] > DeltaLimit2)

    {
    if (BarsInProgress == 0)
    { "Several Conditions"

    Any idea what is wrong there? How can I call second instrument cumulativeDelta?

    #2
    Hello Impeesa,

    Thanks for your post.

    This section will never be true because only 1 bars object can call OnBarUpdate at a time:

    if (BarsInProgress == 1 && BarsInProgress == 2)
    {
    cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
    cumulativeDelta1.Update(cumulativeDelta1.BarsArray[2].Count - 1, 1);
    }


    I would suggest something like:

    if (BarsInProgress == 1)
    {
    cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
    {
    else if (BarsInprogress == 2)
    {
    cumulativeDelta1.Update(cumulativeDelta1.BarsArray[2].Count - 1, 1);
    }


    Also, this statement: cumulativeDelta1 = OrderFlowCumulativeDelta(BarsArray[4], CumulativeDeltaType.BidAsk, CumulativeDeltaPeriod.Bar, 0); References BarsArray[4] which i don't see listed.
    BarsArray 0 will be the chart bars
    BasrArray 1 is AddDataSeries(Data.BarsPeriodType.Tick, 1);
    BarsArray 2 is AddDataSeries("MNQ 12-20", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);

    Finally, this line, will be run every time OnBarUpdate() is called no matter which series called it.:

    if (cumulativeDelta.DeltaHigh[1] > DeltaLimit || cumulativeDelta1.DeltaHigh[0] > DeltaLimit2)

    I would recommend reading this section of the help guide to better understand Multi timeframe/instrument programming: https://ninjatrader.com/support/help...nstruments.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by junkone, Today, 11:37 AM
    2 responses
    14 views
    0 likes
    Last Post junkone
    by junkone
     
    Started by frankthearm, Yesterday, 09:08 AM
    12 responses
    44 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by quantismo, 04-17-2024, 05:13 PM
    5 responses
    35 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by proptrade13, Today, 11:06 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    36 views
    0 likes
    Last Post love2code2trade  
    Working...
    X