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

Error in adding exponential smoothing to DM

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

    Error in adding exponential smoothing to DM

    Hello Everyone,

    I tried to add an exponential smoothing to the default Ninja Indicator DM, Here is What I did,

    I replaced the following code:
    Code:
                                    if (CurrentBar < Period)
    				{
    					sumTr.Set(sumTr[1] + tr[0]);
    					sumDmPlus.Set(sumDmPlus[1] + dmPlus[0]);
    					sumDmMinus.Set(sumDmMinus[1] + dmMinus[0]);
    				}
    				else
    				{
    					sumTr.Set(sumTr[1] - sumTr[1] / Period + tr[0]);
    					sumDmPlus.Set(sumDmPlus[1] - sumDmPlus[1] / Period + dmPlus[0]);
    					sumDmMinus.Set(sumDmMinus[1] - sumDmMinus[1] / Period + dmMinus[0]);
    				}
    with :

    Code:
                                    sumTr     =[COLOR="Red"]Value[/COLOR][1]+(1/14)*(tr[0]-Value[1]);
    				sumDmPlus =[COLOR="red"]Value[/COLOR][1]+(1/14)*(dmPlus[0]-Value[1]);
    				sumDmMinus=[COLOR="red"]Value[/COLOR][1]+(1/14)*(dmMinus[0]-Value[1]);
    for convenience, I did not change the name the variables sumTr, sumDmPlus, sumDmMinus, and they actually represent smoothed Tr, Dmplus, DmMinus respectively,

    but the compiler show the errors(shown in red) as :

    Cannot implicitly convert type 'double' to 'NinjaTrader.Data.DataSeries' (NT0029).

    Anyone knows why is this happening ?

    Thank you !
    Wolfcuring

    #2
    Hello wolfcuring,

    This is because you are trying to assign a double value directly to a DataSeries object. You would want to use the .Set() command to assign the values for example:

    Code:
    sumTr.Set(Value[1]+(1/14)*(tr[0]-Value[1]));
    sumDmPlus.Set(Value[1]+(1/14)*(dmPlus[0]-Value[1]));
    sumDmMinus.Set(Value[1]+(1/14)*(dmMinus[0]-Value[1]));
    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Thank you JC !!

      Comment


        #4
        Hi,

        I have tried adding the piece of code shown as the replacement for existing one in the 'else brackets' to get the exponential +DM and -DM. but the resulting graph doesn't display anything. Can anyone please point my mistake and let me know how to make this indicator exponentially smooth.

        Comment


          #5
          VarunDivakar, welcome to our forums - could you please post what exactly you're trying to use? Would the log tab in NT (rightmost tab in Control Center) have any errors listed as you apply the study?
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Originally posted by VarunDivakar View Post
            Hi,

            I have tried adding the piece of code shown as the replacement for existing one in the 'else brackets' to get the exponential +DM and -DM. but the resulting graph doesn't display anything. Can anyone please point my mistake and let me know how to make this indicator exponentially smooth.
            It is not clear what you are trying to achieve.

            The Directional Movement indicator was developed by Welles Wilder. The plots can be obtained by following the four steps below:

            (1) calculate true range, DM+ and DM-
            (2) exponential smoothing of true range, DM+ and DM-
            (3) calculate DI+ and DI- as ratios from the smoothed parameters as per step 2
            (4) calculate ADX from from DI+ and DI-

            All this is done by the NinjaTrader default indicator DM, which displays DI+, DI- and the ADX.

            What exactly do you need? The code snippet below does not lead anywhere, because the NinjaTrader indicator already does the exponential smoothing as required. It simply uses a more efficient algorithm which has redundant divisions eliminated. In my opinion there is nothing to code.

            If you look for an enhanced version of the DM which has the exponential smoothing (step 2) replaced with any of 27 other moving averages, please contact me via private message.
            Attached Files

            Comment


              #7
              Hi Everyone,

              Thank you for your reply. Sorry for not being clear in my earlier post. What i wanted to say was that. NinjaTrader_JC had posted the following code.

              sumTr.Set(Value[1]+(1/14)*(tr[0]-Value[1])); sumDmPlus.Set(Value[1]+(1/14)*(dmPlus[0]-Value[1])); sumDmMinus.Set(Value[1]+(1/14)*(dmMinus[0]-Value[1]));
              I just wanted to know where this code would go in the original code built in NT.
              I tried replacing the code existing in the else brackets to compare the resulting difference in the values of +DM and -DM. but the result i got was a no graph.
              I was just wondering where my mistake was.

              Thank you,

              Comment


                #8
                Originally posted by VarunDivakar View Post
                Hi Everyone,

                Thank you for your reply. Sorry for not being clear in my earlier post. What i wanted to say was that. NinjaTrader_JC had posted the following code.

                sumTr.Set(Value[1]+(1/14)*(tr[0]-Value[1])); sumDmPlus.Set(Value[1]+(1/14)*(dmPlus[0]-Value[1])); sumDmMinus.Set(Value[1]+(1/14)*(dmMinus[0]-Value[1]));
                I just wanted to know where this code would go in the original code built in NT.
                I tried replacing the code existing in the else brackets to compare the resulting difference in the values of +DM and -DM. but the result i got was a no graph.
                I was just wondering where my mistake was.

                Thank you,
                The code is false and cannot work. Value[1] refers to the prior value of the ADX. Subtracting the prior value of the ADX from the true range does not produce a useable result. Just forget that piece of code, it does not make any sense.

                If you tell us what you want to achieve - other than copying false code - we will help you.

                Comment


                  #9
                  Hi,

                  Thank you very much. The reason i started looking into this exponential ADX was because i have a reuters EIKON terminal they have an ADX, +DM and -DM exponential as well. I checked both NT and EIKON the values are significantly different in any given time frame, and eikon was giving a much better entry point than NT. So, i started looking into the formula used to check for the differences in both of them. As far as i can tell there is absolutely no difference in both. But results vary.

                  Thank you.

                  Comment


                    #10
                    If the values that you observed were different, there are two possible explanations

                    -> either the data input for the indicators was different (this can be related to the data feed and/or session templates)
                    -> or the formulae to calculate the DM+, DM- and ADX were different

                    If you post the two charts, we should be able to find out the reason for the difference.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Javierw.ok  
                    Started by timmbbo, Today, 08:59 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post bltdavid  
                    Started by alifarahani, Today, 09:40 AM
                    6 responses
                    40 views
                    0 likes
                    Last Post alifarahani  
                    Started by Waxavi, Today, 02:10 AM
                    1 response
                    18 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by Kaledus, Today, 01:29 PM
                    5 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X