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 benmarkal, Yesterday, 12:52 PM
              3 responses
              23 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by helpwanted, Today, 03:06 AM
              1 response
              19 views
              0 likes
              Last Post sarafuenonly123  
              Started by Brevo, Today, 01:45 AM
              0 responses
              11 views
              0 likes
              Last Post Brevo
              by Brevo
               
              Started by pvincent, 06-23-2022, 12:53 PM
              14 responses
              244 views
              0 likes
              Last Post Nyman
              by Nyman
               
              Started by TraderG23, 12-08-2023, 07:56 AM
              9 responses
              388 views
              1 like
              Last Post Gavini
              by Gavini
               
              Working...
              X