What am I missing here? I want the counter to ''reset'' at market close everyday, or at ''certain'' time of the day. So that the strategy can take 2 more trades the next day, and so on...
Here i will show you the code I have so far... Please can someone give me the part of the code Im missing for this to work? Thankyou..
namespace NinjaTrader.NinjaScript.Strategies
{
public class SimpleCross : Strategy
{
double allTrades;
private EMA EMA1;
private SMA SMA1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "SimpleCross";
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;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
SMAs = 20;
EMAs = 9;
Start = DateTime.Parse("15:30", System.Globalization.CultureInfo.InvariantCulture) ;
End = DateTime.Parse("20:00", System.Globalization.CultureInfo.InvariantCulture) ;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, Convert.ToInt32(EMAs));
SMA1 = SMA(Close, Convert.ToInt32(SMAs));
SetProfitTarget(CalculationMode.Currency, 600);
SetStopLoss(CalculationMode.Currency, 300);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
double allTrades = SystemPerformance.AllTrades.TradesPerformance.Trad esPerDay;
// Set 1
if (CrossAbove(EMA1, SMA1, 1) && allTrades < 2)
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"Long");
ExitShort(Convert.ToInt32(DefaultQuantity), close, "");
allTrades ++;
}
// Set 2
if (CrossBelow(EMA1, SMA1, 1) && allTrades < 2)
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"Short");
ExitLong(Convert.ToInt32(DefaultQuantity), close, "");
allTrades ++;
}
Comment