Sunteți pe pagina 1din 4

#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.

Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Gui.Chart; using NinjaTrader.Strategy; #endregion // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// <summary> /// Base test for Daily chart. Reference strategy. /// </summary> [Description("Base test for Daily chart. Reference strategy.")] public class PurePa : Strategy { #region Variables

#endregion /// <summary> /// This method is used to configure the strategy and is called once bef ore any strategy method is called. /// </summary> protected override void Initialize() { // #region Set Properties // Set // ================================ EntryStartTime = new TimeSpan(16, 30, 0); EntryStopTime = new TimeSpan(19, 00, 00); GoLong = true; GoShort = false; MaxEntriesPerDay = 1; Reverse = false; Slippage = 0; // Set Indicators // ================================ CciPeriod = 0; //21 EmaPeriod = 0; // 13, 21, 34, 55, 89, 144, 233, 377, 61 0, 987 // Set PL // ================================

// Set Entry // ================================ StopAmt = 0; TargetAmt= 0; EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; // Unique = > per entry "name" // Set Exit // ================================ ExitOnClose = true; Exit_HLoyStop = true; // Other // ================================ // #endregion //Add(PriorDayOHLC CalculateOnBarClose = true; //Must be last statement in Initialize } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() //Triggers just before bar close? { IfOnNewSession(); HandlePosition(); CheckLod(); if( !IsOutsideEntryExitTimes()) return; //Note (!) we tr ade outside only. if( ExceededMaxEntries()) return; // Entries Print(Time[0].ToString() +" " + LowerHi + " " + IsCurren tBarNewLod + " " + GoLong); if( LowerHi && IsCurrentBarNewLod && GoLong) { //Trigger on many bars, but only executes if sto p order hit. EnterLongIfBarBreakout(); }

} protected override void OnPositionUpdate(IPosition p) { //But what if partial fills? if(p.MarketPosition != MarketPosition.Flat) entriesToday +=1; return;

} protected override void OnExecution (IExecution e) { return; } protected void EnterLongIfBarBreakout() { //Print(Time[0] + " E#: " + entriesToday); // entriesToday +=1; //only if it is filled. if (Reverse) EnterShortLimit (h0, "en"); //Reverse else EnterLongStop(h0 + 1 * TickSize, "en"); } private void HandlePosition() { if (Position.MarketPosition == MarketPosition.Flat) return; Print("LOY/LOD: " + LOY + " " + lod); if (Exit_HLoyStop && IsLong) ExitLongStop( lod - 5 * TickSize, "en"); if (Exit_HLoyStop && IsShort) ExitShortStop( HOY + 2 * TickSize, "en"); if (Position.MarketPosition == MarketPosition.Long) { if (TargetAmt != 0) SetProfitTarget ("en", CalculationMode.T icks, TargetAmt/Instrument.MasterInstrument.PointValue); if (StopAmt != 0) SetStopLoss(StopAmt, true); if (CciTarget != 0) if(CCI(Bars, CciPeriod).Value[0] > CciTa rget) ExitLong(); } } protected bool IsOutsideEntryExitTimes() { if( Time[0].TimeOfDay.TotalSeconds < EntryStartTime.Tot alSeconds ) return true; if( Time[0].TimeOfDay.TotalSeconds > EntryStopTime.Total Seconds ) return true; return false; } protected bool ExceededMaxEntries() { return entriesToday > MaxE ntriesPerDay;} protected void CheckLod() {

IsCurrentBarNewLod = false; if(Low[0] < lod) { lod = Low[0]; IsCurrentBarNewLod = true; } } private void IfOnNewSession() { if ( Time[1].Date == Time[0].Date) return; //CancelAllOrders(true, true); lod = Low[0]; //lodGapMax = 0; //since lod //lodGapTot = 0; entriesToday = 0; //Print(Time[1].Date + " " + Time[0].Date); } } }

S-ar putea să vă placă și