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

Entry trigger above High

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

    Entry trigger above High

    I have attached a chart image for visual. Im using OnBarUpdate=false. With the code below I'm trying to trigger a long trade after there is a MA crossover 2 bars back and when price moves above the high of the bar 2 bars back or the high of the bar at the crossover point.

    if (SMA(Fast)[2] > SMA(Slow)[2] && SMA(Fast)[3] < SMA(Slow)[3] && Close[0] > High[2] )
    { EnterLong(100, ""); }

    As you can see from the chart the 3rd bar after the crossover takes out the high of the bar at the crossover but the entry doesn't trigger till the 4th bar after the crossover? Im looking for it to trigger on the 3rd bar in real time as the price moves above the high 2 bars back.

    I figured having OnBarUpdate=false and using Close[0] > High[2] would take care of this. Should I be using something else other than Close[0]. Is there another Data command such as Last[0] for last price so that as soon as price moves above the high it triggers?
    Attached Files

    #2
    zachj, no Close[0] with COBC set to false would be fine for last price. So your screenshot attached was generated in realtime or backtesting?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      That is backtesting, sorry for confusion, when i said realtime i just meant like the second or few seconds after it goes above the high im looking for it to trigger the long but it always seems to be triggering on the next bar instead?

      Comment


        #4
        For backtesting I would expect that outcome seen, for realtime running or MarketReplay on COBC = false the condition can trigger intrabar if all other parts are satisfied on this bar.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok gotcha..so for backtesting cobc setting does not take effect. Im using 15m bars for primary and even tried creating a 2nd series of 1min to make it trigger within the 15m bar but it still waits till the next 15m bar. Not sure if i am supposed to use barsinprogress=0 or 1 because the cross part of the code needs to use primary but the code to trigger above the high based on 1min needs to use secondary.

          Comment


            #6
            You would need to make sure to send the order in historical from the added one min series then, so BIP = 1. You can still access the highs and price data from the primary timeframe when processing here, for example try something like -

            if (SMA(BarsArray[0], Fast)[2] > SMA(BarsArray[0], Slow)[2] && SMA(BarsArray[0], Fast)[3] < SMA(, BarsArray[0]Slow)[3] && Close[0] > Highs[0][2] )
            { EnterLong(100, ""); }
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Ya that did it. Thanks

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Kaledus, Today, 01:29 PM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by frankthearm, Yesterday, 09:08 AM
              13 responses
              45 views
              0 likes
              Last Post frankthearm  
              Started by PaulMohn, Today, 12:36 PM
              2 responses
              16 views
              0 likes
              Last Post PaulMohn  
              Started by Conceptzx, 10-11-2022, 06:38 AM
              2 responses
              55 views
              0 likes
              Last Post PhillT
              by PhillT
               
              Started by yertle, Yesterday, 08:38 AM
              8 responses
              37 views
              0 likes
              Last Post ryjoga
              by ryjoga
               
              Working...
              X