Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stop loss question

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

    stop loss question

    I would like to set my stop loss to the low of the previous bar and also a hard out lets say of a 1 point, just incase the prevoius bars low is more then a point. how would this be written?

    If long

    SetStopLoss (Low[1]); or SetStopLoss(calculationmode.ticks, stoplossticks)



    Stoplossticks is = 100tick

    Is this correct

    #2
    Once long, you would need to check the difference between the (Position.AvgPrice - Low[2]) / TickSize, then check if this calculation is less than 100 ticks if yes, call SetStopLoss(CalculationMode.Price, Low[2])...

    Something like that.
    RayNinjaTrader Customer Service

    Comment


      #3
      once long

      stoplossticks= 100

      if ((Postion.AvgPrice - Low[1]) / TickSize < 100 * TickSize)


      SetStopLoss(Low[1])


      if ((Postion.AvgPrice - Low[1]) / TickSize > 100 * TickSize)


      SetStopLoss(CalcualtionMode.Ticks, stoplossticks);

      does this look right to you as per your suggestion, one question why 2 bars ago?


      Comment


        #4
        Also I just realized a problem, I only need this function to perform at entry bar only....

        Comment


          #5
          Will not work on entry bar since you don't have the average price of the position yet to calculate the difference between the prior bar low and the entry price.
          RayNinjaTrader Customer Service

          Comment


            #6
            2 bars ago then correct?

            Comment


              #7
              You can run your calculation on the bar after entry (assuming you are filed by then) in which case you would want the low from 2 bars ago.
              RayNinjaTrader Customer Service

              Comment


                #8
                Ray thanks for your help, we fixed the 2 bar ago proble


                if (Position.MarketPosition == MarketPosition.Flat)
                {
                SetStopLoss(CalculationMode.Ticks, stoplossticks);
                }

                // If a long position is open, allow for stop loss modification elseif (Position.MarketPosition == MarketPosition.Short
                && High[
                0] <= Position.AvgPrice - 5 * TickSize)
                {
                SetStopLoss(CalculationMode.Price, Position.AvgPrice +
                20 * TickSize);
                }
                if (Position.MarketPosition == MarketPosition.Short
                && High[
                0] <= Position.AvgPrice - 25 * TickSize)
                {
                SetStopLoss(CalculationMode.Price, Position.AvgPrice -
                10 * TickSize);
                }


                THE CODE ABOVE IS WHAT WE HAVE FOR THE TRAILING STOP, I KNOW IT IS INCORRECT DUE FACT IT CONTINUES TO RECALULATE BASED ON THE LAST BAR WHEN IN THEORY I NEED TO KNOW ONCE I HAVE A 25 TICK PROFIT IT WILL LOCK IN A 10 TICK STOP LOSS AND NOT RECALCULATE AGAIN LEAVING THE STOP LOSS SET AT 10 TICKS

                Comment


                  #9
                  Not sure what your question is...in any case, the code will do what you have scripted, if its not working as expected you will have to debug it and figure out what tweaks you need to introduce etc...
                  RayNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Revazi123, Today, 08:48 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post Revazi123  
                  Started by M_ichel, Today, 08:38 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post M_ichel
                  by M_ichel
                   
                  Started by soon123, Today, 12:18 AM
                  1 response
                  20 views
                  0 likes
                  Last Post NinjaTrader_PaulH  
                  Started by space_trader, Today, 12:52 AM
                  1 response
                  20 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by ybhx0315, Yesterday, 09:06 PM
                  0 responses
                  21 views
                  0 likes
                  Last Post ybhx0315  
                  Working...
                  X