Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate Distance

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

    Calculate Distance

    Hi!
    Using the strategy builder:

    is there a way to calculate the distance between price (open) and EMA?
    i'd like to use it for an entry condition:
    something like "distance from price to EMA" needs to be smaller than "x".

    any other way to calculate will also be fine!
    anybody any ideas ?
    thank you


    #2
    Hello Tradexxx,

    Thanks for your post.

    The Strategy Builder does have some functionality for creating mathematical offsets, however more intuitive and robust solutions can be programmed by hand.

    In the Builder, I would suggest using separate conditions to consider cases when the Open is greater than the EMA or if the EMA is greater than the open. This is relevant because if you subtract the EMA from the Open, you could get a negative number which may not be what your logic is set up to check.

    I've recorded a short video showing how you could check if Open is greater than the EMA value, and then to check if the Open - the EMA value is less than a value you specify.

    Demo - https://drive.google.com/file/d/1xQM...w?usp=drivesdk

    Please let me know if I can be of further assistance.

    Comment


      #3
      Hi Jim,
      thank you for the information and the video! nice job!!

      Comment


        #4
        Hello NinjaTrader_Jim​,

        Just a quick question about the distance strategy, this would work for a long for me, but for a short, to avoid the negative number would it be possible to flip the equation and say EMA [0] - Open [0]? Woudl that work?

        Also is there a way in the builder to reference the open of the next candle? For example go long if the open of the next candle is x distance from EMA8.

        Comment


          #5
          Hello Mcol5925,

          Thanks for your note.

          You could try using EMA(Close, 14)[0] - Open[0] in your strategy to see if this suits your overall goal.

          Something to consider is printing out EMA(Close, 14)[0] - Open[0] and Open[0] - EMA(Close, 14)[0] to see the differences in values and decide which one you want to use.

          There are no options to reference the Open price of a future (next) candle as this price is not known since there is no data for future bars.

          The most current Open price you could access is the Open price of the currently forming bar (Open[0]).

          Please let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          64 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          139 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          75 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X