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

distance between 2 EMAs

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

    distance between 2 EMAs

    Hello. Trying to restrict trades from entering if the 21 is too far from the 50. Or could be worded the other way. Only enter trade if the 21 is within a certain amount of ticks from the 50. Either way. Can it be done on the strategy builder? Thank you

    #2
    Hi Touch-Ups, thanks for posting. You would need to be able to do some math operations on the value of each EMA object, so unfortunately that would not be possible in the builder. You would need to check:

    Code:
    if(Math.Abs((EMA(21)[0]-EMA(50)[0])/Bars.Instrument.MasterInstrument.TickSize) > SomeTickValue)
    {}​


    Kind regards,
    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Well... I ran across EMAticksaway indicator from here:

      Hello, I have been looking through the huge list of indicators to see if I can find one that measures the distance from EMA to the current candle. For example, it asks for what EMA you want let's say EMA13 for starters, and then it would always tell you how man ticks away from that EMA the closest part of the current candle is.


      It would be perfect, but I can not get it to work in the strategy analyzer. I don't get any errors. It just will not allow any trades when I run it.

      Comment


        #4
        Never mind. Got the price from ema to work. That is not what I wanted. Got myself confused messing with this so much. Really want the ema distance thing, but if it can't be done, then you have answered my question. thanks

        Comment


          #5
          Hi Touch-Ups, thanks for the follow up.The indicator was not adding a Plot that strategies need to read data. I added a Plot object to it called "DifferenceValue". It is now useable in a strategy.

          Kind regards.
          Attached Files
          Chris L.NinjaTrader Customer Service

          Comment


            #6
            If you set the input series to an EMA you can take the difference of two EMA objects e.g.



            Kind regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              You can work with the distance between moving averages in the strategy builder. It requires using the "offset" for the math of subtracting one from the other and it would require using the "points" instead of a tick reference.

              I've attached an example using the MES 12-22, which has 4 ticks per point. In the example I created the conditions to look for a spread of less than or equal to +/- 1 (4 ticks) and when true to color the background. You use the +/- because sometimes one moving average is above or below the other. As you can see it is showing correct functionality.

              Click image for larger version

Name:	StrategyBuilderEMAspread.png
Views:	308
Size:	121.7 KB
ID:	1219056


              Here is a link to the strategy builder help guide on Offset: https://ninjatrader.com/support/help...setAnItemValue

              It would also be possible to convert to ticks however it is more complex and involves storing values in custom series in the strategy builder.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by sidlercom80, 10-28-2023, 08:49 AM
              167 responses
              2,260 views
              0 likes
              Last Post jeronymite  
              Started by warreng86, 11-10-2020, 02:04 PM
              7 responses
              1,361 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by Perr0Grande, Today, 08:16 PM
              0 responses
              5 views
              0 likes
              Last Post Perr0Grande  
              Started by elderan, Today, 08:03 PM
              0 responses
              9 views
              0 likes
              Last Post elderan
              by elderan
               
              Started by algospoke, Today, 06:40 PM
              0 responses
              10 views
              0 likes
              Last Post algospoke  
              Working...
              X