Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Move stop to Break Even error

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

    Move stop to Break Even error

    I am unable to move my stop to breakeven after the 1st contract is filled, even though my code prints to the output window correctly, the stop order does not change in the DOM. I turned on trace orders and, it shows there is an error. Can someone help me fix this issue?

    Output window shows:
    2/24/2014 7:33:53 AM Ignored internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=1847 Currency=0 Simulated=False' Reason='Another SetStopTarget() method call has already submitted a stop/target order'
    Move long stop b/e1847


    Code:
    protected override void Initialize()
            {
    
                           CalculateOnBarClose = false;
    			EntriesPerDirection = 2;
    			EntryHandling 		= EntryHandling.UniqueEntries;
    			SetProfitTarget("a",CalculationMode.Ticks,12);
    			SetProfitTarget("b",CalculationMode.Ticks,8);
    			//SetStopLoss(CalculationMode.Ticks,8);
    			
    			
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                // Condition set 1
                if(!Historical){
    				if(Position.MarketPosition == MarketPosition.Flat)
    				{
    					Random rnd = new Random();
    					if(rnd.Next(10) >= 5){
    						SetStopLoss("a",CalculationMode.Ticks,8,false);
    						SetStopLoss("b",CalculationMode.Ticks,8,false);
    						EnterLongLimit(Close[0],"a"); 
    						EnterLongLimit(Close[0],"b");
    						filledOne = true;
    						
    					}else{
    						SetStopLoss("a",CalculationMode.Ticks,8,false);
    						SetStopLoss("b",CalculationMode.Ticks,8,false);
    						EnterShortLimit(Close[0],"a");
    						EnterShortLimit(Close[0],"b");
    						filledOne = true;
    						
    					}
    				}
    				else{
    					if(Position.Quantity == 1 && filledOne){
    						if(Position.MarketPosition == MarketPosition.Long && Close[0] > Position.AvgPrice + 1){
    							SetStopLoss("b",CalculationMode.Price,Position.AvgPrice,false);
    							filledOne = false;
    							Print("Move long stop b/e" + Position.AvgPrice);
    						}
    						else if(Position.MarketPosition == MarketPosition.Short && Close[0] < Position.AvgPrice - 1){
    							SetStopLoss("b",CalculationMode.Price,Position.AvgPrice,false);
    							filledOne = false;
    							Print("Move short stop b/e" + Position.AvgPrice);
    						}
    
    					}
    				}
    			}
    			
            }
    Last edited by habibalex; 03-09-2014, 04:31 PM.

    #2
    Hello habibalex,

    Thank you for your post.

    Can you provide the full strategy code in it's .cs file format to test further on my end? Can you also provide your log and trace files so I may investigate this error message further? In addition, please advise what instrument, period type and interval you are testing the strategy on.

    You can do this by going to the Control Center-> Help-> Mail to Support-> ensure the log and trace option is enabled and attach the strategy's .cs file to your response. You will find the file under (My) Documents\NinjaTrader 7\bin\Custom\Strategy. Please place 'ATTN: Patrick - 1032148' 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=64505

    Comment


      #3
      sorry for the late reply, i am sending it right now

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by manueldecastro, Yesterday, 10:26 AM
      6 responses
      25 views
      0 likes
      Last Post manueldecastro  
      Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
      24 responses
      75 views
      0 likes
      Last Post cmtjoancolmenero  
      Started by businessman1929, 04-29-2024, 01:28 PM
      3 responses
      32 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by mintos, 04-02-2024, 08:22 PM
      3 responses
      27 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Creamers, 04-27-2024, 05:32 AM
      13 responses
      74 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X