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

Problem: EMA SMA calculation

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

    Problem: EMA SMA calculation

    Hello,

    In developing a strategy I have a strange behaviur in a certain point of ema and sma.
    I can't find the problem also using debug so I post the file with the strategy fault and a picture and debug info when fault occur.
    I verify the error comparing the chart and the value from ema and sma function.

    In the debug file you can see:
    Sma =3,23340740740741 ema= 3,29517788702776 Close = 3,456 PROBLEM: should be (measured from the chart): ema= 3,45 Sma= 3,40
    Sma =3,25089655172414 ema= 3,31540181975563 Close = 3,402 PROBLEM: should be (measured from the chart): ema= 3,44 Sma= 3,445

    I use yahoo data and Intesa as stock. The first error happens on 7/08/2015.
    All other value before is ok.

    Thanks in advance
    Attached Files

    #2
    Hello henry77,

    Thank you for your post.

    Please use the attached test and advise if you see the same case.
    Attached Files

    Comment


      #3
      Hello,

      Thank you for your reply. I tested your indicator with no error found.
      But I can't understand what happen in the strategy. What I can do/verify?
      Thanks a lot for your effort.
      Last edited by henry77; 04-15-2017, 03:58 AM.

      Comment


        #4
        Hello,

        I found the line that generate the error but I can't understand why is a problem.
        The error disappear when I comment following line in (State == State.Configure)

        // Add week data serie (5 days)
        AddDataSeries(Data.BarsPeriodType.Day, 5); // BarsArray[1] (line to be commented to fix error sma, ema) I had inserted this dataseries but not used in the code yet.

        Is there any explanation for that behavior ? or I added data series in wrong syntax?

        Thanks

        Comment


          #5
          Hello henry77,

          Thank you for your response.

          I am not seeing different values from the chart. Can you advise a specific date and time where the values differ?
          Please add the following to your prints:
          Code:
          					Print("");
          					Print(Time[0]);
          					Print("Sma =" + sma + " ema= " + ema + " Close = " + close);
          I look forward to your response.

          Comment


            #6
            Hello,

            After same debug and experiment I think when using multitime frame (adding another time series)

            I post two log file:
            NinjaScript Output_camelback_error2_without_multiframes.txt : log file without line AddDataSeries(Data.BarsPeriodType.Day, 5);

            NinjaScript Output_camelback_error2.txt with AddDataSeries(Data.BarsPeriodType.Day, 5);

            Note that in the first log file there are two error:
            first error:
            06/08/2015 06:00:00
            Sma =3,43369230769231 ema= 3,34812326264384 Close = 3,456
            30/07/2015 06:00:00
            Sma[1] =3,42433333333333 ema[1]= 3,33271230016439 Close[1] = 3,438
            where sma[1], ema[1] refer to day-1

            Am Iusing multitime frame in a wrong way?

            Close[0], High[0] must be write Close[0][0], High[0][0] ??
            Close[1], High[1] seem refer to Close[1][0], High[1][0] ??

            Thanks
            Attached Files
            Last edited by henry77; 04-28-2017, 03:27 AM.

            Comment


              #7
              Hello Henry77,

              Thank you for your response.

              Close[0], High[0] must be write Closes[0][0], Highs[0][0].
              Close[1], High[1] refers to the prior bar, not another bar series. You will want to use Closes and Highs in the following manner: Closes[1][0] and Highs[1][0]

              I am not able to find the cause in your script, however if you are not using the correct calls as detailed above this would affect the data being output.

              Please let me know if you have any questions.

              Comment


                #8
                Thank you for your time.
                In my script I use only primary bar so I used only Close[0], High[0] etc for reference data, so the behavoiur is very strange.
                I don't know why there are present errors when added another time series.
                For now I decide to not to use multi time frame data series. If i will find something I will write to forum.

                Thanks

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by maybeimnotrader, Yesterday, 05:46 PM
                4 responses
                23 views
                0 likes
                Last Post maybeimnotrader  
                Started by frankthearm, Today, 09:08 AM
                6 responses
                24 views
                0 likes
                Last Post frankthearm  
                Started by adeelshahzad, Today, 03:54 AM
                5 responses
                33 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by stafe, 04-15-2024, 08:34 PM
                7 responses
                32 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by merzo, 06-25-2023, 02:19 AM
                10 responses
                823 views
                1 like
                Last Post NinjaTrader_ChristopherJ  
                Working...
                X