/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { ast = anaSuperTrend(1, 3, 3); dc = DonchianChannel(20); hma = HMA(30); // Open Secret Sauce Long if (isFlat() && enableLong //&& Close[0] <= ast.StopLine[0] && ast.UpTrend[0] && !ast.UpTrend[1] //&& ((dc.Upper[0] - dc.Lower[0])/TickSize >= 12) && Rising(hma) //&& (BarsSinceExit() > 5 || BarsSinceExit() == -1) ) { EnterLong(DefaultQuantity); //EnterLongLimit(DefaultQuantity, ast.StopLine[0]); } // Open Secret Sauce Short if (isFlat() && enableShort ) { EnterShort(DefaultQuantity); } AtmStrategyHandler(); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { ast = anaSuperTrend(AtrMultiplier, AtrPeriod, MedianPeriod); //if (ast.StopLine[0] == High[0]) // Switch to uptrend if (ast.UpTrend[0] && !ast.UpTrend[1]) { //DrawArrowUp("My up arrow" + CurrentBar, false, 0, ast.StopLine[0] - 10 * TickSize, Color.Lime); if (previousLow > 0) { double bottom = Low[LowestBar(Low, CurrentBar - previousLow)]; DrawDot("My up dot" + CurrentBar, false, 0, bottom, Color.Black); channelLow = Math.Min(Low[LowestBar(Low, CurrentBar - previousLow)], Low[LowestBar(Low, CurrentBar - currentLow)]); DrawLine("Bottom line" + CurrentBar, 0, channelLow, -10, channelLow, Color.DarkRed); enableLong = true; } previousLow = currentLow; currentLow = CurrentBar; //double top = High[HighestBar(High, CurrentBar - previousHigh)]; //DrawDot("My up dot" + CurrentBar, false, 0, top, Color.White); //channelHigh = Math.Max(High[HighestBar(High, CurrentBar - previousHigh)], High[HighestBar(High, CurrentBar - currentHigh)]); //DrawLine("Top line" + CurrentBar, 0, channelHigh, -10, channelHigh, Color.DarkBlue); //previousHigh = currentHigh; //currentHigh = CurrentBar; } // Switch to downtrend if (!ast.UpTrend[0] && ast.UpTrend[1]) { //DrawArrowLine("My down line" + CurrentBar, 5, ast.StopLine[0] + 10 * TickSize, 0, ast.StopLine[0] + 5 * TickSize, Color.Cyan); //DrawArrowDown("My down arrow" + CurrentBar, false, 0, ast.StopLine[0] + 10 * TickSize, Color.Lime); if (previousHigh > 0) { double top = High[HighestBar(High, CurrentBar - previousHigh)]; DrawDot("My up dot" + CurrentBar, false, 0, top, Color.White); channelHigh = Math.Max(High[HighestBar(High, CurrentBar - previousHigh)], High[HighestBar(High, CurrentBar - currentHigh)]); DrawLine("Top line" + CurrentBar, 0, channelHigh, -10, channelHigh, Color.DarkBlue); enableShort = true; } previousHigh = currentHigh; currentHigh = CurrentBar; // double bottom = Low[LowestBar(Low, CurrentBar - previousLow)]; // DrawDot("My down dot" + CurrentBar, false, 0, bottom, Color.Black); // channelLow = Math.Min(Low[LowestBar(Low, CurrentBar - previousLow)], Low[LowestBar(Low, CurrentBar - currentLow)]); // DrawLine("Bottom line" + CurrentBar, 0, channelLow, -10, channelLow, Color.DarkRed); //previousLow = currentLow; //currentLow = CurrentBar; } if (Position.MarketPosition == MarketPosition.Short && Close[0] > channelHigh) { //ExitShort(""); } if (Position.MarketPosition == MarketPosition.Long && Close[0] < channelLow) { ExitLong(""); } //SetTrailStop(CalculationMode.Ticks, 20); //SetTrailStop(CalculationMode.Price, (channelHigh - channelLow) * TickSize); if (Position.MarketPosition == MarketPosition.Flat) { if (enableLong && Close[0] > channelHigh && (channelHigh - channelLow) < 2) { EnterLong(""); enableLong = false; //SetTrailStop("", CalculationMode.Ticks, (channelHigh - channelLow) / TickSize, false); SetProfitTarget("", CalculationMode.Ticks, (channelHigh - channelLow) / TickSize); SetStopLoss(CalculationMode.Ticks, (channelHigh - channelLow) / TickSize); //Print(Time + " channelHigh: " + channelHigh + " Channel Width: " + (channelHigh - channelLow)); } if (enableShort && Close[0] < channelLow && (channelHigh - channelLow) < 2) { EnterShort(""); enableShort = false; SetProfitTarget("", CalculationMode.Ticks, (channelHigh - channelLow) / TickSize); SetStopLoss(CalculationMode.Price, channelHigh); DrawDot("My stop" + CurrentBar, false, 0, channelHigh, Color.Red); //Print(Time + " channelLow: " + channelLow + " Channel Width: " + (channelHigh - channelLow)); } } }