{
public class StochRSIStrategy : Strategy
{
private StochRSI StochRSI1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Buy and Sell based on Stochastic RSI";
Name = "StochRSIStrategy";
Calculate = Calculate.OnEachTick;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = false;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Day;
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;
Buy_Stoch_RSI = 0.5;
Sell_Stoch_RSI = 0.8;
}
else if (State == State.Configure)
{
AddDataSeries("ES 12-22", Data.BarsPeriodType.Minute, 3, Data.MarketDataType.Last);
}
else if (State == State.DataLoaded)
{
StochRSI1 = StochRSI(Closes[1], 14);
SetProfitTarget(@"4", CalculationMode.Ticks, 0);
SetStopLoss(@"12", CalculationMode.Ticks, 0, false);
SetTrailStop(@"2", CalculationMode.Ticks, 0, false);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1
|| CurrentBars[1] < 1)
return;
// Set 1
if (CrossAbove(StochRSI1, Buy_Stoch_RSI, 1))
{
EnterLong(3, @"");
}
// Set 2
if (CrossBelow(StochRSI1, Sell_Stoch_RSI, 1))
{
EnterShort(3, "");
}
}
region Properties
[NinjaScriptProperty]
[Range(0.5, double.MaxValue)]
[Display(Name="Buy_Stoch_RSI", Order=1, GroupName="Parameters")]
public double Buy_Stoch_RSI
{ get; set; }
[NinjaScriptProperty]
[Range(0.8, double.MaxValue)]
[Display(Name="Sell_Stoch_RSI", Order=2, GroupName="Parameters")]
public double Sell_Stoch_RSI
{ get; set; }
#endregion
}
}
Comment