Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
- // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
- //
- #region Using declarations
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Xml.Serialization;
- using NinjaTrader.Cbi;
- using NinjaTrader.Gui;
- using NinjaTrader.Gui.Chart;
- using NinjaTrader.Gui.SuperDom;
- using NinjaTrader.Data;
- using NinjaTrader.NinjaScript;
- using NinjaTrader.Core.FloatingPoint;
- using NinjaTrader.NinjaScript.Indicators;
- using NinjaTrader.NinjaScript.DrawingTools;
- #endregion
- //This namespace holds strategies in this folder and is required. Do not change it.
- namespace NinjaTrader.NinjaScript.Strategies.AlanStrategies
- {
- public class Buy3with3Pts3Sl : Strategy
- {
- /*
- Written by Alan Palmer
- */
- private double xPrice1;
- private double xPrice2;
- private double xPrice3;
- private Order myEntryOrder1 = null;
- private Order myEntryOrder2 = null;
- private Order myEntryOrder3 = null;
- protected override void OnStateChange()
- {
- if (State == State.SetDefaults)
- {
- Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDescriptionSampleMACrossOver;
- Name = "Buy3with3Pts3Sl";
- EntriesPerDirection = 1;
- EntryHandling = EntryHandling.UniqueEntries;
- IsInstantiatedOnEachOptimizationIteration = false;
- }
- else if (State == State.Configure)
- {
- }
- }
- protected override void OnBarUpdate()
- {
- if(State==State.Historical) return;
- if (CurrentBar < 20) return;
- if(Close[0] != Close[5] && Position.MarketPosition == MarketPosition.Flat)
- {
- EnterLong(1, "Buy Long A");
- EnterLong(1, "Buy Long B");
- EnterLong(1, "Buy Long C");
- }
- if (Close[0] > xPrice1+3*TickSize)
- {
- ExitLongLimit(0, true, 1, xPrice1 + 4 * TickSize, "Sell 1a", "Buy Long A");
- }
- }
- protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
- {
- Print(execution.Order.Name.ToString());
- if (execution.Order.Name == "Buy Long A" && execution.Order.OrderState == OrderState.Filled)
- {
- xPrice1 = Position.AveragePrice;
- ExitLongLimit(0, true, 1, xPrice1 + 20 * TickSize, "Sell 1a", "Buy Long A");
- ExitLongStopMarket(0, true, 1, xPrice1 - 12 * TickSize, "Sell Stop A", "Buy Long A");
- }
- if (execution.Order.Name == "Buy Long B" && execution.Order.OrderState == OrderState.Filled)
- {
- xPrice2 = Position.AveragePrice;
- ExitLongLimit(0, true, 1, xPrice2 + 5 * TickSize, "Sell 1b", "Buy Long B");
- ExitLongStopMarket(0, true, 1, xPrice2 - 12 * TickSize, "Sell Stop B", "Buy Long B");
- }
- if (execution.Order.Name == "Buy Long C" && execution.Order.OrderState == OrderState.Filled)
- {
- xPrice3 = Position.AveragePrice;
- ExitLongLimit(0, true, 1, xPrice3 + 6 * TickSize, "Sell 1c", "Buy Long C");
- ExitLongStopMarket(0, true, 1, xPrice3 - 12 * TickSize, "Sell Stop C", "Buy Long C");
- }
- // xPrice1 = Position.AveragePrice;
- //ExitLongLimit(0, true, 1, xPrice+4*TickSize, "Sell 1a", "Buy Long A");
- //ExitLongLimit(0, true, 1, xPrice+5*TickSize, "Sell 1b", "Buy Long B");
- //ExitLongLimit(0, true, 1, xPrice+6*TickSize, "Sell 1c", "Buy Long C");
- //ExitLongStopMarket(0, true, 1, xPrice-12*TickSize, "Sell Stop A", "Buy Long A");
- //ExitLongStopMarket(0, true, 1, xPrice-12*TickSize, "Sell Stop B", "Buy Long B");
- //ExitLongStopMarket(0, true, 1, xPrice-12*TickSize, "Sell Stop C", "Buy Long C");
- }
- #region Properties
- // [Range(1, int.MaxValue), NinjaScriptProperty]
- // [Display(ResourceType = typeof(Custom.Resource), Name = "Fast", GroupName = "NinjaScriptStrategyParameters", Order = 0)]
- // public int Fast
- // { get; set; }
- // [Range(1, int.MaxValue), NinjaScriptProperty]
- // [Display(ResourceType = typeof(Custom.Resource), Name = "Slow", GroupName = "NinjaScriptStrategyParameters", Order = 1)]
- // public int Slow
- // { get; set; }
- #endregion
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment