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

Adjusting stop

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

    Adjusting stop

    Hello,

    I'm trying to set up a trailing type stop where once a certain price is reached, the stop will trail one tick above the high/low of the previous bar. My initial entry, stop, and profit targets are all working correctly, but the stop adjustment didn't work at all... CaculateOnBarClose = false

    My code for the trailing stop is:

    if ((Position.MarketPosition == MarketPosition.Short) && (trail == 1) && (FirstTickOfBar))
    {
    SetStopLoss(CalculationMode.Price, High[1] + TickSize);
    }

    if ((Position.MarketPosition == MarketPosition.Short) && (trail == 0) && (Close[0] == trailtarget))
    {
    SetStopLoss(CalculationMode.Price, High[1] + TickSize);
    trail = 1;
    }



    Execution completely ignored adjusting the stop, but the logic seems correct from what I see. Should I be using the ExitShortStop instead of SetStopLoss function? If that's the case, does it still leave the initial stop in place until the position is exited? Is there a way to just move the initial stop rather than having a 2nd one trailing along? Or maybe I'm misunderstanding something. trailtarget is assigned along with the initial order entry as Close[0] - value, and trail = 0 as well.
    Last edited by Xkaern; 01-08-2008, 11:47 AM.

    #2
    In concept what you wish to do is sound. You will just need to debug your code to see why its not working as you expect.

    Here is a reference sample - http://www.ninjatrader-support.com/v...ead.php?t=3222
    RayNinjaTrader Customer Service

    Comment


      #3
      Yea, I saw that reference, also. Doesn't seem much different than what I'm doing, so maybe a variable assignment has gone awry somewhere. That code should be all I need once it's functioning properly then, correct? Meaning I don't need the ExitLong/ShortStop functions? What are those used for?

      Comment


        #4
        In concept, your approach should work...I did not review your code for correct logic, you will need to do that and debug.

        - Set() methods submit orders as executions come in, Exit() methods place orders as they are called in your code
        RayNinjaTrader Customer Service

        Comment


          #5
          When playing with stop levels I always find it very helpful to place a dot on the chart like this:

          DrawDot("stop"+CurrentBar, 0, price, Color.Blue);

          It lets you know exactly what is happening with the calculation. I also use different colors for different conditions, it's an easy way to visually debug.

          Comment


            #6
            Excellent tip! Will add this to our debug tip.

            Thanks
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sidlercom80, 10-28-2023, 08:49 AM
            172 responses
            2,278 views
            0 likes
            Last Post sidlercom80  
            Started by Irukandji, Yesterday, 02:53 AM
            2 responses
            17 views
            0 likes
            Last Post Irukandji  
            Started by adeelshahzad, Today, 03:54 AM
            0 responses
            3 views
            0 likes
            Last Post adeelshahzad  
            Started by CortexZenUSA, Today, 12:53 AM
            0 responses
            3 views
            0 likes
            Last Post CortexZenUSA  
            Started by CortexZenUSA, Today, 12:46 AM
            0 responses
            1 view
            0 likes
            Last Post CortexZenUSA  
            Working...
            X