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

Help plz...Three day low trailing stop

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

    Help plz...Three day low trailing stop

    I have tried dozen of times to create a strategy where long stop exit will be triggered when it touches the previous 3-day low. I would be grateful if someone could help.

    #2
    Hello JT1230,

    You can use Lows, which will hold an array of DataSeries objects holding historical bar low prices. A DataSeries object is added to this array when calling the Add() method in a Custom Strategy. Add a Daily Data Series to your chart so you reference daily bars.
    Code:
    [LEFT][FONT=Courier New][SIZE=2]Add(PeriodType.Day,[/SIZE]  I have included the Lows Help Guide to assist you further.
      
     [FONT=Courier New][SIZE=2][COLOR=#800080]1[/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            stopPrice = Low[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]];     [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Low[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] <= LowestBar(Lows[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]             ExitLongStop(stopPrice);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            }[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            [/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]            }    
    [/SIZE][/FONT][/LEFT]



    [/FONT][/COLOR]
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      What does it meant by [ the name "ExitLongStop" does not exist in the current context] ?

      Comment


        #4
        Hello JT1230,


        Could you please reply with your script attached, so that I may investigate this behavior further?


        You can attach your strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your strategy > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.



        You could post the script to your forum reply, or send an email to platformsupport [at] ninjatrader [dot] com with the script as an attachment. In the email please include a link to this forum thread.
        Shawn B.NinjaTrader Customer Service

        Comment


          #5
          I think the error appears because "ExitLongStop" is for NT7 and "ExitLongStopMarket" is for NT8, please correct me if I'm wrong. And I cant seem to be able to do a backtest using this strategy

          Comment


            #6
            Hello JT1230,
            This is correct, if you are in NT8 you would need to use ExitLongStopMarket(). If you are still unable to backtest your strategy, use the steps outlined in my previous post to send us your script.
            Shawn B.NinjaTrader Customer Service

            Comment


              #7
              Is it possible for us to make three day high-low trailing stop instead of stick, percent and price?

              Comment


                #8
                Hello,
                Hello,


                To do this, set your SetTrailStop() value to the three day low.


                Code:
                [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/SIZE][FONT=Courier New][SIZE=2] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]Initialize()[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]        {[/SIZE][/FONT][FONT=Courier New][SIZE=2]      Add(PeriodType.Day, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]        }[/SIZE][/FONT][/LEFT]
                [/FONT][/COLOR]
                [COLOR=#000000][FONT=Tahoma]
                [/FONT][/COLOR]
                [COLOR=#000000][FONT=Tahoma]
                [/FONT][/COLOR]
                [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]        {[/SIZE][/FONT][/LEFT]
                [/FONT][/COLOR]
                [COLOR=#000000][FONT=Tahoma]
                [/FONT][/COLOR]
                [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2] stopPrice = Low[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080] 0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]];    [/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]
                [/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]                  [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Low[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]] <= LowestBar(Lows[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]], [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]3[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]            {[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]                  SetTrailStop([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] , CalculationMode.Price, stopPrice, [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] );[/SIZE][/FONT]
                [FONT=Courier New][SIZE=2]            }     
                [/SIZE][/FONT][/LEFT]
                [/FONT][/COLOR]
                [/FONT][/COLOR]
                I have included the SetTrailStop() Help Guide to assist you further.
                Shawn B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by fx.practic, 10-15-2013, 12:53 AM
                5 responses
                5,406 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by Shai Samuel, 07-02-2022, 02:46 PM
                4 responses
                98 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by DJ888, Yesterday, 10:57 PM
                0 responses
                8 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by MacDad, 02-25-2024, 11:48 PM
                7 responses
                160 views
                0 likes
                Last Post loganjarosz123  
                Started by Belfortbucks, Yesterday, 09:29 PM
                0 responses
                9 views
                0 likes
                Last Post Belfortbucks  
                Working...
                X