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

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 Javierw.ok, Today, 04:12 PM
              0 responses
              4 views
              0 likes
              Last Post Javierw.ok  
              Started by timmbbo, Today, 08:59 AM
              2 responses
              10 views
              0 likes
              Last Post bltdavid  
              Started by alifarahani, Today, 09:40 AM
              6 responses
              40 views
              0 likes
              Last Post alifarahani  
              Started by Waxavi, Today, 02:10 AM
              1 response
              18 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Kaledus, Today, 01:29 PM
              5 responses
              15 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X