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

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
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Helpful as always, NinjaTrader_Kate ! Thank you!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by DJ888, Today, 10:57 PM
          0 responses
          6 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          158 views
          0 likes
          Last Post loganjarosz123  
          Started by Belfortbucks, Today, 09:29 PM
          0 responses
          7 views
          0 likes
          Last Post Belfortbucks  
          Started by zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          151 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Working...
          X