/// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { // re-trigger on each tick - may not be required with unmanaged order entry, yet to be determined CalculateOnBarClose = false; // Use Unmanaged order methods Unmanaged = true; // Triggers the exit on close function 60 min prior to session end // Note: This property is a real-time only property. ExitOnClose = true; ExitOnCloseSeconds = 3600; // 60 min before session close TimeInForce = Cbi.TimeInForce.Day; //Add(ATR(period)); //ATR(period).Plots[0].Pen.Color = Color.DarkGreen; ma = HMA(MaPeriod); Add(ma); // Add(Stochastics(stocD, stocK, stocS)); // Stochastics(stocD, stocK, stocS).Plots[0].Pen.Color = Color.Blue; // D color // Stochastics(stocD, stocK, stocS).Plots[0].Pen.Width = 2; // Stochastics(stocD, stocK, stocS).Lines[0].Pen.Color = Color.Black; // Lower // Stochastics(stocD, stocK, stocS).Lines[0].Pen.DashStyle = DashStyle.Dot; // Stochastics(stocD, stocK, stocS).Lines[0].Pen.Width = 2; // Stochastics(stocD, stocK, stocS).Plots[1].Pen.Color = Color.Black; // K color // Stochastics(stocD, stocK, stocS).Lines[1].Pen.Color = Color.Black; // Upper // Stochastics(stocD, stocK, stocS).Lines[1].Pen.DashStyle = DashStyle.Dot; // Stochastics(stocD, stocK, stocS).Lines[1].Pen.Width = 2; // ClearOutputWindow(); TraceOrders = enableTraceOrders; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { HMA hma = HMA(hullPeriod); Sharkchop_v01_1 sc = Sharkchop_v01_1(13, 1, 1, 16); _ADXVMA_Alerts_v01_5_1 adx = _ADXVMA_Alerts_v01_5_1(adxPeriod, conservativeMode); //EMA ema = EMA(20); ManageOrder(); if (Position.MarketPosition != MarketPosition.Flat) { return; } if (Rising(hma) && adx.Signal[0] == RISING && MAX(sc.Long, Math.Min(Bars.BarsSinceSession, sharkyChopLookBack))[0] >= sharkyChopTrigger && sc.Long[0] > sc.Long[1] ) { GoLong(); } else if (Falling(hma) && adx.Signal[0] == FALLING && MAX(sc.Short, Math.Min(Bars.BarsSinceSession, sharkyChopLookBack))[0] >= sharkyChopTrigger && sc.Short[0] > sc.Short[1] ) { GoShort(); } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { EntryHandling = EntryHandling.UniqueEntries; myTickSize = TickSize * 10; SMA smav = SMA(SMAlength); EMA emav = EMA(EMAlength); HMA hmav = HMA(HMAlength); ManageOrders(); if (Position.MarketPosition != MarketPosition.Flat) { return; } if (Rising(smav) && Rising(emav) && Rising(hmav)) { GoLong(); } else if (Falling(smav) && Falling(emav) && Falling(hmav)) { GoShort(); } }
/// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { //this.HallMaColored SetProfitTarget(CalculationMode.Ticks, iparm1); SetStopLoss(CalculationMode.Ticks, iparm1); //SetTrailStop("", CalculationMode.Percent, dparm2, false); smaLow = HMA(Low, period1); smaHigh = HMA(High, period1); //Add(smaLow); //Add(smaHigh); smaHigh.Displacement = 0; smaLow.Displacement = 0; hallMa = HallMaColored(Typical, period1); //hallMaFast = HallMaColored(Low, period2); Add(hallMa); //Add(hallMaFast); dc = DonchianChannel(period2); Add(dc); CalculateOnBarClose = true; ExitOnClose = true; IncludeCommission = false; }
/// <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(); }
protected override void OnStart() { DragonID = "Golden Dragon " + DragonNumber + " - " + Symbol.Code; Positions.Closed += PositionsOnClosed; BuyVolume = TradeVolume; OpeningBalance = Account.Balance; MaxLong = MaxLongTrades; MaxShort = MaxShortTrades; cog1 = Indicators.GetIndicator <BelkhayatePRC>(cogDegree, cog1Periods, Inner, Middle, Outer); if (cog2Periods > 0) { cog2 = Indicators.GetIndicator <BelkhayatePRC>(cogDegree, cog2Periods, Inner, Middle, Outer); } if (cog3Periods > 0) { cog3 = Indicators.GetIndicator <BelkhayatePRC>(cogDegree, cog3Periods, Inner, Middle, Outer); } if (BelkhayateTimingFilter) { timing = Indicators.GetIndicator <BelkhayateTiming>(); } if (HullFilter) { hull = Indicators.GetIndicator <HMA>(HullPeriod); } // Identify existing trades from this instance foreach (var position in Positions) { if (position.Label == DragonID) { switch (position.TradeType) { case TradeType.Buy: LongPositions++; break; case TradeType.Sell: ShortPositions++; break; } } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { atr = ATRTrailing(atrTimes, atrPeriod, atrRatched); hmaFast = HMA(hmaFastPeriod); hmaMed = HMA(hmaMedPeriod); hmaSlow = HMA(hmaSlowPeriod); //adx = ADXVMA(hmaFastPeriod); if (Bars.FirstBarOfSession) { lastTrade = NUTRAL; } if (Position.MarketPosition != MarketPosition.Flat) { //ManageTrade(); AtmStrategyHandler(); return; } //resetLastTrade(); //DrawDot(CurrentBar + "adx", false, 0, adx.ADXVMAPlot[0], Color.Black); if (Close[0] > Close[1] && Close[1] > Close[2] && Close[2] > Close[3] //&& lastTrade != LONG && Rising(hmaSlow) && (BarsSinceExit() > 4 || BarsSinceExit() == -1) // && Close[1] < adx.ADXVMAPlot[0] ) { //Print(Time + " - Slope: " + Slope(adx.ADXVMAPlot, 1, 0)); GoLong(); } else if (Close[0] < Close[1] && Close[1] < Close[2] && Close[2] < Close[3] //&& lastTrade != SHORT && Falling(hmaSlow) && (BarsSinceExit() > 4 || BarsSinceExit() == -1) // && Close[1] > adx.ADXVMAPlot[0] ) { GoShort(); } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { hmaFast = HMA(75); hmaSlow = HMA(1050); if (Position.MarketPosition == MarketPosition.Flat) { if (Rising(hmaSlow) && CrossAbove(hmaFast, hmaSlow, 1) && Rising(hmaFast) && High[0] > hmaSlow[0] ) { EnterLong(); } } AtmStrategyHandler(); }
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "Plot Higher Time Frame indicator"; } else if (State == State.Configure) { AddDataSeries(BarsPeriodType.Minute, 60); AddPlot(Brushes.Green, "HMA1"); AddPlot(Brushes.Red, "HMA2"); } else if (State == State.DataLoaded) { myHMA = HMA(Closes[1], 14); myHMA2 = HMA(Closes[1], 30); } }
protected override void OnStart() { DragonID = "Golden Dragon " + Symbol.Code + "-" + DragonNumber; Count = BuyWait; BuyVolume = OpeningLotSize; Quantity = BuyVolume; OpeningBalance = Account.Balance; MaxLong = MaxLongTrades; MaxShort = MaxShortTrades; cog = Indicators.GetIndicator <BelkhayatePRC>(cogDegree, cogPeriod, Inner, Middle, Outer); hull = Indicators.GetIndicator <HMA>(HullPeriod); if (atr1Period > 0 && atr2Period > 0) { atr1 = Indicators.AverageTrueRange(atr1Period, atr1Type); atr2 = Indicators.AverageTrueRange(atr2Period, atr2Type); } Message(0, "Dragon awakening..."); foreach (var position in Account.Positions) { if (position.Label == DragonID) { BotBalance += position.GrossProfit; switch (position.TradeType) { case TradeType.Buy: LongPositions++; break; case TradeType.Sell: ShortPositions++; break; } } } if (LongPositions > 0 || ShortPositions > 0) { Message(0, "Found " + LongPositions + " half-eaten eagle(s) and " + ShortPositions + " rotting sheep"); } else { Message(0, "No open trades found"); } ChartRefresh(); filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), DragonID + ".txt"); if (MartingaleEnabled && File.Exists(filePath)) { _fileReader = File.OpenText(filePath); MartingaleActive = Int32.Parse(_fileReader.ReadLine()); Message(0, "Martingale Level : " + MartingaleActive); _fileReader.Close(); } }
public HmaStrategy(string symbol, string strTimeInterval, int period, string applied, decimal quantity, BinanceApiClient client, Order last = null) { m_Symbol = symbol; m_TimeInterval = strTimeInterval; m_Period = period; m_Applied = applied; m_Quantity = quantity; m_Hma = new HMA(m_Period, m_Applied); try { if (last == null) { m_NewOrder = null; } else { var candles = client.GetCandleStick(m_Symbol, m_TimeInterval); if (candles == null) { m_NewOrder = null; } else { var hmaArray = m_Hma.iHMA_Array(candles); int preSignal = -1; for (int i = hmaArray.Length - 1; i >= 0; i--) { if (last.Side == "BUY") { if (hmaArray[i].Trend != ENUM_TREND.UP_TREND) { preSignal = i; break; } } else if (last.Side == "SELL") { if (hmaArray[i].Trend != ENUM_TREND.DOWN_TREND) { preSignal = i; break; } } } if (preSignal < 0 || preSignal >= hmaArray.Length) { m_NewOrder = null; } else { if (candles.ElementAt(preSignal).CloseTime >= last.Time) { m_NewOrder = null; } else { m_NewOrder = new NewOrder(); m_NewOrder.OrderId = last.OrderId; m_NewOrder.ClientOrderId = last.ClientOrderId; m_NewOrder.Symbol = symbol; m_NewOrder.TransactTime = last.Time; } } } } } catch { m_NewOrder = null; } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { //DonchianChannel dc = DonchianChannel(20); hma = HMA(hmaPeriod); zz = ZigZag(deviationType, deviationValue, useHighLow); zzFib = ZigZagFib(deviationType, deviationValue, useHighLow); // ReadZigZag(); swingHigh = zzFib.Upper[0]; swingLow = zzFib.Lower[0]; double upperTrade = zzFib.LowerFib[0]; double lowerTrade = zzFib.LowerFib[0]; //if (enableDebug) DrawText(CurrentBar + "currentHigh", barsAgoHigh+"", 0, High[0] + 5 * TickSize, Color.White); //if (enableDebug) DrawText(CurrentBar + "currentLow", barsAgoLow+"", 0, Low[0] - 5 * TickSize, Color.White); if (swingHigh <= 0 || swingLow <= 0) { return; } //DrawDot(CurrentBar + "zz", true, 0, zz.ZigZagHigh[0], Color.Purple); //if (swingLow > currentZigZagLow && currentZigZagLow > 0) // swingLow = currentZigZagLow; //RemoveDrawObjects(); //Print("HighestBar(High, period): " + HighestBar(High, 30) + " swingHigh: " + swingHigh); //DrawHorizontalLine("SwingHigh", swingHigh, Color.White); //DrawHorizontalLine("SwingLow", swingLow, Color.White); //DrawHorizontalLine("UpperTrade", false, upperTrade, Color.Blue, DashStyle.Dash, 1); //DrawHorizontalLine("LowerTrade", false, lowerTrade, Color.Red, DashStyle.Dash, 1); //if (ToTime(Time[0]) > ToTime(7, 04, 0)) { if (Position.MarketPosition == MarketPosition.Flat) { //if (barsAgoHigh > barsAgoLow) // && Rising(hma)) if (Rising(hma) && Close[0] <= zzFib.LowerFib[0] //&& (zzFib.Lower[20] - zzFib.Lower[0]) <= 0 * TickSize // may potentially need to ignore new lows due to expired old lows ) { triggeredStopMove = false; GoLong(zzFib.LowerFib[0], zzFib.LowerFib[0]); DrawDot(CurrentBar + "tLong", true, 0, zzFib.LowerFib[0], Color.Green); DrawDot(CurrentBar + "tStop", true, 0, zzFib.UpperFib[0], Color.LightGreen); } if (Falling(hma) && AtTop(Close[0])) { openHigh = swingHigh; openLow = swingLow; GoShort(upperTrade, upperTrade); DrawDot(CurrentBar + "tShort", true, 0, zzFib.UpperFib[0], Color.Yellow); DrawDot(CurrentBar + "tStop", true, 0, zzFib.LowerFib[0], Color.LightYellow); } } ManageTrade(); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { hmaFast = HMA(HmaFastPeriod); hmaMed = HMA(HmaMedPeriod); hmaSlow = HMA(HmaSlowPeriod); adx = ADX(adxPeriod); if (Position.MarketPosition != MarketPosition.Flat) { ManageTrade(); return; } if ( adx.Value[0] > AdxValue && Rising(hmaFast) //&& Rising(hmaMed) //&& hmaFast[0] > hmaMed[0] //&& hmaFast[0] > hmaSlow[0] && Close[0] > hmaFast[0] && Close[0] > hmaMed[0] && Close[0] > hmaSlow[0] && Open[0] > Open[1] //&& Open[1] > Open[2] && Close[0] > Close[1] //&& Close[1] > Close[2] && (hmaSlow[0] - hmaFast[0]) / TickSize < 5 ) { GoLong(); } if ( adx.Value[0] > AdxValue && Falling(hmaFast) //&& Falling(hmaSlow) //&& hmaFast[0] < hmaMed[0] //&& hmaFast[0] < hmaSlow[0] && Close[0] < hmaFast[0] && Close[0] < hmaMed[0] && Close[0] < hmaSlow[0] && Open[0] < Open[1] //&& Open[1] < Open[2] && Close[0] < Close[1] //&& Close[1] < Close[2] && (hmaFast[0] - hmaSlow[0]) / TickSize < 5 //&& (BarsSinceExit("Short") > 2 || BarsSinceExit("Short") == -1) ) { GoShort(); } // This call to go short doesn't depend on ADX if ( Falling(hmaFast) && hmaFast[0] < hmaMed[0] && hmaMed[0] < hmaSlow[0] && Open[0] < Open[1] && Open[1] < Open[2] && Close[0] < Close[1] && Close[1] < Close[2] && (BarsSinceExit("Short") > 2 || BarsSinceExit("Short") == -1) && 2 == 3 ) { GoShort(); } }