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

strat triggering outside of chosen trading hours and being disabled

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

    strat triggering outside of chosen trading hours and being disabled

    Hi,
    I set this strategy up for symbols ZT and ZF for CME US index RTH, and when enabled both symbols triggered orders instantly 40 minutes before the open, and then the strat was auto disabled. I received this message:


    Enabling NinjaScript strategy 'EC05ATRBreakout/288695454' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
    NinjaScript strategy 'EC05ATRBreakout/288695454' submitting order
    Disabling NinjaScript strategy 'EC05ATRBreakout/288695454'​

    Any ideas?

    here's the script:

    AtrMult = 1;
    AtrPeriod = 15;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    ATR1 = ATR(Close, Convert.ToInt32(AtrPeriod));
    ATR1.Plots[0].Brush = Brushes.DarkCyan;
    AddChartIndicator(ATR1);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    EnterLongStopMarket(Convert.ToInt32(DefaultQuantit y), (Close[0] + ((ATR1[0] * AtrMult) )) , "");
    EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), (Close[0] - ((ATR1[0] * AtrMult) )) , "");
    }
    ​

    #2
    Hello trader3000a,

    The code you have now will submit orders as soon as you enable the strategy, there are no conditions to trade here. If you meant for it to only work in the current trading session you need to add a condition to return for historical bars.

    if(State == State.Historcial) return;

    You also cannot submit two opposing orders like that with the managed approach. If you are trying to make a bracket entry you need to use the unmanaged approach, there is a sample of that here: https://ninjatrader.com/support/foru...926#post486926
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,
      ok, I'll look at the sample for the bracket part, but I'm wondering why the orders triggered for ZT and ZF when I chose CME US index RTH in the setup interface? I had other symbols set up the same way, and they waited for the open of CME US index RTH to trigger (although they only submitted the long half of the bracket)

      please see attachment. worked for other symbols but not for zt, zf (bonds)
      thanks,
      David
      Attached Files

      Comment


        #4
        Hello trader3000a,

        I couldn't really comment on what may have occurred as I didn't run the script to test that situation. In any case the script you have is not the correct approach for what you are trying to do. I would suggest using the sample I had linked to as a starting point if you are trying to make a bracket type order. You can make any adjustments necessary to see it enter how you want.


        JesseNinjaTrader Customer Service

        Comment


          #5
          Ok, thanks. Just to be sure, I wanted to mention that it works fine in backtest, if you have a look at the backtest image I've attached using same setup of var's and trading hours.
          It's not a bracket order like an OCO stop and profit, it's just a stop and reverse thing. Hopefully I'm being more clear.
          thanks,
          David
          Attached Files

          Comment


            #6
            Hello trader3000a,

            This type of logic will work differently in backtest vs realtime. As you have it now its not actually a reversal strategy because one of the orders will be ignored. The definition of a reversal strategy is where you have a condition that enters into a single direction like Long. It holds that position for a time and then a second condition calls the opposite entry order at a later time. by doing that it closes the Long position and enters into the opposite direction.

            With what you have now one of the orders is ignored, If you enable traceorders you can see that one of the orders is being ignored.

            The way you made this code it would be a bracket entry which won't work in the managed approach. A bracket entry is where you place two entry orders at the same time which are entering into opposite directions. One of the orders would need to be cancelled after the other fills so you can enter into a single direction. If both orders filled and one was not cancelled you would just be flat. The sample I linked to does a bracket entry using the unmanaged approach which allows submitting opposing orders at the same time.

            Another potential issue is that because you don't have any type of entry conditions its going to keep updating the order as long as its not filled. You aren't using a fixed price so that will allow the order to be moved up or down as the ATR value changes which can prolong how long the order is working. The orders would work similar to a trailing stop without any limit on the direction it can travel.

            If you are trying to do a reversal strategy I would suggest looking at the SampleMACrossOver, that uses conditions for long and short so they don't happen at the exact same time.




            JesseNinjaTrader Customer Service

            Comment


              #7
              Ok, thanks for taking the time to explain all of this. Very helpful!
              David

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PaulMohn, Today, 05:00 AM
              0 responses
              8 views
              0 likes
              Last Post PaulMohn  
              Started by ZenCortexAuCost, Today, 04:24 AM
              0 responses
              6 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by ZenCortexAuCost, Today, 04:22 AM
              0 responses
              3 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by SantoshXX, Today, 03:09 AM
              0 responses
              16 views
              0 likes
              Last Post SantoshXX  
              Started by DanielTynera, Today, 01:14 AM
              0 responses
              5 views
              0 likes
              Last Post DanielTynera  
              Working...
              X