namespace NinjaTrader.NinjaScript.Strategies
{
public class reversion : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "reversion";
Calculate = Calculate.OnEachTick;
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;
//ProfitTarget = 3;
//StopLoss = 1.50;
//EnterRule = 1.25;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries("MES", Data.BarsPeriodType.Minute, 3, Data.MarketDataType.Last);
}
else if (State == State.DataLoaded)
{
}
}
protected override void OnBarUpdate()
{
double MovAvgValue = SMA(Close, 3)[0];
double barOpen = Bars.GetOpen(0);
double getCurrentBar = Bars.GetBid(0);
//double _ProfitTarget = 3;
//double _StopLoss = 1.50;
//double _EnterRule = 1;
if (BarsInProgress != 0) return;
if (Position.MarketPosition == MarketPosition.Flat){
if((barOpen- MovAvgValue) >= _EnterRule && barOpen> MovAvgValue && getCurrentBar > MovAvgValue){
//Print("The current Enter Rule value is " + average.ToString());
EnterShort(1);
SetProfitTarget(CalculationMode.Ticks, 10 );
SetStopLoss(CalculationMode.Ticks,5);
} else
if(barOpen < MovAvgValue && (MovAvgValue - barOpen) >= _EnterRule && getCurrentBar < MovAvgValue){
EnterLong(1);
SetProfitTarget(CalculationMode.Ticks, 10 );
SetStopLoss(CalculationMode.Ticks,5);
}
}
//Add your custom strategy logic here.
}
private void EnterLong(){
//not using
}
private void EnterShort(){
//not using
}
}
}
Comment