Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Managing stop once the position is up

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

    Managing stop once the position is up

    Hi,

    Once i get filled ( i have a stoploss of 25), but then im trying to move my stop to my entry price if the EMA 8 crosses EMA 21.

    Im having a hard time writing that into programming sentences, can anyone help?

    Thank you

    #2
    Hi fladou246,

    Just to clarify, you mean when the entry order fills correct?

    Try the following in OnBarUpdate():

    Code:
    if (Position.MarketPosition == Long && CrossAbove(EMA(8), EMA(21), 1))
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }
    The Position.MarketPosition is to see if you have taken a long position.

    You can change this to the entry order filled property if you set the entry to a IOrder handle.
    (You will want to set the handle to null when the order is exited)

    for example:

    Code:
    In #region Variables
    private IOrder entryOrder = null;
    
    
    entryOrder = EnterLongLimit();
    
    if (entryOrder != null && entryOrder.Filled == true && CrossAbove(EMA(8), EMA(21), 1))
    {
    SetStopLoss(CalculationMode.Price, entryOrder.AvgFillPrice);
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thx for the fast response!

      this is what I wrote :
      --------------------------------
      // Condition set 3
      if (Position.MarketPosition == Long && CrossAbove(EMA(8), EMA(21), 1));
      {
      SetStopLoss(CalculationMode.Price, Position.AvgPrice);
      }

      ------------------------------

      But I get 2 different errors :

      1: Only assignment, call, increment, decrement, and new object expressions can be used as a statement (code CS0201)
      2: The name 'Long' does not exist in the current context (CS0103)

      Comment


        #4
        Hi fladou246,

        That was my mistake.

        The correct code is:
        Code:
        if (Position.MarketPosition ==[B] MarketPosition.[/B]Long && CrossAbove(EMA(8), EMA(21), 1))
        {
        SetStopLoss(CalculationMode.Price, Position.AvgPrice);
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I am still having issues with managing my stop.

          Im trying to move the stop to entry price if the position is in profit when there is a crossover of the Moving average or to move my profittarget to entry price if my position is losing when theres the crossover of the moving average.

          Attached is my code!!

          Thank you very much !!

          Francis
          Attached Files

          Comment


            #6
            Hi fladou246,

            What behavior are you getting now that is incorrect?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Oh Nevermind ,everything Is working now!

              Thanks

              Francis

              Comment

              Latest Posts

              Collapse

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