ninjatrader/strategies/VWAPTrendBot.cs

59 lines
1.9 KiB
C#
Raw Normal View History

2024-06-28 21:00:24 +00:00
#region Using declarations
using NinjaTrader.Cbi;
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 VWAPTrendBot : Strategy
{
private VWAP vwap;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Long Above VWAP / Short Below VWAP";
Name = "VWAP Trend 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.DataLoaded)
{
vwap = VWAP();
}
}
protected override void OnBarUpdate()
{
if (CurrentBar < BarsRequiredToTrade)
return;
if (Close[0] > vwap[0])
EnterLong();
else if (Close[0] < vwap[0])
EnterShort();
}
public override string DisplayName
{
get { return Name; }
}
}
}