Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AtmStrategyChangeStopTarget

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

    AtmStrategyChangeStopTarget

    Hi guys, I'm having some problems with AtmStrategyChangeStopTarget and would appreciate some help.

    Basically I'm scaling into a strategy using two separate ATM strategies within one strategy and then moving the stop of the 1st strategy/trade up to the stop of the second trade once the second trade is active. The problem is I'm getting all these errors in the log. The stop moves ok.

    AtmStrategyChangeStopTarget()method error: Order Name STOP1 does not exist. I also get it for STOP 2 for TARGET 1 and TARGET 2 as well.

    The problem is in the scale 1 part doesn't work.

    AtmStrategyChangeStopTarget(0, lineStopline+5*TickSize, "STOP1", atmStrategyId1);
    AtmStrategyChangeStopTarget(0, lineStopline+5*TickSize, "STOP2", atmStrategyId1);
    }

    Here is the code.

    PHP Code:

    {
                    
                    
                    
    //i. Set stops on entry                
                        
    {        
                        if (
    GetAtmStrategyRealizedProfitLoss(atmStrategyId1) <1)
                        {                    
                            
                        
    AtmStrategyChangeStopTarget(0lineStopline"STOP1"atmStrategyId1);                    
                        
    AtmStrategyChangeStopTarget(0lineStopline"STOP2"atmStrategyId1);                    
                                            
                        }                        
                                        
                        
                        
    //ii. Set Targets on entry                
                        
                        
    AtmStrategyChangeStopTarget(lineTargetone,0"TARGET1"atmStrategyId1);                                        
                        
    AtmStrategyChangeStopTarget(lineTargettwo,0"TARGET2"atmStrategyId1);                                            
                        
                                        
                        
                        
    //iii. Change Stop 2 to Breakeven once 1st Target reached
                        
                        
    if (GetAtmStrategyRealizedProfitLoss(atmStrategyId1) >1)
                            
                        {                    
                        
    AtmStrategyChangeStopTarget(0GetAtmStrategyPositionAveragePrice(atmStrategyId1)+1*TickSize"STOP2"atmStrategyId1);                        
                        }
                                            
                }        
                    
                
    //Scale in 1        
                        
                
    if (atmStrategyId2.Length &&  GetAtmStrategyMarketPosition(atmStrategyId2) == Cbi.MarketPosition.Long
                    
    )
                {            
                        
    //Scale in
                        
                        
    if (GetAtmStrategyRealizedProfitLoss(atmStrategyId2) <1)
                        {    
                        
    AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP1"atmStrategyId2);                    
                        
    AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP2"atmStrategyId2);                                        
                        
    AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP1"atmStrategyId1);                                            
                        
    AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP2"atmStrategyId1);                                                
                        }    
                                            
                        
    //Scale in
                        
                        
    AtmStrategyChangeStopTarget(lineTargetone,0"TARGET1"atmStrategyId2);                                        
                        
    AtmStrategyChangeStopTarget(lineTargettwo,0"TARGET2"atmStrategyId2);                                            
                        
                        
    //iii. Change Stop 2 to Breakeven once 1st Target reached
                        
                        
    if (GetAtmStrategyRealizedProfitLoss(atmStrategyId2) >1)
                            
                        {                    
                        
    AtmStrategyChangeStopTarget(0GetAtmStrategyPositionAveragePrice(atmStrategyId2)+1*TickSize"STOP2"atmStrategyId2);                        
                        }                                        
                } 
    Thanks
    DJ
    Last edited by djkiwi; 12-18-2012, 02:44 PM.

    #2
    Hello DJ,

    Thank you for your post.

    For the Scale in 1 section you are only checking that the atmStrategyId2 exists and not if the atmStrategyId1 exists, so this could return true even though you do not have an atmStrategyId1 and return the error message when trying to change the stop as the atmStrategyId1 does not exist.

    If you wish to scale in both at the same time you will need to add the check for the atmStrategyId1 as well:
    Code:
    if (atmStrategyId2.Length > 0 &&  [B]atmStrategyId1.Length > 0[/B] && GetAtmStrategyMarketPosition(atmStrategyId2) == Cbi.MarketPosition.Long)
    Please let me know if you have any questions.

    Comment


      #3
      Thanks Patrick, unfortunately that didn't work, same error. Here is the complete code. The reason I think your idea didn't work is because all it is testing is whether atmStrategyId2.Length > 0. If that is > 0 then it should work ok for atmStrategyId1.Length > 0 and doesn't need to test atmStrategyId1.Length > 0 . I've highlighted the problems lines in red bold. I also tried the orange bold below which didn't work either. I thought I would need to say that strategy 2 is inactive otherwise it would involve both.

      Any other ideas? Thanks. DJ

      PHP Code:

      Scale in first trade

      if (atmStrategyId1.Length && GetAtmStrategyMarketPosition(atmStrategyId1) == Cbi.MarketPosition.Long 
      &&atmStrategyId2.Length 1
                                      
                      
      )
                  {
                      
                      
                      
      //i. Set stops on entry                
                          
      {        
                          if (
      GetAtmStrategyRealizedProfitLoss(atmStrategyId1) <1)
                          {                                            
                          
      AtmStrategyChangeStopTarget(0lineStopline"STOP1"atmStrategyId1);                                                
                          
      AtmStrategyChangeStopTarget(0lineStopline"STOP2"atmStrategyId1);    
                          }                        
                              
                          
                          
      //ii. Set Targets on entry                
                          
                          
      AtmStrategyChangeStopTarget(lineTargetone,0"TARGET1"atmStrategyId1);                                        
                          
      AtmStrategyChangeStopTarget(lineTargettwo,0"TARGET2"atmStrategyId1);                                        
                          
                          
      //iii. Change Stop 2 to Breakeven once 1st Target reached
                          
                          
      if (GetAtmStrategyRealizedProfitLoss(atmStrategyId1) >1)
                              
                          {                    
                          
      AtmStrategyChangeStopTarget(0GetAtmStrategyPositionAveragePrice(atmStrategyId1)+1*TickSize"STOP2"atmStrategyId1);                        
                          }                                        
                  }        
                      
      //Scale in next trade
                          
                  
      if (atmStrategyId2.Length && GetAtmStrategyMarketPosition(atmStrategyId2) == Cbi.MarketPosition.Long
                      
      )
                      
                      
                  {            
                          
      //Scale in
                          
                          
      if (GetAtmStrategyRealizedProfitLoss(atmStrategyId2) <1)
                          {    
                          
                      
      //    AtmStrategyChangeStopTarget(0, lineStopline+5*TickSize, "STOP1", atmStrategyId1);                                            
                      //    AtmStrategyChangeStopTarget(0, lineStopline+5*TickSize, "STOP2", atmStrategyId1);                                                    
                          
      AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP1"atmStrategyId2);                    
                          
      AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP2"atmStrategyId2);            
                          }    
                                              
                          
      //Scale in
                          
                          
      AtmStrategyChangeStopTarget(lineTargetone,0"TARGET1"atmStrategyId2);                                        
                          
      AtmStrategyChangeStopTarget(lineTargettwo,0"TARGET2"atmStrategyId2);                                            
                          
                          
      //iii. Change Stop 2 to Breakeven once 1st Target reached
                          
                          
      if (GetAtmStrategyRealizedProfitLoss(atmStrategyId2) >1)
                              
                          {                    
                          
      AtmStrategyChangeStopTarget(0GetAtmStrategyPositionAveragePrice(atmStrategyId2)+1*TickSize"STOP2"atmStrategyId2);                        
                          }                                        
                  } 

      Comment


        #4
        Hello DJ,

        Thank you for your response.

        So I may investigate this matter further can you provide the conditions and actions used to create both ATM Strategies that you are trying to change with your scale in logic?

        I look forward to your response.

        Comment


          #5
          Thanks Patrick, I solved that one but now have another. The scaling works ok. The only problem I'm having is once I try to move the stop on the first strategy.

          So what happens is once the second strategy is in force the the first strategy should more the stop up 10 ticks which it does. I'm using the code below. The problem is it just keeps looping whereby it keeps changing the same order continuously. How do I make it so that once the second strategy goes long it just processes the atmchangeorder for strategy 1 once and not repeating as per the log? Thanks DJ

          PHP Code:
          if (atmStrategyId2.Length && GetAtmStrategyMarketPosition(atmStrategyId2) == Cbi.MarketPosition.Long)
                              {
                              
          AtmStrategyChangeStopTarget(0,  lineStopline+10*TickSize"STOP1"atmStrategyId1);                                            
                              
          AtmStrategyChangeStopTarget(0,  lineStopline+10*TickSize"STOP2"atmStrategyId1);                        
                              } 
          Last edited by djkiwi; 12-19-2012, 11:55 AM.

          Comment


            #6
            Hello DJ,

            Thank you for your response.

            You can use the OnExecution() method to ensure the AtmStrategyChangeStopTarget() only runs when the second ATM Strategy goes long and not on every OnBarUpdate() when the ATM strategy is long.

            For example:
            Code:
            protected override void OnExecution(IExecution execution)
            {
                if (atmStrategyId2.Length != 0 && GetAtmStrategyMarketPosition(atmStrategyId2) == Cbi.MarketPosition.Long)
                                {
                                AtmStrategyChangeStopTarget(0,  lineStopline+10*TickSize, "STOP1", atmStrategyId1);                                            
                                AtmStrategyChangeStopTarget(0,  lineStopline+10*TickSize, "STOP2", atmStrategyId1);                        
                                } 
            }
            For information on OnExecution() please visit the following link: http://www.ninjatrader.com/support/h...nexecution.htm

            For a reference sample on using OnExecution() please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=7499

            Please let me know if I may be of further assistance.

            Comment


              #7
              Hi Patrick that didn't seem work. I put it after onbarupdate but it never moved the stop. Plus I'm not sure what it is doing. I can see the problem. Because the condition is always true it keeps trying to modify the stop. Any other ideas you can think of?

              Also I'm confused as I've never had this problem before. For example when I do this part in the code, it only does it once and doesn't keep trying to update orders nonstop. Note sure whats different:

              PHP Code:
              //i. Set stops on entry                
                                  
              {        
                                  if (
              GetAtmStrategyRealizedProfitLoss(atmStrategyId1) <1)
                                  {                                            
                                  
              AtmStrategyChangeStopTarget(0lineStopline"STOP1"atmStrategyId1);                                                
                                  
              AtmStrategyChangeStopTarget(0lineStopline"STOP2"atmStrategyId1);    
                                  } 
              Cheers
              DJ
              Last edited by djkiwi; 12-19-2012, 06:31 PM.

              Comment


                #8
                Hello DJ,

                Thank you for your response.

                I would like to note that realized PnL is not calcualted until an ATM strategy is closed, you will want to use GetAtmStrategyUnrealizedProfitLoss().
                For information on GetAtmStrategyUnrealizedProfitLoss() please visit the following link: http://www.ninjatrader.com/support/h...izedprofit.htm

                Please let me know if implementing GetAtmStrategyUnrealizedProfitLoss() in place of GetAtmStrategyRealizedProfitLoss() resolves this matter.

                Comment


                  #9
                  Patrick the realized part is working fine as it is moving the stop to the line after entry. I'm not worried about that part. The issue is this:

                  1. Trade 1 live ok
                  2. trade 2 live ok

                  Once trade 2 is live the stop from trade one needs to move up 5 ticks. I'm using the code below to say that once trade 2 is long move up the stop to trade 1 4 ticks. It keeps trying to process the ATM change order nonstop. I only want to the order to change once. Any other ideas on how to fix this problem. If not is there someone else you can talk to about these ATM strategies?

                  Thanks in advance.
                  DJ

                  PHP Code:
                  if (atmStrategyId2.Length && GetAtmStrategyMarketPosition(atmStrategyId2) == Cbi.MarketPosition.Long
                                  
                  )                
                                  
                              {            
                                      
                  //Move trade 1 stops up 5 ticks                    
                                   
                                                      
                                      
                  AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP1"atmStrategyId1);                    
                                      
                  AtmStrategyChangeStopTarget(0lineStopline+5*TickSize"STOP2"atmStrategyId1);            
                                      } 

                  Comment


                    #10
                    Hello DJ,

                    Thank you for your response.

                    So I may investigate this matter further please provide either a toy version or the full version of your strategy. If you prefer you can send this to support[at]ninjatrader[dot]com with 'ATTN: Patrick' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=54664

                    I look forward to your response.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by pmachiraju, 11-01-2023, 04:46 AM
                    8 responses
                    148 views
                    0 likes
                    Last Post rehmans
                    by rehmans
                     
                    Started by mattbsea, Today, 05:44 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post mattbsea  
                    Started by RideMe, 04-07-2024, 04:54 PM
                    6 responses
                    33 views
                    0 likes
                    Last Post RideMe
                    by RideMe
                     
                    Started by tkaboris, Today, 05:13 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post tkaboris  
                    Started by GussJ, 03-04-2020, 03:11 PM
                    16 responses
                    3,283 views
                    0 likes
                    Last Post Leafcutter  
                    Working...
                    X