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

What Am i doing wrong to calculate distance?

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

    What Am i doing wrong to calculate distance?

    Hi, I want to make a filter that if price is too close to 200 ema then dont take order.
    I have
    DistTo200EMA = 40;

    double dist200ToPrice = Math.Abs(EMA(200)[0] - Close[0]);

    and logic is here
    If (DistTo200EMA >= dist200ToPrice * TickSize)
    -> order

    But it still takes orders when close is less then DistTo200EMA.

    #2
    Hello tkaboris,

    Be sure to print the values to understand why the condition is still evaluating as true.
    https://ninjatrader.com/support/foru...121#post791121

    Print(string.Format("{0} | DistTo200EMA: {1} >= dist200ToPrice * TickSize: {2}", Time[0], DistTo200EMA, dist200ToPrice * TickSize));

    What is the value of (dist200ToPrice * TickSize)?
    Is DistTo200EMA with a value of 40 greater than dist200ToPrice * TickSize?

    But it still takes orders when close is less then DistTo200EMA.
    Your logic looks for (dist200ToPrice * TickSize) to be less than 40. Is this what you want? Did you want it to be greater than 40?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3


      Yes i wanted to be greater then 40.

      Comment


        #4
        Hello tkaboris,

        Be sure to add the prints so that you fully understand.

        But try comparing (dist200ToPrice * TickSize) to be greater than DistTo200EMA and not the other way around.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          HI I was able put that Print line and wanted to cofirm . TickSize 7.27 is current ticks to 200EMA? if so its not accurate i think.

          2/13/2023 2:13:55 PM | DistTo200EMA: 40 >= dist200ToPrice * TickSize: 7.27802326968003

          Comment


            #6
            I think i got it to work with two instances of ticksize
            && (dist200ToPrice * TickSize >= DistTo200EMA * TickSize)

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rdtdale, Today, 01:02 PM
            0 responses
            1 view
            0 likes
            Last Post rdtdale
            by rdtdale
             
            Started by alifarahani, Today, 09:40 AM
            3 responses
            15 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by RookieTrader, Today, 09:37 AM
            4 responses
            18 views
            0 likes
            Last Post RookieTrader  
            Started by PaulMohn, Today, 12:36 PM
            0 responses
            5 views
            0 likes
            Last Post PaulMohn  
            Started by love2code2trade, 04-17-2024, 01:45 PM
            4 responses
            40 views
            0 likes
            Last Post love2code2trade  
            Working...
            X