Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trades not closing in strategy analyzer

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

    Trades not closing in strategy analyzer

    HI
    I have this issue,
    I have several strategies withing a stategy that i mark by a bool.
    Nothing seems to be wrong and all is working as suppose to in market replay, take profits are set and stop losses are set.
    However in strategy analyzer, if i select one strategy it works fine but as soon as I select another one along with the previous one, SL are not set and strategy cancels at EOD.
    I looked and looked throught code and nothing that stands out that would call this issue.

    Do you have any ideas what might it be?



    #2
    Hello tkaboris,

    Thank you for your post.

    Please describe the process from your statement "if i select one strategy it works fine but as soon as I select another one along with the previous one"

    So I may assist you more accurately, please answer all of the following questions:
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • If you select one strategy where?
      • What are the steps you take to select another strategy, and what do you mean by along with the previous one?
      • Do you mean that you somehow have both strategies selected somewhere, or that you go back to selecting the first strategy?
    • Do you see results when running the same test on the SampleMaCrossOver strategy with the same settings as your strategy?
    • Who are you connected to? This is displayed in green in the lower-left corner of the Control Center window.
    • Are you connected to your data feed provider when running this test?
    • What instrument(s) (and expiry if applicable) have you selected?
    • What Data Series Type have you selected? Example: Tick, Minute, Day
    • What From and To date is selected?
    • Is your strategy a multi-instrument or multi-time frame strategy?
    • Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    Thanks in advance; I look forward to further investigating this item.​

    Comment


      #3
      Where can i look for logs from strategy ran in strategy analyzer? is it in Logs or Trace Folder?

      Comment


        #4
        After enabling trace orders i get lots of these
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Xiphos Long' Reason='Order already has this stop price/limit price/quantity'
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Entered internal SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Dory Long'
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Dory Long' Reason='SignalName does not have a matching FromEntrySignal to exit'
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Entered internal SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Kopis Long'
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Kopis Long' Reason='SignalName does not have a matching FromEntrySignal to exit'
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Entered internal SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Xiphos Long'
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Ignored SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Xiphos Long' Reason='Order already has this stop price/limit price/quantity'
        8/24/2023 12:32:01 PM Strategy 'Sparta Algo/-1': Entered internal SubmitOrderManaged() method at 8/24/2023 12:32:01 PM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15027.25 StopPrice=0 SignalName='PTL' FromEntrySignal='Dory Long'​
        Subsequent orders maybe ignored..

        Maybe thats why?​

        Comment


          #5
          I am entering like this
          EnterLong(1,PositionSize, "Dory Long");

          and exiting like this, so the exit order matching...
          if(Position.MarketPosition == MarketPosition.Long && (Position.AveragePrice - (TickSize * StopLossTicks)) <= bid){
          ExitLongStopMarket(1, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Xiphos Long");
          ExitLongStopMarket(1, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Dory Long");
          ExitLongStopMarket(1, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Kopis Long");
          }
          if(Position.MarketPosition == MarketPosition.Long && (Position.AveragePrice + (TickSize * ProfitTargetTicks)) >= bid){
          ExitLongLimit(1, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Xiphos Long");
          ExitLongLimit(1, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Dory Long");
          ExitLongLimit(1, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Kopis Long");
          }​

          Comment


            #6
            Hello tkaboris,

            Thank you for your reply.

            It does seem that some orders are being ignored, which would explain why you are not seeing some of the stops and/or targets that you expect to see. For example, from these messages, the order with signal name PTL must have some scenarios where it is set up with fromEntrySignal Dory Long, but the error indicates that it was not able to match with an order that has Dory Long as the signal name. This is the same case with Xiphos Long; the order PTL was ignored because it could not pair it with an entry that has signal name Xiphos Long. You will need to go back and review your strategy logic to get a better understanding of what signal names are being used for entry and stop/target orders.

            Please let us know if we may be of further assistance.

            Comment


              #7
              can you please look at post 5? Does it set up correctly?

              Comment


                #8
                Originally posted by tkaboris View Post
                I am entering like this
                EnterLong(1,PositionSize, "Dory Long");

                and exiting like this, so the exit order matching...
                if(Position.MarketPosition == MarketPosition.Long && (Position.AveragePrice - (TickSize * StopLossTicks)) <= bid){
                ExitLongStopMarket(1, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Xiphos Long");
                ExitLongStopMarket(1, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Dory Long");
                ExitLongStopMarket(1, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Kopis Long");
                }
                if(Position.MarketPosition == MarketPosition.Long && (Position.AveragePrice + (TickSize * ProfitTargetTicks)) >= bid){
                ExitLongLimit(1, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Xiphos Long");
                ExitLongLimit(1, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Dory Long");
                ExitLongLimit(1, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Kopis Long");
                }​
                Thanks for your patience; I had typed my previous reply prior to seeing this post and did not notice it when the page refreshed.

                I see your entry order has a signalName of Dory Long:
                EnterLong(1,PositionSize, "Dory Long");

                That said, your exit orders are using Dory Long, Xiphos Long, and Kopis Long in the fromEntrySignal parameter (see fromEntrySignal info on the ExitLongStopMarket() and ExitLongLimit() pages in the help guide). This only makes sense if you also have entries using signal names of Xiphons Long and Kopis Long. If you want to have a position with multiple contracts and separate stop loss and profit target orders, then it is suggested to use multiple separate entry orders with unique signal names. You should also use unique signal names for each of your stops and target orders, similar to what my colleague has described here:
                Hi, I am trying to enter short position with 3 contract (Stop Limit) with 3 profit target levels, each one of them buy 1 contract, When running the strategy, the first target works OK but the 2 other and also the stop loss dont work any more. What is the problem ? This is the entry command: EnterShortStopLimit(3, (Low[0] -


                Please let us know if we may be of further assistance.

                Comment


                  #9
                  Yes i have entries with Dory Long Xiphons Long and Kopis Long (Sorry weird names) Its 3 strategies but they share same TP and SL.
                  However SLL(Stop loss long) and PTL(profit target long) is shared among all strategies and its the same name.
                  So what is the approach i should take? Should I rename SLL and PTL to unique ones between strategies?

                  Comment


                    #10
                    Hello tkaboris,

                    Thank you for your reply.

                    I see what you are saying. As long as they are in separate strategies, keeping the names to SLL and PTL should be okay. I recommend enabling Trace Orders and only testing one strategy at a time to understand when orders are being submitted, canceled, ignored, or rejected. TraceOrders may be set to true in State.SetDefaults. For more information regarding Trace Orders:I also suggest adding Print() statements to print out the values being used in your conditions to submit your entry and exit orders. If you place prints both inside of your conditions and outside of your conditions, this can help to understand if an order is being submitted or not and why. More details on using prints to debug your script's behavior may be found here:Here is an example of prints you could use in your strategy that uses the "Dory Long" signal name. Please feel free to modify these prints to suit your needs, this example is just to serve as an idea of what kind of information you might want to print:
                    Code:
                    EnterLong(1,PositionSize, "Dory Long");
                    Print(Time[0] + "Dory Long entry submitted");
                    
                    Print(string.Format("{0} Position.MarketPosition: {1} Position.AveragePrice: {2} - TickSize * StopLossTicks: {3} <= bid: {4}", Time[0], Position.MarketPosition, Position.AveragePrice, (TickSize * StopLossTicks), bid));
                    if(Position.MarketPosition == MarketPosition.Long && (Position.AveragePrice - (TickSize * StopLossTicks)) <= bid){
                    ExitLongStopMarket(1, true, Position.Quantity, Position.AveragePrice - (TickSize * StopLossTicks), "SLL", "Dory Long");
                    Print(Time[0] + "ExitLongStopMarket submitted with stop price: " + (Position.AveragePrice - (TickSize * StopLossTicks)));
                    Print(string.Format("{0} Position.MarketPosition: {1} Position.AveragePrice: {2} - TickSize * StopLossTicks: {3} <= bid: {4}", Time[0], Position.MarketPosition, Position.AveragePrice, (TickSize * StopLossTicks), bid));
                    }
                    
                    if(Position.MarketPosition == MarketPosition.Long && (Position.AveragePrice + (TickSize * ProfitTargetTicks)) >= bid){
                    ExitLongLimit(1, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "Dory Long");
                    Print(Time[0] + "ExitLongLimit submitted with limit price: " + (Position.AveragePrice + (TickSize * ProfitTargetTicks)));
                    Print(string.Format("{0} Position.MarketPosition: {1} Position.AveragePrice: {2} - TickSize * StopLossTicks: {3} <= bid: {4}", Time[0], Position.MarketPosition, Position.AveragePrice, (TickSize * StopLossTicks), bid));​
                    }​​
                    Please feel free to reach out with any additional questions or concerns.

                    Comment


                      #11
                      HI i modified my script but now i am getting duplicate errors, There already is a matching order with same prices and quantity'

                      how do i make sure i am not submitting new orders to be ignored?
                      and I am getting blank fron entry signal on first iteration

                      Code:
                       EnterShort(1,PositionSize, "Xiphos Short");
                                                      isXiphosShortSetup = true;
                                                      Draw.Diamond(this, "Down Diamond" + CurrentBar, false, 0, High[0], Brushes.Magenta);
                                                      myFreeTradeShort = true;    ​
                      
                      if (Position.MarketPosition == MarketPosition.Short  && myFreeTradeShort == true && isXiphosShortSetup == true )
                      
                                      if (UseFixedSLTP)
                                      {
                                          Print("condition2");
                                          if(Position.MarketPosition == MarketPosition.Short && (Position.AveragePrice + (TickSize * StopLossTicks)) >= ask){  
                                              Print("condition3");
                                              ExitShortStopMarket(1, true, Position.Quantity, Position.AveragePrice + (TickSize * StopLossTicks), "SLS", "Xiphos Short");                    
                                          }
                                          if(Position.MarketPosition == MarketPosition.Short && (Position.AveragePrice - (TickSize * ProfitTargetTicks)) <= ask){        
                                              Print("condition4");
                                              Print("freetradeshort5"+myFreeTradeShort );
                                              ExitShortLimit(1, true, Position.Quantity, Position.AveragePrice - (TickSize * ProfitTargetTicks), "PTS", "Xiphos Short");                    
                                          }
                                      }​

                      8/7/2023 9:57:51 AM Strategy 'Sparta Algo/284766074': Entered internal SubmitOrderManaged() method at 8/7/2023 9:57:51 AM: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=15406.50 StopPrice=0 SignalName='PTS' FromEntrySignal='Xiphos Short'
                      8/7/2023 9:57:51 AM Strategy 'Sparta Algo/284766074': Ignored SubmitOrderManaged() method at 8/7/2023 9:57:51 AM: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=15406.50 StopPrice=0 SignalName='PTS' FromEntrySignal='Xiphos Short' Reason='There already is a matching order with same prices and quantity'
                      8/7/2023 9:57:51 AM Strategy 'Sparta Algo/284766074': Entered internal SubmitOrderManaged() method at 8/7/2023 9:57:51 AM: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15417.50 SignalName='SLS' FromEntrySignal='Xiphos Short'
                      8/7/2023 9:57:51 AM Strategy 'Sparta Algo/284766074': Ignored SubmitOrderManaged() method at 8/7/2023 9:57:51 AM: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15417.50 SignalName='SLS' FromEntrySignal='Xiphos Short' Reason='There already is a matching order with same prices and quantity'​


                      ema cross short5839
                      8/7/2023 9:57:34 AM Strategy 'Sparta Algo/284766074': Entered internal SubmitOrderManaged() method at 8/7/2023 9:57:34 AM: BarsInProgress=1 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Xiphos Short' FromEntrySignal=''
                      8/7/2023 9:57:34 AM Strategy 'Sparta Algo/284766074': Entered internal SubmitOrderManaged() method at 8/7/2023 9:57:34 AM: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15417.50 SignalName='SLS' FromEntrySignal='Xiphos Short'
                      8/7/2023 9:57:34 AM Strategy 'Sparta Algo/284766074': Entered internal SubmitOrderManaged() method at 8/7/2023 9:57:34 AM: BarsInProgress=1 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=15406.50 StopPrice=0 SignalName='PTS' FromEntrySignal='Xiphos Short'
                      Current Trade Count 1 8/7/2023 9:57:33 AM​
                      Last edited by tkaboris; 09-03-2023, 03:48 PM.

                      Comment


                        #12
                        Hello tkaboris,

                        In the code you provided you are using live until cancelled orders so that means you only need that logic to be called only one time to submit the order. It looks like the condition you made can become true anytime you are short and the average price plus offset is greater than the ask price. If you call that same order again you will get the ignored warning.

                        You will need to use prints to evaluate how your logic is working so you can make changes to avoid calling the same order multiple times.

                        If you need to change an order that is live until cancelled you would use the ChangeOrder method.

                        https://ninjatrader.com/support/help...hangeorder.htm

                        Ignored SubmitOrderManaged() method at 8/7/2023 9:57:51 AM: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15417.50 SignalName='SLS' FromEntrySignal='Xiphos Short'

                        ExitShortStopMarket(1, true, Position.Quantity, Position.AveragePrice + (TickSize * StopLossTicks), "SLS", "Xiphos Short");
                        Last edited by NinjaTrader_Jesse; 09-04-2023, 07:28 AM.

                        Comment


                          #13
                          Thank you for responding

                          Can you please help me with exaple of how i need to modify an order? I am not clear what i need to change in the order. If I need to change liveuntilcancel to false. then i dont see that property in change order.

                          if (UseFixedSLTP)
                          {
                          Print("condition2");
                          if(Position.MarketPosition == MarketPosition.Short && (Position.AveragePrice + (TickSize * StopLossTicks)) >= ask){
                          Print("condition3");
                          ExitShortStopMarket(1, true, Position.Quantity, Position.AveragePrice + (TickSize * StopLossTicks), "xSLS", "Xiphos Short");
                          }
                          if(Position.MarketPosition == MarketPosition.Short && (Position.AveragePrice - (TickSize * ProfitTargetTicks)) <= ask){
                          Print("condition4");
                          Print("freetradeshort5"+myFreeTradeShort );
                          ExitShortLimit(1, true, Position.Quantity, Position.AveragePrice - (TickSize * ProfitTargetTicks), "xPTS", "Xiphos Short");
                          }
                          }

                          if (stopOrder != null )
                          ChangeOrder(stopOrder, stopOrder.Quantity, 0, Position.AveragePrice);​

                          Comment


                            #14
                            Hello tkaboris,

                            Your condition is becoming true multiple times which is why the ignored warning happens. You need to change your condition that submits that order to become true only 1 time.

                            If you need to make modifications to the order after its submitted you need to ChangeOrder to change a live until cancelled order. There is a sample of how to use that in the link i provided in the last reply.

                            Comment


                              #15
                              in the example it shows

                              if (stopOrder != null && stopOrder.StopPrice < Position.AveragePrice )
                              ChangeOrder(stopOrder, stopOrder.Quantity, 0, Position.AveragePrice); // no bool

                              but my order submitio is this
                              ExitShortStopMarket(1, true, Position.Quantity, Position.AveragePrice + (TickSize * StopLossTicks), "xSLS", "Xiphos Short");

                              So change order doesnt have option to change bool to false

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, 03-13-2026, 05:17 AM
                              0 responses
                              87 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              151 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              80 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              53 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              62 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X