Add another opening range bot
This commit is contained in:
parent
fb506efbb7
commit
1a17b9bd95
72
strategies/OpeningRangeBot.cs
Normal file
72
strategies/OpeningRangeBot.cs
Normal file
@ -0,0 +1,72 @@
|
||||
#region Using declarations
|
||||
using NinjaTrader.Cbi;
|
||||
using NinjaTrader.Data;
|
||||
using NinjaTrader.NinjaScript.Indicators;
|
||||
#endregion
|
||||
|
||||
//This namespace holds Strategies in this folder and is required. Do not change it.
|
||||
namespace NinjaTrader.NinjaScript.Strategies
|
||||
{
|
||||
public class OpeningRangeBot : Strategy
|
||||
{
|
||||
private const int PrimaryBars = 0;
|
||||
|
||||
private OpeningRange OR;
|
||||
|
||||
protected override void OnStateChange()
|
||||
{
|
||||
if (State == State.SetDefaults)
|
||||
{
|
||||
Description = @"Strategy based on opening range breakouts";
|
||||
Name = "Opening Range Bot";
|
||||
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;
|
||||
IsInstantiatedOnEachOptimizationIteration = true;
|
||||
}
|
||||
else if (State == State.Configure)
|
||||
{
|
||||
AddDataSeries(BarsPeriodType.Minute, 1);
|
||||
AddDataSeries(Instrument.FullName, new BarsPeriod
|
||||
{ BarsPeriodType = BarsPeriodType.Minute, Value = 5 }, "US Equities RTH");
|
||||
}
|
||||
else if (State == State.DataLoaded)
|
||||
{
|
||||
OR = OpeningRange(30, OpeningRangeBarType.Minutes);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnBarUpdate()
|
||||
{
|
||||
// TODO: Make this timezone-agnostic.
|
||||
if (ToTime(Time[0]) <= 70000)
|
||||
return;
|
||||
|
||||
if (PrimaryBars != BarsInProgress)
|
||||
return;
|
||||
|
||||
if (Open[0] < OR.ORH[0] && Close[0] > OR.ORH[0])
|
||||
{
|
||||
SetStopLoss(CalculationMode.Price, Low[0]);
|
||||
EnterLong();
|
||||
}
|
||||
else if (Open[0] > OR.ORL[0] && Close[0] < OR.ORL[0])
|
||||
{
|
||||
SetStopLoss(CalculationMode.Price, High[0]);
|
||||
EnterShort();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user