Here is an idea of the code.
namespace NinjaTrader.NinjaScript.Strategies
{
public class BuilderTemplateCode : Strategy
{
private ADX ADX1;
private ADX ADX2;
private ADX ADX3;
private ADX ADX4;
private RSI RSI1;
private RSI RSI2;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "BuilderTemplateCode";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 300;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 1;
IncludeCommission = true;
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;
Input1 = 0;
Input2 = 0;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
SetProfitTarget("", CalculationMode.Ticks, 30);
ADX2 = ADX(Close, 10);
ADX3 = ADX(Close, 15);
ADX4 = ADX(Close, 20);
RSI1 = RSI(Close, 15, 3);
RSI2 = RSI(Close, 12, 3);
}
}
protected override void OnBarUpdate()
{
return;
if (CurrentBars[0] < 5)
return;
var f1 = (ADX1[0] > 30);
var f2 = (ADX2[0] > 45);
var f3 = (RSI1[0] > 80);
var f4 = (RSI1[0] < 20);
if (
&& (Close[1] > Close[2])
{
EnterLong(Convert.ToInt32(DefaultQuantity), "");
}
if (
&& (Close[1] < Close[2])
)
{
EnterShort(Convert.ToInt32(DefaultQuantity), "");
}
}
region Properties
[NinjaScriptProperty]
[Range(-200, int.MaxValue)]
[Display(Name="Input1", Order=1, GroupName="Parameters")]
public int Input1
{ get; set; }
[NinjaScriptProperty]
[Range(-200, int.MaxValue)]
[Display(Name="Input2", Order=2, GroupName="Parameters")]
public int Input2
{ get; set; }
#endregion
}
}
Comment