Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add / Substartct two EMA's

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

    Add / Substartct two EMA's

    In strategy builder how can I code on the left side - if EMA(A) - EMA(B). Thanks.

    #2
    Hi dkbyond, thanks for your note.

    Unfortunately, arithmetic between two indicator values is not supported in the strategy builder. The offset setting for a value is the closest to arithmetic you can get in the builder. Any other computations need to be written by hand in the NinjaScript Editor. I attached a sample indicator for your reference. To compile and run, place the file within Documents\NinjaTrader 8\bin\Custom\Indicators and press F5 in the NInjaScript editor.

    Best regards,

    -ChrisL
    Attached Files

    Comment


      #3
      Thanks Chris. Will give it a try.

      Comment


        #4
        Understood the script a little bit. Now need help on the below.


        FastLine = ExpAverage(close, 20) - ExpAverage(close, 40); --> this is how as per your script Value[0] = EMA1[0] - EMA2[0]; where EMA1 = 20 and EMA2 = 40.


        SlowLine = ExpAverage(FastLine, 10); ---> how do I code this SlowLine? Thanks.

        Comment


          #5
          Hi dkbyond, thanks for your reply.

          What is ExpAverage? I'm not seeing anything in our documentation pages for this. From the looks of it, this takes a Series object and not a double assuming FastLine is a double data type variable. You will need to make a custom series and for each bar, calculate FastLine roughly:

          MyCustomSeries[0] = ExpAverage(Close, 20) - ExpAverage(Close, 40);
          if(CurrentBar < 10)
          return;
          SlowLine = ExpAverage(MyCustomSeries, 10);

          Comment


            #6
            Sorry my bad, it is exponential average. So I want a indicator plotting first line MyCustomSeries[0] = ExpAverage(Close, 20) - ExpAverage(Close, 40); and second line plotting ExpAverage(MyCustomSeries, 10);

            Later I would want to use this indicator in my crossover strategy (first line crosses above second) in strategy builder. I will go through the information you provided, if still stuck, will come back. Thanks.

            Comment


              #7
              Hi Chris,

              It seems what I wanted can be achieved by MACD, where (MyCustomSeries[0] = ExpAverage(Close, 20) - ExpAverage(Close, 40)) is the MACD and (ExpAverage(MyCustomSeries, 10)) is the AVG of MACD. My query is solved.Thanks.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Mindset, 04-21-2026, 06:46 AM
              0 responses
              87 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by M4ndoo, 04-20-2026, 05:21 PM
              0 responses
              134 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by M4ndoo, 04-19-2026, 05:54 PM
              0 responses
              68 views
              0 likes
              Last Post M4ndoo
              by M4ndoo
               
              Started by cmoran13, 04-16-2026, 01:02 PM
              0 responses
              118 views
              0 likes
              Last Post cmoran13  
              Started by PaulMohn, 04-10-2026, 11:11 AM
              0 responses
              67 views
              0 likes
              Last Post PaulMohn  
              Working...
              X