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

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.
    JimNinjaTrader Customer Service

    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.
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by KenneGaray, Today, 03:48 AM
          0 responses
          3 views
          0 likes
          Last Post KenneGaray  
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          470 views
          0 likes
          Last Post tradingnasdaqprueba  
          Started by aa731, Today, 02:54 AM
          0 responses
          4 views
          0 likes
          Last Post aa731
          by aa731
           
          Started by Christopher_R, Today, 12:29 AM
          0 responses
          10 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,237 views
          0 likes
          Last Post sidlercom80  
          Working...
          X