Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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
can someone help me?
thanks
private int trades_till_today = 0;
private int _MaxEntriesDay = 2;
protected override void OnBarUpdate()
{
if ( Bars.IsFirstBarOfSession )
{
trades_till_today = SystemPerformance.AllTrades.Count;
}
I attached below complete code
it work well in backtesting with any intrument (i try ZN)
I trade one sesión per day
but, in realtime or market replay, the limit of trades per day, donīt work.
#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;
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; }
}
I suggest you output some of those values with a Print statement, when you run it in real-time
and then you will see what values are returned and where the logic flows...
Sorry for my inexperience rleplae,
I conect Ninjascript output at same time that run market replay and.... any mesages any errors
(only definition of parameters ..." ennabling Ninjascript strategy TPD: On starting a real time strategy.......
Then you can add other Print statements to make sure you are editing the right file.
If you have your output window open, you should at least see something