Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Cumulative Delta EMA for Conditions in Strategy

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

    Using Cumulative Delta EMA for Conditions in Strategy

    I have Order Flow Cumulative Delta added as a secondary data source in my strategy and have 3 period EMA attached to it, like so:

    Code:
    else if (State == State.DataLoaded)
                {
                    cumulativeDelta                = OrderFlowCumulativeDelta(Close, NinjaTrader.NinjaScript.Indicators.CumulativeDeltaType.BidAsk, NinjaTrader.NinjaScript.Indicators.CumulativeDeltaPeriod.Session, 0);
                    EMA1                = EMA(cumulativeDelta.DeltaHigh, 3);
                
                }​​
    which picks up the value for Print commands or Data Box display, but I'm not able to get it to work for a IsFalling or IsRising condition in OnBarClose. Do I need to call it with BarsArray[1] or is it deeper than that? Hoping you could help point the way.

    Thanks!

    #2
    Hello swjake,

    Thank you for your post.

    Are you saying that you have an IsFalling or IsRising condition using cumulative delta that is not being triggered?

    Have you added 1 tick data series in State.Configure for the indicator (cumulative delta runs off of tick data)?

    Please see the Help Guide code snippet on calling OrderFlowCumulativeDelta() method by reference:


    In your script, make sure you have logic to update the secondary series of the hosted indicator to make sure the values you get in BarsInProgress == 0 are in sync.

    Please let us know if you have any further questions.

    Comment


      #3
      Thank you for your reply. Yes, I have tick data series added.

      Code:
      else if (State == State.Configure)
                  {    
                      AddDataSeries(Data.BarsPeriodType.Tick, 1);        
                  }​
      and in OnBarUpdate I have BarsInProgress updated:

      Code:
      if (BarsInProgress == 0)
                                  {
                                        // Print the close of the cumulative delta bar with a delta type of Bid Ask and with a Session period
                                        //Print("Delta Close: " + cumulativeDelta.DeltaClose[0]);
                                  }
                                  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);
                                  }​
      I'm able to use CumDelta in my order conditions just fine, it's when I'm trying to call the EMA. I think the error returned was, "the name EMA1 does not exist in the current context".

      I'm able to see the correct EMA1 value in DataBox or in a print command:

      Code:
      Print(string.Format("{0} | Close[1] {1} < 19 Level {2} | DeltaLow {3} > DeltaLow[1] {4} | Current DeltaLow: {5} EMA1 {6}",
                                          Time[0], Close[1], NineteenLevel, cumulativeDelta.DeltaLow[1], cumulativeDelta.DeltaLow[2], cumulativeDelta.DeltaLow[0],EMA1[0]));  ​
      But when trying to add anywhere else in script, such as a condition for entry, it returns that error.

      Comment


        #4
        Hello,

        The error 'The name "__" does not exist in the current context' means that the EMA1 variable you are using does not exist where you are trying to use it.

        What line does the error say this is occurring on? Can you share that line and where it is in the code?

        Comment


          #5
          I didn't save log file and deleted code. I'll try to recreate and then post back. Thanks Gaby!

          Comment


            #6
            Ok, so tried this within OnBarUpdate:

            Code:
             if (IsFalling(EMA1(3))) //Line 249
                                         {
                                             Print(string.Format("{0}", EMA1[0])); 
                                         }
                                        
                                         else if (IsRising(EMA1(3))) //Line 254
                                         {
                                             Print(string.Format("{0}", EMA1[0]));
                                         }​
            When trying to compile Error: The Name 'EMA1' does not exist in the current context.

            Also put this in order condition in OBU:

            Code:
            (EMA1[0] < EMA1[1])
            which compiles but so far haven't had a trigger to see if working...

            Comment


              #7
              Hello,

              Which line specifically does the compile error list as the line with the error?

              Since you mentioned you deleted the code, can you confirm if you still have EMA1 defined in Stata.DataLoaded? And are you also calling private EMA EMA1; at the class-level?

              I look forward to your response.

              Comment


                #8
                Think I got it. This works:

                Code:
                if (IsRising(EMA1))
                                            {
                                                Print("EMA1 is rising");
                                            }
                                            else if (IsFalling(EMA1))
                                            {
                                                Print("EMA1 is falling");
                                            }​

                Comment

                Latest Posts

                Collapse

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