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 per Day

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

    Max trades per Day

    I need to implement max limit per day in NT8
    I have the next code in NT8 that trade well in backtesting, but not in Real time or marker repaly.
    can someone help me?
    (i attached the script below)

    thanks

    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class TPD : Strategy
    {

    private int profitTargetTicks = 15;
    private int stopLossTicks = 10;
    private int trades_till_today = 0;
    private SMA SMA1;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"trade per day Limit (one session per day)";
    Name = "TPD";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    IsInstantiatedOnEachOptimizationIteration = true;

    _cntrcts = 1;
    _MaxEntriesDay = 2;

    }

    else if (State == State.Configure)
    {
    SetStopLoss(CalculationMode.Ticks, stopLossTicks);
    SetProfitTarget(CalculationMode.Ticks, profitTargetTicks);

    }

    else if (State == State.DataLoaded)
    {
    SMA1 = SMA(10);
    }

    }

    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequiredToTrade) return;

    if (CurrentBars[0] < 1)
    return;
    if ( Bars.IsFirstBarOfSession )
    {
    trades_till_today = SystemPerformance.AllTrades.Count;
    }

    int trades_today = SystemPerformance.AllTrades.Count - trades_till_today + (Position.MarketPosition != MarketPosition.Flat ? 1 : 0);
    if (trades_today < _MaxEntriesDay)

    {

    // Set 1
    if (Close[0] > (SMA1[0] ))

    {
    EnterLong(Convert.ToInt32(_cntrcts), "");
    }

    // Set 2
    if (Close[0] < (SMA1[0]))

    {
    EnterShort(Convert.ToInt32(_cntrcts), "");
    }

    }

    }

    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(ResourceType = typeof(Custom.Resource), Name="_cntrcts", Description="cntrcts", Order=1, GroupName="NinjaScriptStrategyParameters")]
    public int _cntrcts
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(ResourceType = typeof(Custom.Resource), Name="_MaxEntriesDay", Description="_MaxEntriesDay ", Order=2, GroupName="NinjaScriptStrategyParameters")]
    public int _MaxEntriesDay
    { get; set; }


    [Range(0, int.MaxValue)]
    [NinjaScriptProperty]
    [Display(Name="Profit Target Ticks", Description="Number of ticks away from entry price for the Profit Target order", Order=3, GroupName="Parameters")]
    public int ProfitTargetTicks
    {
    get { return profitTargetTicks; }
    set { profitTargetTicks = value; }
    }

    [Range(0, int.MaxValue)]
    [NinjaScriptProperty]
    [Display(Name="Stop Loss Ticks", Description="Numbers of ticks away from entry price for the Stop Loss order", Order=4, GroupName="Parameters")]
    public int StopLossTicks
    {
    get { return stopLossTicks; }
    set { stopLossTicks = value; }
    }


    #endregion

    }
    }

    #2
    Hello Handel,

    In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients.

    I would suggest adding print statements to check whether your conditions are becoming true. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


    I’ve provided a link covering debugging which you may find helpful.
    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

    You can also contact a professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Trades per day

      Thanks for your reply.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Waxavi, Today, 02:10 AM
      1 response
      16 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by Kaledus, Today, 01:29 PM
      5 responses
      13 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by Waxavi, Today, 02:00 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by alifarahani, Today, 09:40 AM
      5 responses
      23 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by gentlebenthebear, Today, 01:30 AM
      3 responses
      17 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X