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

Adding indicator to strategy with BarsArray syntax

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

    Adding indicator to strategy with BarsArray syntax

    I am trying to create a SMA of the OrderFlowCumulativeDelta

    I have added the data series in State.Configure.

    I added the BarsArray when calling(not sure if that is the correct term) the indicator in State.DataLoaded.

    I am getting the error messages below when compiling. I haven't been able to figure out what additional arguments I am missing.


    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute, 1);
    }
    else if (State == State.DataLoaded)
    {
    OrderFlowCumulativeDelta1 = OrderFlowCumulativeDelta(BarsArray[1],Close, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Type.BidAsk, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Period.Session, 0);
    SMA1 = SMA(BarsArray[1],OrderFlowCumulativeDelta1.DeltaClose, 7);
    SMA2 = SMA(BarsArray[1],OrderFlowCumulativeDelta1.DeltaClose, 20);
    }

    DeltaCrossLe.cs No overload for method 'OrderFlowCumulativeDelta' takes 5 arguments CS1501 65 36
    DeltaCrossLe.cs No overload for method 'SMA' takes 3 arguments CS1501 66 15
    I appreciate any help

    #2
    Hello sdauteuil,

    Thanks for your post.

    From the help guide for Order Flow Cumulative Delta there are 3 parameters (4 if you include the input series). It looks like you have both BarsArray[1] and Close. BarsArray[1] would be the added 1 minute series and it would default to the close price of that data series. Close, by itself, would be the chart bars.
    Reference: https://ninjatrader.com/support/help...ive_delta2.htm

    In the two SMAs you are specifying BarsArray[1] as the input series and I think you really want just OrderFlowCumulativeDelta1.DeltaClose and then the value for the period. The help guide shows just two parameters of input series and period. Reference: https://ninjatrader.com/support/help...simple_sma.htm

    Just to help out, when you create a private instance of an indicator, feel free to name it as you wish. When I create a private indicator I don't want to type any more than I have to so I would use a name like OFCD1 = OrderFlowCumulativeDelta(.... as it is far easier for me to type OFCD1 than all of that!

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      That worked

      Thank you

      Comment


        #4
        One more question

        I had to use a 1 tick data series for Cumulative Delta but I still want the SMA to work off the 1 minute data series. I was getting an error when trying to use the 1 minute series.

        If I use the code below does that mean the SMA is operating on the 1 tick series.

        else if (State == State.Configure)
        {
        AddDataSeries(BarsPeriodType.Tick, 1);
        AddDataSeries(BarsPeriodType.Minute, 1);
        }
        else if (State == State.DataLoaded)
        {
        OrderFlowCumulativeDelta1 = OrderFlowCumulativeDelta(BarsArray[1], NinjaTrader.NinjaScript.Indicators.CumulativeDelta Type.BidAsk, NinjaTrader.NinjaScript.Indicators.CumulativeDelta Period.Session, 0);
        SMA1 = SMA(OrderFlowCumulativeDelta1.DeltaClose, 7);
        SMA2 = SMA(OrderFlowCumulativeDelta1.DeltaClose, 20);

        Comment


          #5
          Hello sdauteuil,

          Thanks for your reply.

          The BarsArray[1] will be the first added data series which as shown in your post is the 1 tick series. You would need to rearrange the order of adding data series if you want BarsArray[1] to be the 1-minute data series.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            I am trying to use BarsArray

            SMA1(BarsArray[2])[0]

            also tried

            SMA1(BarsArray[2])

            Getting error message
            DeltaCrossLe.cs The name 'SMA1' does not exist in the current context CS0103 85 8
            Last edited by sdauteuil; 08-24-2021, 01:28 PM.

            Comment


              #7
              When I tried to enable the strategy using the 1 minute data series with the cumulative delta I was getting an error message in the log and the strategy wouldn't enable that is why I added the 1 tick series.

              It seems like no matter the order I put the AddDataSeries I will still have to use the 1 tick series for Cumulative Delta.

              Which being used when calling the SMA indicator.

              If that makes sense.

              Comment


                #8
                Hello sdauteuil,

                Thanks for your reply.

                Can you clarify what you are trying to do here and specify where in the code this is?

                Earlier you were creating SMA1 in State.DataLoaded but that was using the Order flow CD as input.



                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Would it be appropriate to put the logic under BarsInProgress == 2

                  If BarsInProgress == 2
                  {
                  if (CrossAbove(SMA1, SMA2, 1))
                  {
                  EnterLong(Convert.ToInt32(DefaultQuantity), @"Delta Cross Le");
                  }
                  }

                  Comment


                    #10
                    Basically I am just trying to test using a simple SMA cross on a 1 minute chart using the Cumulative Delta as the input for the SMA.

                    The Cumulative Delta seems to be throwing a wrench in the works because it needs the one tick series.

                    Comment


                      #11
                      Hello sdauteuil,

                      Thanks for your reply.

                      I am going to guess that you are creating the SMA1 as you showed in your post #3. You want the SMA of the OrderFlowCumulativeDelta.

                      It should look like:
                      SMA1 = SMA(OrderFlowCumulativeDelta1.DeltaClose, 7);
                      SMA2 = SMA(OrderFlowCumulativeDelta1.DeltaClose, 20);

                      The OrderflowcumulativeDelta indicator does need the 1 tick data series but you want the input to the Orderflow indicator to be the 1 minute bars (I think)

                      You can rearrange the sequence and add the 1-minute series first and then the Tick series so that BarsArray[1] remains as the minute data.

                      Assuming you do that, then to support the cumulative delta you would need something similar to the help guide example, in OnBarUpdate():

                      else if (BarsInProgress == 2)

                      {

                      // 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[2].Count - 1, 1);

                      }


                      Paul H.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by GussJ, 03-04-2020, 03:11 PM
                      16 responses
                      3,281 views
                      0 likes
                      Last Post Leafcutter  
                      Started by WHICKED, Today, 12:45 PM
                      2 responses
                      19 views
                      0 likes
                      Last Post WHICKED
                      by WHICKED
                       
                      Started by Tim-c, Today, 02:10 PM
                      1 response
                      9 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by Taddypole, Today, 02:47 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post Taddypole  
                      Started by chbruno, 04-24-2024, 04:10 PM
                      4 responses
                      53 views
                      0 likes
                      Last Post chbruno
                      by chbruno
                       
                      Working...
                      X