Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wait until flat multi instrument

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

    Wait until flat multi instrument

    Hi guys,
    I have a multi instrument strategy that takes pairs trades on BarsArray[1] and BarsArray[2], but never on BarsArray[0].
    The instrument in BarsArray[2] is always the same as the chart instrument.

    It is working well.

    However I am having difficulties with the WAIT UNTIL FLAT BEFORE EXECUTING LIVE option. This doesn't appear to work correctly on my strategy.
    If I have a pair of virtual trades open when I start the strategy, one of them will WAIT UNTIL FLAT, but the other one - on BarsInProgress==2 - will create a real order and real Strategy Position using an Exit() order.

    Here is the log of a trade creating a real position using an Exit() order....

    07-Aug-09 7:44:02 AM|1|128|Starting NinjaScript strategy 'JRPairsTraderRT/fcc7f251c317488d9da27602ace99d7b' : On starting a real-time strategy - StrategySync=WaitUntilFlat EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=ByStrategyPosition ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 135 before close Set order quantity by=Strategy
    07-Aug-09 1:58:31 PM|1|32|Order='71758bd371f446f88b4d566a381c4f80/Sim101' Name='UberZTarget' New State=PendingSubmit Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=11 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    07-Aug-09 1:58:31 PM|1|32|Order='71758bd371f446f88b4d566a381c4f80/Sim101' Name='UberZTarget' New State=Accepted Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=11 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    07-Aug-09 1:58:31 PM|1|32|Order='71758bd371f446f88b4d566a381c4f80/Sim101' Name='UberZTarget' New State=Working Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=11 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
    07-Aug-09 1:58:31 PM|1|32|Order='71758bd371f446f88b4d566a381c4f80/Sim101' Name='UberZTarget' New State=Filled Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=11 Type=Market Filled=11 Fill price=1012.25 Error=NoError Native error=''
    07-Aug-09 1:58:31 PM|1|16|Execution='eab60c8fffcf48649c090d33de6fd9e b' Instrument='ES ##-##' Account='Sim101' Exchange=Default Price=1012.25 Quantity=11 Market position=Long Operation=Insert Order='71758bd371f446f88b4d566a381c4f80' Time='07-Aug-09 1:58:31 PM'
    07-Aug-09 1:58:31 PM|1|64|Instrument='ES ##-##' Account='Sim101' Avg price=1012.25 Quantity=11 Market position=Long Operation=Insert Currency=Unknown

    You can see that a "BuyToCover" order generated a real Long position.

    How precisely is the virtual "FLAT" position determined? Does it only examine the first BarsInProgress ? If so, and there is no position there but positions in other BarsInProgress, this test would fail.

    Hoping you can help.
    saltminer
    Last edited by saltminer; 08-08-2009, 01:53 PM. Reason: to the point.

    #2
    saltminer,

    It is determined by the position held by the strategy. Please try using TraceOrders = true along with Print()s to evaluate your position at the time of the order placement.

    If you still feel there is an issue we would like to see an as-simple-as-possible, generic version of your strategy that is able to reproduce the scenario. That way we can give you a better analysis. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Proof

      Ok, I have proof here that "Wait Until Flat Before Executing Live" does not work as advertised.

      Load this strategy in MarketReplay, a few minutes past midday. (Make sure you add a second instrument that has market replay data, and that Exit On Close is false.)
      It takes a trade at midday. It should just exit that virtual trade at 20 past 12 without taking a real position in the market in the process.

      AHA! It places a real position!

      Entering at bar 3492, at 07-Aug-09 12:00:00 PM
      07-Aug-09 12:20:00 PM Entered internal PlaceOrder() method at 07-Aug-09 12:20:00 PM: Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='ExitInRealtime' FromEntrySignal='MyEntry'
      07-Aug-09 12:20:00 PM Entered internal PlaceOrder() method at 07-Aug-09 12:20:00 PM: Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='ExitInRealtime' FromEntrySignal='MyEntry'
      Exiting at bar 3512, at 07-Aug-09 12:20:00 PM
      07-Aug-09 12:20:00 PM Cancelled remaining exit order: Order='NT-00019/Replay101' Name='ExitInRealtime' State=Working Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Strategy='TestWaitUntilFlat' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='0ad9775bb41d41f6b3269157502cb6f4' Gtd='01-Dec-99 12:00:00 AM'


      11-Aug-09 4:49:45 AM|1|128|Starting NinjaScript strategy 'TestWaitUntilFlat/6cd0c6c0c88643a692648976a23fbf3f' : On starting a real-time strategy - StrategySync=WaitUntilFlat EntryHandling=UniqueEntries EntriesPerDirection=99 StopTargetHandling=ByStrategyPosition ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=False Set order quantity by=Strategy
      11-Aug-09 4:51:07 AM|1|32|Order='0ad9775bb41d41f6b3269157502cb6f4/Replay101' Name='ExitInRealtime' New State=PendingSubmit Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
      11-Aug-09 4:51:08 AM|1|32|Order='0ad9775bb41d41f6b3269157502cb6f4/Replay101' Name='ExitInRealtime' New State=Accepted Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
      11-Aug-09 4:51:08 AM|1|32|Order='0ad9775bb41d41f6b3269157502cb6f4/Replay101' Name='ExitInRealtime' New State=Working Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error=''
      11-Aug-09 4:51:08 AM|1|32|Order='0ad9775bb41d41f6b3269157502cb6f4/Replay101' Name='ExitInRealtime' New State=Filled Instrument='ES ##-##' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=1013 Error=NoError Native error=''
      11-Aug-09 4:51:08 AM|1|16|Execution='193f19cf8963407db2f316c1da424d8 1' Instrument='ES ##-##' Account='Replay101' Exchange=Default Price=1013 Quantity=1 Market position=Long Operation=Insert Order='0ad9775bb41d41f6b3269157502cb6f4' Time='07-Aug-09 12:20:00 PM'
      11-Aug-09 4:51:08 AM|1|64|Instrument='ES ##-##' Account='Replay101' Avg price=1013 Quantity=1 Market position=Long Operation=Insert Currency=Unknown

      Attached is the strategy.
      saltminer
      Attached Files
      Last edited by saltminer; 08-11-2009, 06:46 AM.

      Comment


        #4
        Please provide the replay files you are using. Thank you.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Sure, but it won't make any difference. You can use any data you like.

          I can't attach something larger than 100k to a post. Please provide an email address or some other method of conveying the replay data to you.

          saltminer

          Comment


            #6
            saltminer, you can direct those to support at ninjatrader com - if the files are larger than 3 MB, please use a service like www.yousendit.com thanks

            Comment


              #7
              Ran your replay and your strategy. Nothing unexpected. It trades past noon because your strategy position is flat the whole time. Since its flat there is nothing preventing it from going live with the orders.

              Added this line to your OnBarUpdate() to confirm strategy positions.
              Print(Time[0] + " Positions 0: " + Positions[0].MarketPosition + " " + Positions[0].Quantity + " Positions 1: " + Positions[1].MarketPosition + " " + Positions[1].Quantity + " Positions 2: " + Positions[2].MarketPosition + " " + Positions[2].Quantity);

              It is always flat till it trades.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Hi Josh,
                It should be taking a trade at noon every day of your MarketReplay chart.

                I can see that here.

                Please retry doing the following:

                Use the ES ##-## for the chart's instrument.

                When you load the Strategy, it is very important to stipulate a second instrument for BarsArray[1].
                1) Enter FESX 09-09 into the parameter "SecondInstrument"

                2) Change the ExitOnClose parameter to FALSE

                3) make sure the time on the market replay is about ten minutes past midday.

                When the strategy is loaded, you should be able to see an entry marked on the chart, but no exit yet.

                At twenty past midday, the trade will exit, and mistakenly fill a real market position. Please see attached images I just made doing this.

                saltminer
                Attached Files
                Last edited by saltminer; 08-12-2009, 06:08 PM.

                Comment


                  #9
                  Will look into.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thank you for reporting. It is fixed in NT7.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Ninjascript order of action

                      If my Ninjascript strategy is set to "Calculate on bar close," is there an order that commands are executed? For example, if Set 1 states that there be an "Exit short position" and "Exit Long Position" (in order to close out any orders in process at the close of the current bar) and Set 2 states that there be an "Enter short position" at the close of the current bar, does this set up a hierarchical set of actions such that the Exit short and Exit long of Set 1 always occur before the Enter short of Set 2?

                      Comment


                        #12
                        Set 1 is processed before Set 2. Whatever in 1 will be submitted first, but that does not guarantee it will be filled by the time it reaches set 2.
                        Josh P.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        647 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        368 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        108 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        571 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        573 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X