/// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { ClearOutputWindow(); // Add a 1508 tick Bars object to the strategy // the chart bar will be BarsArray[0] and this added timeframe will be BarsArray[1] Add(PeriodType.Tick, 377); // normally this will be 1508 //Add(PeriodType.Tick, 1508); //pas = PriceActionSwing(dtbStrength, swingSize, SwingTypes.Standard); //Add(pas); //paso = PriceActionSwingOscillator(dtbStrength, swingSize, SwingTypes.Standard); //Add(paso); /// pasp = PriceActionSwingPro(dtbStrength, swingSize, SwingTypes.Standard); /// Add(pasp); //zz = ZigZagUTC(ZZ_SHOW_LINES, zzSpan, zzUseHighLow, Color.Black); //Add(zz); ichi = IchiCloud(periodFast, periodMedium, periodSlow); Add(ichi); ema = EMA(emaPeriod); Add(ema); SetProfitTarget(CalculationMode.Ticks, 22); // 22 * 12.5 = 275 SetStopLoss(CalculationMode.Ticks, 12); // 12 * 12.5 = 150 CalculateOnBarClose = true; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Ignore bar update events for the supplementary Bars object added above if (BarsInProgress == 0) { return; } /* * if (ToTime(Time[0]) < ToTime(3, 00, 0)) * return; * * if (ToTime(Time[0]) >= ToTime(8, 00, 0)) * return; */ ic = IchiCloud(BarsArray[1], periodFast, periodMedium, periodSlow); ema = EMA(BarsArray[1], 13); //zz = ZigZag(BarsArray[1], DeviationType.Points, deviationValue, useHighLow); swing = Swing(BarsArray[1], strength); //SetHigherHighsAndLowerLowers(1); if (Position.MarketPosition == MarketPosition.Long) { // check for sell trigger on a down bar if (Close[0] < Open[0]) { sellTrigger = Math.Max(sellTrigger, Low[0] - 1 * TickSize); //DrawDot(CurrentBar + "sell", false, 0, ic[0], Color.Pink); } else { double stop = Math.Max(Position.AvgPrice - stopLoss * TickSize, sellTrigger); DrawDot(CurrentBar + "stop", false, 0, stop, Color.Pink); SetStopLoss(CalculationMode.Price, stop); } if (sellTrigger < (Position.AvgPrice - stopLoss * TickSize)) { //SetStopLoss(CalculationMode.Price, sellTrigger); //DrawDot(CurrentBar + "ouch", false, 0, sellTrigger, Color.Yellow); } } //hh = High[swing.SwingHighBar(0, 1, 1000)] > High[swing.SwingHighBar(0, 2, 1000)]; //ll = Low[swing.SwingLowBar(swing.SwingHighBar(0, 1, 1000), 1, 1000)] SetSwingHighAndLows(); if ( //!newHighPending High[swing.SwingHighBar(0, 1, 500)] > High[swing.SwingHighBar(0, 2, 500)] && Low[swing.SwingLowBar(0, 1, 500)] > Low[swing.SwingLowBar(0, 2, 500)] //&& Low[swing.SwingLowBar(swing.SwingHighBar(0, 1, 500), 1, 500)] < Low[0] && High[0] > High[swing.SwingHighBar(20, 1, 500)] && (High[0] - stopLoss * TickSize < ic[0] || High[0] - stopLoss * TickSize < ema[0]) && Close[0] > ic[0] //&& hl ) { BackColor = Color.Beige; //DrawDot(CurrentBar + "ic", false, 0, ic[0], Color.Pink); if (isValidLongTrigger()) { if (Position.MarketPosition == MarketPosition.Flat) { EnterLongStop(High[0] + 1 * TickSize); // set to some real high value sellTrigger = 0; SetStopLoss(CalculationMode.Price, High[0] + 1 * TickSize - stopLoss * TickSize); DrawDot(CurrentBar + "estop", false, 0, High[0] + 1 * TickSize - stopLoss * TickSize, Color.Blue); } } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < 100) { return; } //zz = ZigZagUTC(BarsArray[0], ZZ_SHOW_LINES, zzSpan, zzUseHighLow, Color.Black); ichi = IchiCloud(BarsArray[0], periodFast, periodMedium, periodSlow); ema = EMA(BarsArray[0], emaPeriod); //paso = PriceActionSwingOscillator(BarsArray[0], dtbStrength, swingSize, SwingTypes.Standard); /// pasp = PriceActionSwingPro(BarsArray[0], dtbStrength, swingSize, SwingTypes.Standard); if (Position.MarketPosition == MarketPosition.Long) { } // check if it's being called on the primary barsArray if (BarsInProgress == 0) { //DrawText(CurrentBar.ToString(), pasp.SwingRelation[0].ToString(), 0, High[0]+1*TickSize, Color.Black); DrawText(CurrentBar + "HH", pasp.HigherHigh[0].ToString(), 0, High[0] + 8 * TickSize, Color.Black); DrawText(CurrentBar + "LH", pasp.LowerHigh[0].ToString(), 0, High[0] + 6 * TickSize, Color.DarkGreen); DrawText(CurrentBar + "HL", pasp.HigherLow[0].ToString(), 0, Low[0] - 6 * TickSize, Color.Red); DrawText(CurrentBar + "LL", pasp.LowerLow[0].ToString(), 0, Low[0] - 8 * TickSize, Color.Black); } /* * // PriceActionSwingOscillator code * switch ((int) pasp.SwingRelation[0]) { * case 2: * * break; * case 10: * DrawText(CurrentBar.ToString(), "HH", 0, High[0]+1*TickSize, Color.DarkGreen); * break; * case -10: * DrawText(CurrentBar.ToString(), "LL", 0, Low[0]-1*TickSize, Color.Red); * break; * case -2: * * break; * default: * * break; * } */ // ZigZagUTC Code // Print(Time + " zz.Hi " + zz.Hi[0] + " zz.Lo " + zz.Lo[0] + " zz.ZigZagDot[0] " + zz.ZigZagDot[0]); // DrawDot(CurrentBar + "hi", true, 0, zz.Hi[0], Color.Blue); // DrawDot(CurrentBar + "dot", true, 0, zz.ZigZagDot[0], Color.Cyan); // DrawDot(CurrentBar + "lo", true, 0, zz.Lo[0], Color.Yellow); // PriceActionSwing code //pas.HigherHigh //pas.HigherLow //pas.LowerLow //pas.LowerHigh //pas.DoubleBottom //pas.DoubleTop //Print(Time + " HigherHigh: " + pas.HigherHigh[0] + " HigherLow: " + pas.HigherLow[0]); //DrawDot(CurrentBar + "HH", true, 0, pas.HigherHigh[0], Color.Green); //DrawDot(CurrentBar + "HL", true, 0, pas.HigherLow[0], Color.LightGreen); //DrawDot(CurrentBar + "HHx", true, 1, pas.HigherHigh[1]+0 * TickSize, Color.Blue); //DrawDot(CurrentBar + "HLx", true, 1, pas.HigherLow[1]-0 * TickSize, Color.LightGreen); // if (CurrentBar % 10 == 0) // for (int i = 0; i < 5; i++) // { // DrawDot(CurrentBar + "HH" + i, true, i, pas.HigherHigh[i], Color.Purple); // } }