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

How do I embed a simple Stop Loss into my NinjaScript strategy?

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

    How do I embed a simple Stop Loss into my NinjaScript strategy?

    I created a basic strategy using the StrategyBuilder that runs well but needs a stop loss of a point or so to maximize profits. Does anyone have an EXAMPLE of a stop loss within NinjaScript that I can follow? I read all of the Ninja Support links and found nothing that matches my needs.

    #2
    Hello emersontimmins,

    Thanks for your post and welcome to the NinjaTrader forums!

    I've attached an example of a stoploss in a strategy builder. The stop loss uses the "Mode" of ticks and I entered the value of 4. You would need to enter the number of tick you need that equates to 1 point of your instrument.

    This stop loss is immediately employed when an entry is made, long or short, and will deploy 4 ticks away from the entry price on the correct side for a stop loss.


    Click image for larger version

Name:	Emmersont-1.PNG
Views:	184
Size:	38.6 KB
ID:	1139444


    In case you have not seen these:
    Here are the educational resource available on the strategy builder:
    Free live webinar every other Thursday at 4:00 PM EST, through this link to all webinars: https://ninjatrader.com/PlatformTraining
    Previous recording of the Strategy Builder 301 webinar: https://youtu.be/HCyt90GAs9k?list=PL...auWXkWe0Nf&t=2
    Help guide for the strategy builder: https://ninjatrader.com/support/help...gy_builder.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank You. I also learned that I can edit existing Strategies by inserting:
      SetStopLoss(@"Buy", CalculationMode.Ticks, 150, false);
      SetStopLoss(@"Sell", CalculationMode.Ticks, 150, false);
      Into my "if/and" definitions section. I used a value of 4 as you mentioned, but my fills were immediately Stopped out. It turns out that For AAPL, FB... 100 Ticks = 1 point.
      Thanks for getting me in the right direction, It seems to be executing properly now.
      One new issue that came up was that when backtesting 9 day, my algo makes 1077 trades and if I backtest 180 days the number of trades are still 1077. 5,10,30 increase the number of trades as expected?

      Comment


        #4
        Oops, 90 days not 9 day.

        Comment


          #5
          Hello emersontimmins,

          Thanks for your reply.

          It sounds like you may not have all the historical data needed.

          In the strategy analyzer, I would specify a begin and end date and run the strategy. Then change the display to "Trades" and look at the first trade date time and the last trade date time. if they do not match what the range is set to then change the display to "Chart" and on the chart scroll all the way to the left for the first bar of data and check the date/time of the bar.

          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          3 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          238 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          384 views
          1 like
          Last Post Gavini
          by Gavini
           
          Started by oviejo, Today, 12:28 AM
          0 responses
          4 views
          0 likes
          Last Post oviejo
          by oviejo
           
          Started by pechtri, 06-22-2023, 02:31 AM
          10 responses
          125 views
          0 likes
          Last Post Leeroy_Jenkins  
          Working...
          X