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

Open/Close is higher/lower than EMA does not work

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

    Open/Close is higher/lower than EMA does not work

    Hi, I'm using the strategy builder to create a new trading system.

    A part of the strategy is, that a long order will be set, when a candle crosses over the EMA (Open lower and Close higher, similarly short orders)

    In the backtest I saw that it works. But also orders are set, when Open or Close is equal to the EMA. How can I avoid this behaviour?

    I tried to find something wrong in "Conditions and Actions" and used different operators (Close(0) is higher/lower/crossover) but the result was still the same.

    Unfortunately I don`t know much about Ninjascript or C#, nevertheless I hope you can help me.

    Best regards

    #2
    Hello Heikoman,

    Thanks for your post and welcome to the Ninjatrader forums!

    Have you used the CrossAbove or CrossBelow in the Strategy Builder conditions?

    If you have not reviewed these resources they are available to you on the Strategy Builder:
    Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
    Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
    Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello, and thank you very much!

      At first I have used:

      Open[0] < EMA(14)[0]
      Default input[0] > EMA(14)[0]

      but it did not work. After this I tried:

      CrossAbove(Close, EMA(Close, 14), 1)

      and again I can find wrong orders in the backtest (see photo)

      Comment


        #4
        Hello Heikoman,

        Thanks for your post.

        The screenshot shows that the order was placed on the bar following where the cross occurred on the previous (green) bar. Please note that when looking at historical trades, the trade condition to place the order will be on the previous bar but the order cannot be filled until the following bar, this is because the strategy will run once at the end of each bar.

        To help you see this, I recommend adding a marker to show in the chart when the cross condition is true. You will then see the marker on the bar before the trade entry. Adding a marker when a "set" is true is also very helpful for debugging your strategy. There are a couple of tips when adding markers and I've covered them in this short video: https://paul-ninjatrader.tinytake.co...MF8xMTMwNTc0MA

        Another way to detect a cross above would be Default[1] < EMA(14)[1] and Default[0] > EMA(14)[0] did the previous bar close below the EMA and does the current bar close above the EMA, both conditions would need to be true at the same time for there to be a cross above. For a crossbelow you can use Default[1] > EMA(14)[1] and Default[0] < EMA(14)[0]
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello Paul, Thanks for your reply!

          As you suggested, I've used Default[1] < EMA(14)[1] and Default[0] > EMA(14)[0] to find a cross above.

          In the backtest (see photo) I found the same order as in my first screenshot.

          I haven't understood yet, why the order is placed when the close (green bar) is equal to the EMA (Data Box shows, that close (green bar) and EMA have the same Value)
          I thought, that the close has to be above the EMA for one tick minimum.

          Comment


            #6
            Hello Heikoman,

            Thanks for your reply.

            The price can only move in the minimum price increments that the instrument allows, a moving average is a calculated value and is not rounded to the price level as it shows on the data box.

            For a simple example if the price is a value of 1000 and the calculated moving average is 999.99999999 then the price is greater than the moving average even though visually on the chart they may appear the same and in the data box they are the same as the EMA value has been rounded.

            There are no options to round up/down the values in the strategy builder. You could add an "offset" to either the price of the EMA to ensure a more definitive cross of the close price.

            Here is an example add 1 Tick to the EMA price:

            Default[1] < EMA(14)[1] and Default[0] > EMA(14)[0]+(1 * TickSize) (Code generated by Strategy Builder when using offset of 1 tick.

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello Paul,

              thank you very much, that was the point! Now I can go on with the strategy.

              Best regards

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by ntram, Today, 05:39 PM
              0 responses
              2 views
              0 likes
              Last Post ntram
              by ntram
               
              Started by giulyko00, Today, 11:49 AM
              2 responses
              11 views
              0 likes
              Last Post giulyko00  
              Started by Aviram Y, Today, 06:03 AM
              2 responses
              10 views
              0 likes
              Last Post Aviram Y  
              Started by FishTrade, Today, 03:42 PM
              0 responses
              1 view
              0 likes
              Last Post FishTrade  
              Started by Richozzy38, Today, 01:06 PM
              3 responses
              14 views
              0 likes
              Last Post Richozzy38  
              Working...
              X