Announcement

Collapse
No announcement yet.

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 CaptainJack, 05-29-2026, 05:09 AM
            0 responses
            370 views
            0 likes
            Last Post CaptainJack  
            Started by CaptainJack, 05-29-2026, 12:02 AM
            0 responses
            239 views
            0 likes
            Last Post CaptainJack  
            Started by charlesugo_1, 05-26-2026, 05:03 PM
            0 responses
            205 views
            1 like
            Last Post charlesugo_1  
            Started by DannyP96, 05-18-2026, 02:38 PM
            1 response
            292 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            253 views
            0 likes
            Last Post CarlTrading  
            Working...
            X