Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trades not closing in strategy analyzer

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

    #31
    Hello tkaboris,

    The reason it was canceled because you closed the position that order was associated with. You would have to review your logic so you can better understand the order of events that are happening. One way is to review the order messages and then compare that against your logic which relates to the given orders. Another way is using prints, you can add prints into each part of your conditions to see when each part is becoming true so you can understand how the logic you made works.

    If you are having difficulty being able to follow the order of events that your strategy is producing that will pose a large problem when you run the script live, only you will be able to debug the script if something unexpected happens with your code. If that is something which you will have continuing problems with It would likely be to your benefit to work with a third party developer. In that case you would let them know any problems you see and they could then debug and modify the script as needed for you.

    Comment


      #32
      Upon debugging it shows that strategy cancels stop order but not the targerorder and cancelled order in the output is associated with targetOrder.

      Comment


        #33
        Hello tkaboris,

        The message you are getting is a normal message that happens when the associated position is closed. You can read about this happening in the managed approach documentation, for example with SetProfitTarget: "A profit target order is automatically cancelled if the managing position is closed by another strategy generated exit order".

        If you feel there is something wrong you will need to explore what reason that is by debugging your strategy further. The only information that I can gather from the message is that the associated position is closed, While our support cannot walk through each part of the debugging process you can do tests on your end to find what logic is associated with that result so you can explore other ways of approaching your goal.


        Comment


          #34
          Ok, i am having trouble with using trail stop now.
          My trail is inside onmarketupdate section.
          It sends duplicate order and i get Amended matching order and gnored SubmitOrderManaged()
          my trail code. I dont understand why its sending same orders again and again. What condition do i need to make to stop it?
          Thank you
          Code:
          if (
                              (Position.MarketPosition == MarketPosition.Long) //Needs to be in a long position
                                  && (marketDataUpdate.Price >= trailTriggerLong )
                                      && (Low[1] > Low[2]) //Ensure the trail will only move up if the new candles low is higher.    
                                  )
                              {
          //                    
          
                                  stopLong1 = trailLong;
          
                                  if(Position.MarketPosition == MarketPosition.Long && trailLong <= bid && isXiphosLongSetup == true){    
                                      Print("334");
                                      Print("trailLong" + trailLong);
                                      Print("bid" + bid);
                                      stopOrder = ExitLongStopMarket(1, true, stopOrder.Quantity, trailLong, "SLL", "Xiphos Long"); //Sets Stop
                                  }
                                  if(Position.MarketPosition == MarketPosition.Long && trailLong <= bid && isDoryLongSetup == true){
                                      Print("444");
                                      ExitLongStopMarket(1, true, Position.Quantity, trailLong, "SLL", "Dory Long");        
                                  }
                                  if(Position.MarketPosition == MarketPosition.Long && trailLong <= bid && isKopisLongSetup == true){
                                      ExitLongStopMarket(1, true, Position.Quantity, trailLong, "SLL", "Kopis Long");                                                    
                                  }
                                  trailTriggeredCandle = false; //You can move around trail stop freely until new candle.
                              }​
          in my onexecutionupdate i set initial stop and target for trail orders
          Code:
          if (execution.Name == "Xiphos Long" && SetTrail)
                                    {
                                        Print("222");
                                      stopOrder = ExitLongStopMarket(1, true, execution.Order.Filled, execution.Order.AverageFillPrice - (TickSize * StopLossTicks), "SLL", "Xiphos Long");
                                      targetOrder = ExitLongLimit(1, true, execution.Order.Filled, execution.Order.AverageFillPrice + (TickSize * ProfitTargetTicks), "PTL", "Xiphos Long");
                                    }
                              ​




          Long89B-8/23/2023 2:37:51 AM
          8/23/2023 2:37:52 AM Strategy 'Sparta Algo/284766076': Entered internal SubmitOrderManaged() method at 8/23/2023 2:37:52 AM: BarsInProgress=1 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Xiphos Long' FromEntrySignal=''
          222
          8/23/2023 2:37:52 AM Strategy 'Sparta Algo/284766076': Entered internal SubmitOrderManaged() method at 8/23/2023 2:37:52 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15018.25 SignalName='SLL' FromEntrySignal='Xiphos Long'
          8/23/2023 2:37:52 AM Strategy 'Sparta Algo/284766076': Entered internal SubmitOrderManaged() method at 8/23/2023 2:37:52 AM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=15038.75 StopPrice=0 SignalName='PTL' FromEntrySignal='Xiphos Long'
          Current Trade Count 1 8/23/2023 2:37:51 AM
          ===============================
          Entering Xiphos Long 89B:8/23/2023 2:37:51 AM
          334
          trailLong15020
          bid15025.5
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Entered internal SubmitOrderManaged() method at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15020.00 SignalName='SLL' FromEntrySignal='Xiphos Long'
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Amended matching order at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15020.00 SignalName='SLL' FromEntrySignal='Xiphos Long'
          334
          trailLong15023.25
          bid15025.5
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Entered internal SubmitOrderManaged() method at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15023.25 SignalName='SLL' FromEntrySignal='Xiphos Long'
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Amended matching order at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15023.25 SignalName='SLL' FromEntrySignal='Xiphos Long'
          334
          trailLong15023.25
          bid15025.5
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Entered internal SubmitOrderManaged() method at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15023.25 SignalName='SLL' FromEntrySignal='Xiphos Long'
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Ignored SubmitOrderManaged() method at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15023.25 SignalName='SLL' FromEntrySignal='Xiphos Long' Reason='There already is a matching order with same prices and quantity'
          334
          trailLong15023.25
          bid15025.5
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Entered internal SubmitOrderManaged() method at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15023.25 SignalName='SLL' FromEntrySignal='Xiphos Long'
          8/23/2023 2:38:11 AM Strategy 'Sparta Algo/284766076': Ignored SubmitOrderManaged() method at 8/23/2023 2:38:11 AM: BarsInProgress=1 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=15023.25 SignalName='SLL' FromEntrySignal='Xiphos Long' Reason='There already is a matching order with same prices and quantity'
          334​

          Comment


            #35
            Hello tkaboris,

            That's the same situation that we have already discussed earlier in this thread. I won't be able to tell you specific conditions that need to change because that's your code that you designed. You need to work through the problem by debugging your code. We already covered how you can debug your code and also why you can see ignored orders which is the extent that I can assist with. At this point it would now be up to you to use what you have learned about this warning and go through your code to make any necessary changes.

            Our support is not able to debug your code for you so If you are having difficulty being able to debug or follow the order of events that your strategy is producing that will pose a large problem. Only you will be able to debug your custom script if something unexpected happens. If that is something which you will have a hard time with It would likely be to your benefit to work with a third party developer instead of making the code yourself.

            Comment


              #36
              right but i still have a problem and dont understand how to modify the code.
              the issue is in this part. It continues to execute it and sends a same order. Am I right to place stopOrder assignment to ExitLongStopMarket in trail section?

              if(Position.MarketPosition == MarketPosition.Long && trailLong <= bid && isXiphosLongSetup == true){
              Print("334");
              Print("trailLong" + trailLong);
              Print("bid" + bid);
              stopOrder = ExitLongStopMarket(1, true, stopOrder.Quantity, trailLong, "SLL", "Xiphos Long"); //Sets Stop
              }​

              Comment


                #37
                Hello tkaboris,

                If you don't understand how to modify it then you need to debug the code further. I can't tell you what may need to change because you designed your code. You need to start using prints and debug the code yourself.

                We already covered why you get the warning which is the extent that I can assist with here.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                64 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                139 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                75 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X