Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Recalculating Stop after profit target hit

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

    Recalculating Stop after profit target hit

    Hi,

    I have looked at Josh's sample strategy price modification but am not good at programming and I am getting compile errors line 68

    I want to set it up like my ATM where I hit a target and move the stop to + 3 ticks or use an indicator to set the stop like (SMA76 (-5))

    I have 2 positions A + B. I want to set the target as variable perhaps the first target has not been hit and I want them to both come forward static then as the SMA overcomes the point of reference I want the stop to be Equal to the indicator plus or minus a variable. Or perhaps the first Target has been hit and I want to trail the second.

    Any help would be appreciated.

    Raef






    SetProfitTarget("PositionA", CalculationMode.Ticks, TargetA);
    SetProfitTarget(
    "positionB", CalculationMode.Ticks, TargetB);
    SetStopLoss(
    "PositionA", CalculationMode.Ticks, StopA, false);
    SetStopLoss(
    "positionB", CalculationMode.Ticks, StopB, false);
    CalculateOnBarClose =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Resets the stop loss to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(
    "PositionA",CalculationMode.Ticks, StopA, false);
    SetStopLoss(
    "positionB",CalculationMode.Ticks, StopB, false);
    }

    // If a long position is open, allow for stop loss modification to breakeven
    elseif (Position.MarketPosition == MarketPosition.Long)
    {
    // Once the price is greater than entry price+TargetA+2 ticks, set stop loss to breakeven+3
    if (Close[0] > Position.AvgPrice + (TargetA + 2) * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice +
    3 * TickSize);
    }
    }

    #2
    One extra thing.
    How do I stop it from entering another position as soon as the first target is filled it is still buy ready and soon after when the conditions are met enters another PositionA
    I have it set to unique entries but I am at a loss for ideas?

    Raef

    Comment


      #3
      Raef, what is the exact error you're receiving? Also, to answer your second question, what code are you using for the entry?
      AustinNinjaTrader Customer Service

      Comment


        #4
        Hi Austin,
        The error was on the compiling but I have not saved the changes and scrapped the strategie. I guess it is better to have two different strategies if I want two different positions.

        I want to set it up like my ATM where I hit a target and move the stop to + 3 ticks profit.
        When the SMA - 15ticks > Stop Loss I then want my stop to become a trailing stop equal to SMA - 15ticks

        Any suggestions.

        Thanks Raef

        Comment


          #5
          Raef, this is indeed possible with NinjaTrader, but unfortunately we can't provide custom coding services. There has been much discussion on this forum regarding trailing stops and such so perhaps you could start by searching the forum for "trailing stop".
          AustinNinjaTrader Customer Service

          Comment


            #6
            Thanks Austin I found this area http://www.ninjatrader.com/support/f...splay.php?f=29 for samples there a few good samples there I will look through and i searched through the forum if I wasn't confused before I will be soon enough. LOL
            I see afew people are asking similar questions I'll post my results when I get them.

            Thanks Raef

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X