Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetstopLoss() and SetProfitTarget() ignored in OnBarUpdate

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

    SetstopLoss() and SetProfitTarget() ignored in OnBarUpdate

    Hi everyone,

    The two methods in the title are called multiple times, once in state configure, then in OnBarUpdate().
    They are ignored in OnBarUpdate() and the trades exits occur at the end of day...

    If we comment the OnBarUpdate call, the State.Configure call works as expected.

    Would anyone have an idea why this occurs ? Is the issue from the attached reduced sample script or some property I didn' take into account ?
    We can find them line 116.

    Thank you very much.
    Attached Files

    #2
    Hello Amedeus,

    From the give code I see that you are not using a signal name for the targets, have you tried supplying the signal name that you used for the entry? It looks like that is "_l_"

    Comment


      #3
      hey Jesse, thank you very much.

      I just did and it did not solve this issue.
      I thaught an empty string would just make any order be taken into account by the method. The signal name was empty on purpose in our case .

      Comment


        #4
        Hello Amedeus,

        Does it work if you remove the statements from State.Configure? You should not need to have that as you are always setting targets before the entry in OnBarUpdate.

        Comment


          #5
          thank you Jesse,

          no it does not.
          wether the signal name is empty or not.

          Comment


            #6
            Hello Amedeus,

            I would suggest trying TraceOrders to see if the orders are being ignored.



            After setting TraceOrders = true; in State.DataLoaded remove and re apply the script and check the output window to see if anything additional is printed.

            Comment


              #7
              thank you Jesse,

              the output for one trade tells us :
              27/08/2024 13:58:02 Strategy 'a00teststrategy/316017348': Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=5634,8075 IsSimulatedStop=False IsMarketIfTouched=False
              27/08/2024 13:58:02 Strategy 'a00teststrategy/316017348': Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=5649,8075 IsSimulatedStop=False IsMarketIfTouched=False
              27/08/2024 13:58:02 Strategy 'a00teststrategy/316017348': Entered internal SubmitOrderManaged() method at 27/08/2024 13:58:02: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=5637,25 StopPrice=0 SignalName='_l_' FromEntrySignal=''
              27/08/2024 22:59:59 Strategy 'a00teststrategy/316017348': Cancelled order due to end of session handling: BarsInProgress=0, orderId='NT-00069-365' account='Sim101' name='Stop loss' orderState=Working instrument='MES 09-24' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=4228 quantity=1 tif=Day oco='NT-00038-365' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-08-27 13:58:02' gtd='2099-12-01' statementDate='2024-08-28'
              27/08/2024 22:59:59 Strategy 'a00teststrategy/316017348': Cancelled order due to end of session handling: BarsInProgress=0, orderId='NT-00070-365' account='Sim101' name='Profit target' orderState=Working instrument='MES 09-24' orderAction=Sell orderType='Limit' limitPrice=7049.25 stopPrice=0 quantity=1 tif=Day oco='NT-00038-365' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2024-08-27 13:58:02' gtd='2099-12-01' statementDate='2024-08-28'
              I read from that what was described before, but not any news about why the order goes to the end of sesion.
              Do you ?

              Comment


                #8
                Hey Jesse,

                So, I understand that the orders are beeing ignored.
                Attached are an even more reduced sample with its corresponding output.
                There are the TraceOrder and OnOrderUpdate prints as suggested, as well as prints in OnBarUpdate which reveal the position should have been exited.

                I just took a look at the managed approach documentation again and was not able to find a cause for this.
                Attached Files

                Comment


                  #9
                  Hello Amedeus,

                  I believe this is due to how you are calculating the prices. You are adding an offset to your SMA price rather than converting that to an amount of ticks, you are supplying a price as an amount of ticks. Your target statemnents should look like the following instead:

                  double myentryPrice = SMA(100)[0]+0*TickSize;
                  double mystopPrice = SMA(100)[0]-10*TickSize;
                  double mytargetPrice = SMA(100)[0]+30*TickSize;

                  SetStopLoss("", CalculationMode.Price, mystopPrice, false);
                  SetProfitTarget("", CalculationMode.Price, mytargetPrice, false);​​

                  Comment


                    #10
                    thank you very much Jesse,

                    CalculationMode.Price made the orders work.

                    solved !

                    have a good one.​

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    50 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    126 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    69 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    42 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    46 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X