//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class E1RgaussZ : Strategy
{
private ZLEMA ZLEMA1;
private RGaussianFilter RGaussianFilter1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "E1RgaussZ";
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;
Zlema_period = 8;
RGauss_period = 34;
TrailStop_value = 16;
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Tick, 1);
AddDataSeries(Data.BarsPeriodType.Day, 1);
}
else if (State == State.DataLoaded)
{
ZLEMA1 = ZLEMA(Close, Convert.ToInt32(Zlema_period));
RGaussianFilter1 = RGaussianFilter(Close, 3, Convert.ToInt32(RGauss_period));
ZLEMA1.Plots[0].Brush = Brushes.Red;
RGaussianFilter1.Plots[0].Brush = Brushes.Blue;
AddChartIndicator(ZLEMA1);
AddChartIndicator(RGaussianFilter1);
SetTrailStop("", CalculationMode.Ticks, TrailStop_value, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
// Set 1
if (ZLEMA1[0] > RGaussianFilter1[0])
{
EnterLong(Convert.ToInt32(DefaultQuantity), @"Long671");
}
// Set 2
if (ZLEMA1[0] < RGaussianFilter1[0])
{
EnterShort(Convert.ToInt32(DefaultQuantity), @"Short671");
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Zlema_period", Order=1, GroupName="Parameters")]
public int Zlema_period
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="RGauss_period", Order=2, GroupName="Parameters")]
public int RGauss_period
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="TrailStop_value", Order=3, GroupName="Parameters")]
public int TrailStop_value
{ get; set; }
#endregion
}
}
Comment