• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:
    https://www.youtube.com/watch?v=K8v_...tu.be&t=48m45s

    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 scfnkysx, Today, 12:30 AM
      0 responses
      4 views
      0 likes
      Last Post scfnkysx  
      Started by jimloforkocv, Today, 12:16 AM
      0 responses
      4 views
      0 likes
      Last Post jimloforkocv  
      Started by claxxical, Yesterday, 10:00 PM
      0 responses
      8 views
      0 likes
      Last Post claxxical  
      Started by ct, Yesterday, 08:13 PM
      0 responses
      8 views
      0 likes
      Last Post ct
      by ct
       
      Started by Lumbeezl, Yesterday, 05:17 PM
      0 responses
      7 views
      0 likes
      Last Post Lumbeezl  
      Working...
      X