Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Profit and Stop

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

    Profit and Stop

    Hi,

    I'm wanting to place a profit target and stop loss when I enter into the market.
    I have been playing around with this and looking in the forum but I cant quite script it in the correct way.

    - I want my profit target to = ATR20 on bar "0".
    SetProfitTarget(????????????????)

    - And I want my Stop loss to = Low of bar "0", -2 ticks.
    SetStopLoss(??????????????????)

    Can you please let me know how to script this and also let me know if it goes under Initialize() or OnBarUpdate()


    Many Thanks,

    Michael

    #2
    Michael, please take a look at this sample here - http://www.ninjatrader-support2.com/...ead.php?t=3222

    You would need to set some default value in the Initialize() for both Target and Stop, then revert to this when you strategy is flat, as in the above sample.

    For your dynamic adjustments to those, the OnBarUpdate() is the correct location - when you filled (Market Position change), you can then set to both as needed.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      Thanks for the reply I have viewed that example, I'm just struggling to write the correct dynamic adjustments in the OnBarUpdate() section?

      Can you please help me by filling in the ?????????? below?

      - I want my profit target to = ATR20 on bar "0".
      SetProfitTarget(????????????????)

      - And I want my Stop loss to = Low of bar "0", -2 ticks.
      SetStopLoss(??????????????????)


      Many Thanks,

      Michael

      Comment


        #4
        Michael, for example for the stop you could start working with -

        Code:
         
        if (Close[0] > Close[5]) // some entry trigger to get us going
        {
        EnterLong(1, "");
        myStopValue = Close[0] - 2 * TickSize;
        }
        
        if (Position.MarketPosition == MarketPosition.Long)
        SetStopLoss(CalculationMode.Price, myStopValue);
        Same would work for the target, just use some ATR offset instead of TickSize then...
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi Bertrand,

          Thanks for that, It seems I have everything in order apart form this line
          myStopValue = Close[0] - 2 * TickSize;

          The Error is saying - "Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)' Code CS0266 and it has no extra info on the Error?
          Can you please help me correct this Error?

          Thanks,

          Michael

          Comment


            #6
            myStopValue needs to be a double variable not an int.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi Josh,

              Thanks for that,

              Can you please show me how to make it a double variable?
              myStopValue = Close[0] - 2 * TickSize;

              Many Thanks,

              Michael

              Comment


                #8
                You want to declare it as double in the Initialize() Michael -

                Code:
                 
                private double myStopValue;
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Great, Thanks Bertrand,
                  That gives me something to work with now.
                  I may have some more questions on this at a later stage, but thanks again for your help so far


                  Michael

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by cmtjoancolmenero, Yesterday, 05:05 PM
                  3 responses
                  33 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
                  27 responses
                  88 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by naanku, Yesterday, 07:25 PM
                  2 responses
                  13 views
                  0 likes
                  Last Post bltdavid  
                  Started by dcriador, Yesterday, 10:45 AM
                  3 responses
                  27 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by SnailHorn, Yesterday, 10:49 PM
                  2 responses
                  14 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X