Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss update doesn't change

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

    SetStopLoss update doesn't change

    I'm running a strategy with Target1, Target2 & Target3 orders (t1.ordername, t2.ordername, t3.ordername). On OnExecution of the t1 "Target profit", I change the t2 & t3 stops, by calling SetStopLoss.

    In the example shown on the attached image, at 10:30, when the first order (t2.ppa$ES.Buy@05/02/13-10:25:00) reach its target (1581.25), the second order (t2.ppa$ES.Buy@05/02/13-10:25:00) stop is changed to 1580.75, but NT choose to execute the original stop of 1579.75, which was set initially.

    The print shows the order trace where the change calls take place:
    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='t2.t1.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1580.75 Currency=0 Simulated=False
    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='t3.t1.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1580.75 Currency=0 Simulated=False
    Here is the code of OnExecution:
    Code:
    protected override void OnExecution(IExecution execution)
    {
    	// if target has meet, update the next targets stops
    	if ((execution.Name == targetName)
    		&& (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled))
    	{
    		string eOrderName = execution.Order.FromEntrySignal;
    		double eOrderStopPrice;
    		if (execution.Order.OrderAction == OrderAction.Sell || execution.Order.OrderAction == OrderAction.SellShort) // its the opposit dir					
    		{
    			if (eOrderName.Substring(0, 3) == "t1.")
    			{
    				eOrderStopPrice = getTargetStop(2, execution.Price, 1); 
    				SetStopLoss("t2."+eOrderName, CalculationMode.Price, eOrderStopPrice - (stopPassThrough ? priceTouch : 0), false);
    			}
    			if (eOrderName.Substring(0, 3) != "t3.")
    			{
    				eOrderStopPrice = getTargetStop(3, execution.Price, 1); 
    				SetStopLoss("t3."+eOrderName, CalculationMode.Price, eOrderStopPrice - (stopPassThrough ? priceTouch : 0), false);
    			}
    		}
    		else
    		{
    			if (eOrderName.Substring(0, 3) == "t1.")
    			{
    				eOrderStopPrice = getTargetStop(2, execution.Price, -1); 
    				SetStopLoss("t2."+eOrderName, CalculationMode.Price, eOrderStopPrice + (stopPassThrough ? priceTouch : 0), false);
    			}
    			if (eOrderName.Substring(0, 3) != "t3.")
    			{
    				eOrderStopPrice = getTargetStop(3, execution.Price, -1); 
    				SetStopLoss("t3."+eOrderName, CalculationMode.Price, eOrderStopPrice + (stopPassThrough ? priceTouch : 0), false);
    			}
    		}
    		orderTimeBaseCounter = Off;			
    	}
    }
    Here is the complete relevant order trace:

    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='t1.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1579.75 Currency=0 Simulated=False
    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='t1.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1581.2475 Currency=0 Simulated=False
    5/2/2013 10:25:00 AM Entered internal PlaceOrder() method at 5/2/2013 10:25:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1580.50 StopPrice=0 SignalName='t1.ppa$ES.Buy@05/02/13-10:25:00' FromEntrySignal=''
    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='t2.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1579.75 Currency=0 Simulated=False
    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='t2.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1581.9975 Currency=0 Simulated=False
    5/2/2013 10:25:00 AM Entered internal PlaceOrder() method at 5/2/2013 10:25:00 AM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=1580.50 StopPrice=0 SignalName='t2.ppa$ES.Buy@05/02/13-10:25:00' FromEntrySignal=''
    5/2/2013 10:25:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00035/Backtest' Name='Stop loss' State=Working Instrument='ES 12-13' Action=Sell Limit price=0 Stop price=1579.75 Quantity=1 Strategy='bdtStrPPA' Type=Stop Tif=Gtc Oco='NT-00022-5838' Filled=0 Fill price=0 Token='1df26d4100924fa0bf8809b6b02218bb' Gtd='12/1/2099 12:00:00 AM'
    Price=1581.25 Quantity=1 Market position=Short Commission=0 Order='NT-00036' Time='5/2/2013 10:30:00 AM'> $Dir=1, $Enter=1580.5, $Target=1581.25, $Stop=1579.75, $TimeBase=4
    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='t2.t1.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1580.75 Currency=0 Simulated=False
    5/2/2013 10:25:00 AM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='t3.t1.ppa$ES.Buy@05/02/13-10:25:00' Mode=Price Value=1580.75 Currency=0 Simulated=False
    5/2/2013 10:25:00 AM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00035/Backtest' Name='Stop loss' State=Cancelled Instrument='ES 12-13' Action=Sell Limit price=0 Stop price=1579.75 Quantity=1 Strategy='bdtStrPPA' Type=Stop Tif=Gtc Oco='NT-00022-5838' Filled=0 Fill price=0 Token='1df26d4100924fa0bf8809b6b02218bb' Gtd='12/1/2099 12:00:00 AM'
    5/2/2013 10:30:00 AM Cancelled expired order: BarsInProgress=0: Order='NT-00035/Backtest' Name='Stop loss' State=Cancelled Instrument='ES 12-13' Action=Sell Limit price=0 Stop price=1579.75 Quantity=1 Strategy='bdtStrPPA' Type=Stop Tif=Gtc Oco='NT-00022-5838' Filled=0 Fill price=0 Token='1df26d4100924fa0bf8809b6b02218bb' Gtd='12/1/2099 12:00:00 AM'
    5/2/2013 11:10:00 AM Cancelled pending exit order, since associated position is closed: Order='NT-00038/Backtest' Name='Profit target' State=Working Instrument='ES 12-13' Action=Sell Limit price=1582 Stop price=0 Quantity=1 Strategy='bdtStrPPA' Type=Limit Tif=Gtc Oco='NT-00023-5838' Filled=0 Fill price=0 Token='c027b0682f794146915f5ad0ff3c0366' Gtd='12/1/2099 12:00:00 AM'
    5/2/2013 11:10:00 AM Cancelled OCO paired order: BarsInProgress=0: Order='NT-00038/Backtest' Name='Profit target' State=Cancelled Instrument='ES 12-13' Action=Sell Limit price=1582 Stop price=0 Quantity=1 Strategy='bdtStrPPA' Type=Limit Tif=Gtc Oco='NT-00023-5838' Filled=0 Fill price=0 Token='c027b0682f794146915f5ad0ff3c0366' Gtd='12/1/2099 12:00:00 AM'
    Attached Files

    #2
    Thanks for the report Shai, the Set's internal processing would be tied to the bar updates - if you reset the stoploss on the next bar after your T1 filled, would you see the expected 'trailed' outcome then?
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Dear Bertrand,

      Maybe I was not clear in my exlaining.

      Lets say its a buy order, Initially I set 2 or 3 orders (depend on risk manegment):
      t1 with a limit1, stop stop1 and a target target1
      t2 with a limit1, stop stop2=stop1 and a target target2>target1
      t3 with a limit1, stop stop3=stop1 and a target target3>target2

      When the target1 is executed, I then want change the stop2 and stop3 to be 2 ticks below target1.

      This is what you see here, stop2, which acnoledge order, but does't set.

      Comment


        #4
        Thanks Shai, I understood the report, please see the question that I raised below. The internal processing of the set methods is really tied to the bar updates, for more control the Exit methods with native IOrder return would be better for your scenario here.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Dear Bertrand,

          Just to let you know, that I found my problem, and it was in the eOrderName, which included the "t1.". So after fixing my bug, everything works as expected.

          The reason I decided to use SetStopLossand SetTargetProfit and not the IOrder approach, was that, with the IOrder, sometime the stop order was rejected, because at the timing of after the order was executed, the price went below the stop price, and I was exposed. With SetStopLoss the stop will always there.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by techgetgame, Yesterday, 11:42 PM
          0 responses
          8 views
          0 likes
          Last Post techgetgame  
          Started by sephichapdson, Yesterday, 11:36 PM
          0 responses
          2 views
          0 likes
          Last Post sephichapdson  
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,613 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Yesterday, 05:56 PM
          0 responses
          10 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          20 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Working...
          X