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 usazencort, Today, 01:16 AM
            0 responses
            1 view
            0 likes
            Last Post usazencort  
            Started by kaywai, 09-01-2023, 08:44 PM
            5 responses
            603 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by xiinteractive, 04-09-2024, 08:08 AM
            6 responses
            22 views
            0 likes
            Last Post xiinteractive  
            Started by Pattontje, Yesterday, 02:10 PM
            2 responses
            21 views
            0 likes
            Last Post Pattontje  
            Started by flybuzz, 04-21-2024, 04:07 PM
            17 responses
            230 views
            0 likes
            Last Post TradingLoss  
            Working...
            X