Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set Stop Loss once

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

    Set Stop Loss once

    Hi All,

    please, could you tell me the way to go with this

    The way to go...

    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    
    	// Setup 1
            EnterLong("","");
    
            // Exit 1 - Set Stop Loss at the min bar ago
            if exit1 == true{
    	double mmstop = Low[miBarsAgo];
    	SetStopLoss(CalculationMode.Price, mmstop);
            }
    
    	// Exit 2 - Set ATR Stop Loss
            if exit2 == true{
    	double mmstop = Position.AvgPrice - ATR(periodoATR)[0];
    	SetStopLoss(CalculationMode.Price, mmstop);
            }
    }
    I am triying to develop a template with several exits that i can enable or disable, from parameters, first exit works great but not the second one... I think i am not setting the ATR Stop Loss i the correct place. Could you help me?

    Best,
    Vince.
    Last edited by vibarco; 12-10-2012, 10:50 AM.

    #2
    Hello,

    Add in a Print() statement to check the value of Position.AvgPrice in the Output Window.

    Print(Position.AvgPrice);

    Try assigning your exit order in OnOrderUpdate() instead of in the OnBarUpdate()
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()



    Please let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thanks Lance,

      Print(Position.AvgPrice); The result is 0, that's is the problem. The right or profesional way is to learn OnOrderUpdate, isn't it?, while i learn OnOrderUpdate, is there a dirty solution? To Set ATR Stop Loss once, in another place of the code.

      Best,
      Vince.

      Comment


        #4
        Hello,

        Yes, this is because you are sending the entry order on the same Bar Update so the position has not yet been updated.

        The only way I can think of to avoid using OnOrderUpdate() would be to hold off on placing the stop until the next OnBarUpdate() but this would leave you unprotected until that occurred.

        Please let me know if I can be of further assistance.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Hi Lance,

          a little hard to understand OnOrderUpdate, could you give a very simple example or pseudocode? ... i am testing strategies always with EOD data.

          Best,
          Vince.

          Comment


            #6
            Hello,

            Here is a great template/tutorial for OnOrderUpdate() that we have: http://www.ninjatrader.com/support/f...ead.php?t=7499

            If you have limited time or programming capabilities, you can discuss your requirements with any of our certified NinjaScript consultants.
            Click here for a list of certified NinjaScript Consultants

            Please let me know if I can be of further assistance.
            LanceNinjaTrader Customer Service

            Comment


              #7
              Thanks Lance, i'd like to try myself.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              77 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              45 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              27 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              32 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              62 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X