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

Change Stop Loss when the price moves into my favor.

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

    Change Stop Loss when the price moves into my favor.

    Hi, I have searched into the forum and none of the solution worked. I am trying to change the Stop Loss when the price moves 8 ticks, I have tried several approaches from the forum but none of them worked. The result is that the SL is only accepted if I dont change from the initial definition in the DataLoaded Area

    Please help!


    ......
    else if (State == State.DataLoaded)
    {
    SetProfitTarget("", CalculationMode.Ticks, TargetLargo/TickSize);
    SetStopLoss("", CalculationMode.Ticks, StopLargo/TickSize, true);
    }


    Below the code I am using under OnBarUpdate()

    // Resets the stop loss to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetProfitTarget("", CalculationMode.Ticks, TargetLargo/TickSize);
    SetStopLoss("", CalculationMode.Ticks, StopLargo/TickSize, false);
    }

    // IF PT > 8 ticks move the SL to Breakeven
    if (Close[0] > Position.AveragePrice + 8 * TickSize)
    {
    Print(Time[0].ToString()+ @"This should be changing SL");
    SetStopLoss(CalculationMode.Price, Position.AveragePrice); // Precio de compra mas un tick
    }
    else
    {
    SetStopLoss("", CalculationMode.Ticks, StopLargo/TickSize, false);
    }




    #2
    Hello lordvader34,

    I have a working example you may benefit from named ProfitChaseStopTrailSetMethodsExample_NT8.


    The code you have does appear to triggered when the close is 8 ticks above the position average price. Are you seeing the print appear?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea, thanks for your answer, the print never appears, sorry for the newbie question, but should I expect to see it in the chart or in the output?

      Comment


        #4
        Hello lordvader34,

        Prints appear in the output window.

        Below is a link to a forum post that demonstrates using prints to understand behavior and includes videos.


        Add a print that prints the values of the condition that leads to that print. Are all of the values what you expect?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you so much!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Kaledus, Today, 01:29 PM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frankthearm, Yesterday, 09:08 AM
          13 responses
          45 views
          0 likes
          Last Post frankthearm  
          Started by PaulMohn, Today, 12:36 PM
          2 responses
          16 views
          0 likes
          Last Post PaulMohn  
          Started by Conceptzx, 10-11-2022, 06:38 AM
          2 responses
          55 views
          0 likes
          Last Post PhillT
          by PhillT
           
          Started by yertle, Yesterday, 08:38 AM
          8 responses
          37 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Working...
          X