I copied this strategy as seen below from a programmer on youtube...partly I liked the strategy basics, and partly to help me to learn the Strategy Builder/NinjaScript/C#. I did it twice and followed it to the T. It compiles no problem, but when I try to implement it, it doesn't take any trades?
It is a simple strategy that will watch for price to move away from a EMA for at least 4 bars and a distance of at least10 ticks...then retrace to the EMA and bounce above/below it. Could someone with a more experienced eye than me see what it is missing? Thanks in advance.
#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
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class GDEMABounce : Strategy
{
private int Counter_Long;
private int Counter_Short;
private EMA EMA1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "GDEMABounce";
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;
Target = 15;
Stop = 15;
Bars_Space = 4;
Distance_Min = 10;
MAPeriod = 17;
Counter_Long = 0;
Counter_Short = 0;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
EMA1 = EMA(Close, Convert.ToInt32(MAPeriod));
SetProfitTarget("", CalculationMode.Ticks, Target);
SetStopLoss("", CalculationMode.Ticks, Stop, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if ((High[0] + (Distance_Min)) <= EMA1[0])
{
Counter_Long = 0;
Counter_Short += 1;
}
// Set 2
if (Low[0] >= (EMA1[0] + (Distance_Min)) )
{
Counter_Long += 1;
Counter_Short = 0;
}
// Set 3
if ((Counter_Long >= Bars_Space)
&& (Low[0] < EMA1[0])
&& (Close[0] > EMA1[0]))
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
// Set 4
if ((Counter_Short >= Bars_Space)
&& (High[0] > EMA1[0])
&& (Close[0] < EMA1[0]))
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Target", Order=1, GroupName="Parameters")]
public int Target
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Stop", Order=2, GroupName="Parameters")]
public int Stop
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Bars_Space", Order=3, GroupName="Parameters")]
public int Bars_Space
{ get; set; }
[NinjaScriptProperty]
[Display(Name="Distance_Min", Order=4, GroupName="Parameters")]
public double Distance_Min
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="MAPeriod", Order=5, GroupName="Parameters")]
public int MAPeriod
{ get; set; }
#endregion
}
}
Comment