Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

only one Trade per day

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

    only one Trade per day

    Please help me. Please excuse my bad english. my script should only trade one time per day. I read any topics but i don´t find a solution. Here ist my code can anyone help me ? i Trade 2-3 Time per day. Every signal will be trade, not the first one

    Code:
    // 
    // Copyright (C) 2007, NinjaTrader LLC <www.ninjatrader.com>.
    // 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 Rangebreakout : Strategy
        {
            #region Variables
        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()
            {
                SetStopLoss("", CalculationMode.Ticks, 40, false);
                SetProfitTarget("", CalculationMode.Ticks, 30);
    
                CalculateOnBarClose = true;
            }
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
       // Resets at the start of every new session
        //if (Bars.FirstBarOfSession && FirstTickOfBar)
        if((Time[0].TimeOfDay >= DateTime.Parse("8:00").TimeOfDay) && (Time[0].TimeOfDay <= DateTime.Parse("18:00").TimeOfDay))
        {
            tradeCounter = 0;
        }
    
        if (tradeCounter < 1)
        {
         EnterLongStop(.........);
         tradeCounter++;
         EnterShortStop(........);
         tradeCounter++;
         
        }
       
       
              
            }
        }
    }

    #2
    thunderbolt, if you want to trade just once per day you can use a bool variable:
    Code:
    // in variables section
    private bool canTrade = true;
    
    OnBarUpdate()
    {
    if (SessionBreak)
        canTrade = true;
    
    if (long trade conditions are met)
    {
        canTrade = false;
        EnterLong(...);
    }
    
    if (short conditions are met)
    {
        canTrade = false;
        enterShort(...);
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      thank you very much

      i use the 5 min chart to get signal

      tried this but this setting, bu it trades all Signals in the range of 8-18 o clock

      Code:
      // 
      // Copyright (C) 2007, NinjaTrader LLC <www.ninjatrader.com>.
      // 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 Rangebreakout : Strategy
          {
              #region Variables
                private int tradeCounter = 0;
              private bool canTrade = true;
      
                
              #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()
              {
                  SetStopLoss("", CalculationMode.Ticks, 40, false);
                  SetProfitTarget("", CalculationMode.Ticks, 30);
      
                  CalculateOnBarClose = true;
              }
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
          // Resets at the start of every new session
          //if (Bars.FirstBarOfSession && FirstTickOfBar)
              {
              if (Bars.SessionBreak)
                  canTrade = true;
              
              if ((Time[0].TimeOfDay >= DateTime.Parse("8:00").TimeOfDay) && (Time[0].TimeOfDay <= DateTime.Parse("18:00").TimeOfDay))
              {
              canTrade = false;
              EnterLongStop(DefaultQuantity, SampleGetHighLowByTimeRange(7, 59, 4, 59).HighestHigh[0] + 1 * TickSize, "");
              }
         
              }
                
              }
          }
      }
      Is there a way to count the trades ? is there an error in my code below ?

      Code:
      // 
      // Copyright (C) 2007, NinjaTrader LLC <www.ninjatrader.com>.
      // 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 Rangebreakout : Strategy
          {
              #region Variables
                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()
              {
                  SetStopLoss("", CalculationMode.Ticks, 40, false);
                  SetProfitTarget("", CalculationMode.Ticks, 30);
      
                  CalculateOnBarClose = true;
              }
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
          // Resets at the start of every new session
          if (Bars.SessionBreak) 
              {
              tradeCounter = 0;
              }
          if ((Time[0].TimeOfDay >= DateTime.Parse("8:00").TimeOfDay) && (Time[0].TimeOfDay <= DateTime.Parse("18:00").TimeOfDay))
          if (tradeCounter < 5)
          {
           EnterLongStop(DefaultQuantity, SampleGetHighLowByTimeRange(7, 59, 4, 59).HighestHigh[0] + 1 * TickSize, "");
           tradeCounter++;
           //EnterShortStop(lowestLow - TickSize);
           //tradeCounter++;
           
          }
         
         
                
              }
          }
      }
      the problem ist now. I i take the counter to 5 for example, the system trade only the first 5 bars after 8.00 am. if i set it to 10 the system search the first 10 bars for a signal. The System trades only one per day, thats correct but i a signal come at 3 pm the system don´t enter, because its the 151st bar, for example. i will trade the first Signal in the range between 8-18 o´clock.

      can anyone help ?
      Last edited by thunderbolt78; 02-03-2010, 02:58 AM.

      Comment


        #4
        thunderbolt78, you want to include a check to canTrade in your entry conditions as well, otherwise you just set and reset it without affect on entries taking place.

        For accessing Trade Performande data and statistics including the trade count (also for RealtimeTrades only) please work with our Performance class.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        656 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        371 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        579 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X