Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help with Daily SMA calculation on primary Tick series

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

    Need help with Daily SMA calculation on primary Tick series

    I run my strategy with primary Timeseries - 900 Tick. I have additional Data Series - Daily.

    I want to have SMA(30) of Daily Body size. To achieve that, I first created additional series:

    Code:
    if (BarsInProgress == 7) // Daily 
    {
                    BODY0D[0] = Math.Abs(Close[0] - Open[0]);
                    BODY30D = SMA(BODY0D, 30)[0];
    }
    However, it doesn't work properly, I tried to print BODY0D[1], BODY0D[2], BODY0D[3] values, and they all return 0.

    I tried to change code to: BODY0D[0] = Math.Abs(Closes[7] - Opens[7]);, but it does give error: "Operator '-' cannot be applied to operands of type 'NinjaTrader.NinjaScript.PriceSeries' and 'NinjaTrader.NinjaScript.PriceSeries'"
    I also get the same error, if I try to change code of BODY30D to BODY30D = SMA(Closes[7] - Opens[7], 30)[0];

    So how can I get SMA(30) Of Daily Body working properly with 900 Tick as primary series?

    #2
    Hello UltraNIX,

    Thank you for your inquiry.

    Closes[7] - Opens[7] would try to subtract the entire Open Series from the entire Close series - you'd use Closes[7][0]-Opens[7][0] to get the current value of those.

    That being said, I've created a simple example script that is working for me. You can test this on a chart with at least 30 days to load - I tested on a 90 day chart.

    Do you see values as you would expect with this example?

    Thanks in advance; I look forward to assisting you further.
    Attached Files

    Comment


      #3
      Thanks, it works! I inspected the code, it seems, i was using BODY0D = new Series<double>(this) INSTEAD OF BODY0D = new Series<double>(BarsArray[1], MaximumBarsLookBack.TwoHundredFiftySix);

      By the way another question. I get 0, when I try this formula: BODY30D[0] * (29/30)

      And it's the (29/30) part that is causing an error. How can I solve it. The idea is to "front-run" indicator calculation (as the "real value" would only be visible on the next daily bar) and use 29/30 from BODY30D[0] + 1/30 * (Math.Abs(Close[0] - CurrentDayOHL(Close).CurrentOpen[0])))

      Comment


        #4
        Hello UltraNIX,

        Thank you for your reply.

        You're likely hitting a casting issue. Try something like this:

        double myValue = BODY30D[0] * (29.0/30.0);

        Making the integer values into a double by adding a decimal should resolve that and return as you'd expect.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Helpful as always, NinjaTrader_Kate ! Thank you!

          Comment

          Latest Posts

          Collapse

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