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

stoploss and dynamic profit targets

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

    stoploss and dynamic profit targets

    Code:
            private void GoLong()
            {
                SetStopLoss("target1", CalculationMode.Price, Close[0] - (Stop*TickSize), false);
                
                SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
            
                EnterLong("target1");
                
            }
    
            private void ManageOrders()
            {
    
                if (Position.MarketPosition == MarketPosition.Long)
                {
                    if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
                        SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
                                    else if (High[0] > Position.AvgPrice + ((Target1+Target2)*TickSize))
                        SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + (Target1*TickSize), false);
                                    else if (High[0] > Position.AvgPrice + (Target1*TickSize))
                        SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice, false);
                    
                }
    here is what i'm trying to do:

    at entry, set a stop loss X ticks away
    when my profit target1 is hit, I want to move my stoploss to position.avgprice
    when my profit target2 is hit, i want to move my stoploss to position.avgprice+target1
    when my profit target3 is hit, i want to move my stoploss to position.avgprice+target1+target2

    #2
    Hello calhawk01,

    Thank you for your post.

    Are you experiencing any items with the code you have posted here?

    It appears to be properly coded for your conditions. Although, would the following condition to change the Stop Loss not be implemented as this would be where the Profit Target is filled?
    Code:
     if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
                        SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
    Profit Target:
    Code:
                SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));

    Comment


      #3
      Originally posted by NinjaTrader_PatrickH View Post
      Hello calhawk01,

      Thank you for your post.

      Are you experiencing any items with the code you have posted here?

      It appears to be properly coded for your conditions. Although, would the following condition to change the Stop Loss not be implemented as this would be where the Profit Target is filled?
      Code:
       if (High[0] > Position.AvgPrice + ((Target1+Target2+Target3)*TickSize))
                          SetStopLoss("target1", CalculationMode.Price, Position.AvgPrice + ((Target1+Target2)*TickSize), false);
      Profit Target:
      Code:
                  SetProfitTarget("target1", CalculationMode.Price, Close[0] + ((Target1+Target2+Target3)*TickSize));
      well it seems when target1 is hit, the stoploss is set at avgprice. and when target two is hit, the stoploss is NOT moved to target1.. and same for target 3

      Comment


        #4
        Pat, any idea what's wrong w/ my code?

        how can i reset my STOPLOSS multiple times once my targets are hit?

        i've seen the ''pricemodiciation'' template that NT provides but that was not helpful. I've tried everything!

        if target1 is hit, stoploss = avg price, if target2 is hit, stoploss = target1, if target3 is hit, stoploss = target2

        Comment


          #5
          Hello calhawk01,

          Thank you for your response.

          Please send me your complete code to support[at]ninjatrader[dot]com or a toy version of your strategy containing the Entries, Stop Losses, and Profit Targets. Please place 'ATTN: Patrick - 852512' in teh subject line and a reference to this thread int the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=58067

          I look forward to your response.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rbeckmann05, Yesterday, 06:48 PM
          1 response
          12 views
          0 likes
          Last Post bltdavid  
          Started by llanqui, Today, 03:53 AM
          0 responses
          6 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by burtoninlondon, Today, 12:38 AM
          0 responses
          10 views
          0 likes
          Last Post burtoninlondon  
          Started by AaronKoRn, Yesterday, 09:49 PM
          0 responses
          15 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Yesterday, 08:42 PM
          0 responses
          11 views
          0 likes
          Last Post carnitron  
          Working...
          X