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

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 maybeimnotrader, Yesterday, 05:46 PM
                  1 response
                  18 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by Perr0Grande, Yesterday, 08:16 PM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by f.saeidi, Yesterday, 08:12 AM
                  3 responses
                  25 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by algospoke, Yesterday, 06:40 PM
                  1 response
                  15 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by quantismo, Yesterday, 05:13 PM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X