Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This namespace holds Strategies in this folder and is required. Do not change it.
- namespace NinjaTrader.NinjaScript.Strategies
- {
- public class MyCustomStrategy : Strategy
- {
- private NinjaTrader.NinjaScript.Indicators.LizardIndicators.amaCurrentDayVWAP amaCurrentDayVWAP1;
- private NinjaTrader.NinjaScript.Indicators.LizardIndicators.amaCurrentDayVWAP amaCurrentDayVWAP2;
- protected override void OnStateChange()
- {
- if (State == State.SetDefaults)
- {
- Description = @"Enter the description for your new custom Strategy here.";
- Name = "MyCustomStrategy";
- Calculate = Calculate.OnEachTick;
- EntriesPerDirection = 3;
- EntryHandling = EntryHandling.AllEntries;
- IsExitOnSessionCloseStrategy = false;
- ExitOnSessionCloseSeconds = 300;
- IsFillLimitOnTouch = true;
- MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
- OrderFillResolution = OrderFillResolution.Standard;
- Slippage = 0;
- StartBehavior = StartBehavior.WaitUntilFlat;
- TimeInForce = TimeInForce.Day;
- TraceOrders = true;
- RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
- StopTargetHandling = StopTargetHandling.ByStrategyPosition;
- BarsRequiredToTrade = 0;
- // 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("FDAX 09-19", Data.BarsPeriodType.Minute, 5, Data.MarketDataType.Last);
- }
- else if (State == State.DataLoaded)
- {
- amaCurrentDayVWAP1 = amaCurrentDayVWAP(Close, amaSessionTypeVWAPD.Full_Session, amaBandTypeVWAPD.Standard_Deviation, amaTimeZonesVWAPD.Chart_Time, @"08:30", @"15:15", 1, 2, 3, 1, 2, 3);
- amaCurrentDayVWAP2 = amaCurrentDayVWAP(Close, amaSessionTypeVWAPD.Full_Session, amaBandTypeVWAPD.Standard_Deviation, amaTimeZonesVWAPD.Exchange_Time, @"08:30", @"15:15", 1, 2, 3, 1, 2, 3);
- amaCurrentDayVWAP1.Plots[0].Brush = Brushes.Gray;
- amaCurrentDayVWAP1.Plots[1].Brush = Brushes.Gray;
- amaCurrentDayVWAP1.Plots[2].Brush = Brushes.Gray;
- amaCurrentDayVWAP1.Plots[3].Brush = Brushes.Gray;
- amaCurrentDayVWAP1.Plots[4].Brush = Brushes.Gray;
- amaCurrentDayVWAP1.Plots[5].Brush = Brushes.Gray;
- amaCurrentDayVWAP1.Plots[6].Brush = Brushes.Gray;
- AddChartIndicator(amaCurrentDayVWAP1);
- SetStopLoss(CalculationMode.Ticks, 100);
- }
- }
- protected override void OnBarUpdate()
- {
- if (BarsInProgress != 0)
- return;
- if (CurrentBars[0] < 20)
- return;
- // Set 1
- if ((Close[0] <= amaCurrentDayVWAP1.LowerBand3[20])
- && (Times[0][0].TimeOfDay >= new TimeSpan(10, 0, 0))
- && (Times[0][0].TimeOfDay <= new TimeSpan(17, 30, 0)))
- {
- EnterLong(Convert.ToInt32(DefaultQuantity), "");
- }
- // Set 2
- if (High[0] >= amaCurrentDayVWAP2.SessionVWAP[0])
- {
- ExitLong(Convert.ToInt32(DefaultQuantity), "", @"");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement