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

Max trades today

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

    Max trades today

    What code would I use to say if max. no of trades today < 3?

    I dont want my strategy to trade more than 3 times a day...

    Thanks

    #2
    maninjapan,

    You would need to run your own counter variable and increment it up every time you trade. Then at the beginning of each session reset it back down to zero.

    For instance, if you named your counter tradeCounter...
    Code:
    if (Bars.FirstBarOfSession && FirstTickOfBar)
         tradeCounter = 0;
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      and how would one code the counter?

      Comment


        #4
        maninjapan,

        In variables region of code,
        Code:
        private int tradeCounter = 0;
        In OnBarUpdate(), whenever you trade,
        Code:
        tradeCounter++;
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for that, Im new to this, but here is my attempt at adding it to a basic breakout strategy (Ive just made some changes to what was a long only ORB sample). Any tips on where my errors are would be much appreciated
          Code:
          // 
          // Copyright (C) 2007, NinjaTrader LLC <[URL="http://www.ninjatrader.com"]www.ninjatrader.com[/URL]>.
          // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
          //
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Indicator;
          using NinjaTrader.Strategy;
          #endregion
          // This namespace holds all strategies and is required. Do not change it.
          namespace NinjaTrader.Strategy
          {
              /// <summary>
              /// Simple strategy that monitors for a breakout.
              /// </summary>
              [Description("Simple strategy that monitors for a breakout.")]
              public class SampleBreakoutStrategy : Strategy
              {
                  #region Variables
            private double highestHigh = 0;
            private double lowestLow = 0;
            private int tradeCounter = 0; 
                  #endregion
                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
                      CalculateOnBarClose = true;
                  }
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
             // Resets the highest high and lowest low at the start of every new session
             if (Bars.FirstBarOfSession && FirstTickOfBar)
                    tradeCounter = 0;
              highestHigh = High[0];
              lowestLow = Low[0];
             
             
             // Stores the highest high from the first 30 bars
             if (Bars.BarsSinceSession < 30 && High[0] > highestHigh)
              highestHigh = High[0];
             // Stores the lowest low from the first 30 bars
             if (Bars.BarsSinceSession < 30 && Low[0] < lowestLow)
              lowestLow = Low[0];
             
              //Enter Long at highest high + 1 of first 30 min. trade if number of trades today is less than 3
              if (tradeCounter < 3)
              {
              
              
               EnterLongStop(highestHigh + TickSize);
               tradeCounter++;
              }
            
              //Enter Short at lowest low - 1 of first 30 min. trade if number of trades today is less than 3
              if (tradeCounter < 3)
              {
               
               EnterShortStop(lowestLow - TickSize);
               tradeCounter++;
              }
             
             
             
            
               // Triggers the exit on close function 30 seconds prior to session end 
                  ExitOnClose        = true; 
                   ExitOnCloseSeconds = 30;
                  
                  }
              }
          }

          Comment


            #6
            // Resets the highest high and lowest low at the start of every new session
            if (Bars.FirstBarOfSession && FirstTickOfBar)
            tradeCounter = 0;
            highestHigh = High[0];
            lowestLow = Low[0];

            If you want all three of those lines to be done at the start of every new session, you need to put them in brackets.

            Code:
            if (Bars...)
            {
                tradeCounter = 0;
                highestHigh....
                ....
            }
            Otherwise, only the first tradeCounter = 0 line will be evaluated at the session start, and the other two will be done on every single bar update.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              MIN() method

              Hi,

              I dont quiet understand how the MIN()method is used.


              I basically want to Record the MAE of my trade in a variable on my indicator.

              so when high[0] hits ema50 -> then record the highest high until the Low[0] is lower than ema50-20pips.

              and advice appreciated

              Comment


                #8
                Suggest you take a look at this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=8600
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by PaulMohn, Today, 05:00 AM
                0 responses
                8 views
                0 likes
                Last Post PaulMohn  
                Started by ZenCortexAuCost, Today, 04:24 AM
                0 responses
                6 views
                0 likes
                Last Post ZenCortexAuCost  
                Started by ZenCortexAuCost, Today, 04:22 AM
                0 responses
                3 views
                0 likes
                Last Post ZenCortexAuCost  
                Started by SantoshXX, Today, 03:09 AM
                0 responses
                16 views
                0 likes
                Last Post SantoshXX  
                Started by DanielTynera, Today, 01:14 AM
                0 responses
                5 views
                0 likes
                Last Post DanielTynera  
                Working...
                X