protected override void OnTimer() { var remainingTime = _triggerTimeInServerTimeZone - Server.Time; DrawRemainingTime(remainingTime); if (!_ordersCreated) { var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize; ChartObjects.DrawHorizontalLine("sell target", sellOrderTargetPrice, Colors.Red, 1, LineStyle.DotsVeryRare); var buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize; ChartObjects.DrawHorizontalLine("buy target", buyOrderTargetPrice, Colors.Blue, 1, LineStyle.DotsVeryRare); if (Server.Time <= _triggerTimeInServerTimeZone && (_triggerTimeInServerTimeZone - Server.Time).TotalSeconds <= SecondsBefore) { _ordersCreated = true; var expirationTime = _triggerTimeInServerTimeZone.AddSeconds(SecondsTimeout); PlaceStopOrder(TradeType.Sell, Symbol, Volume, sellOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime); PlaceStopOrder(TradeType.Buy, Symbol, Volume, buyOrderTargetPrice, Label, StopLoss, TakeProfit, expirationTime); ChartObjects.RemoveObject("sell target"); ChartObjects.RemoveObject("buy target"); } } if (_ordersCreated && !PendingOrders.Any(o => o.Label == Label)) { Print("Orders expired"); Stop(); } }
public void Dispose() { foreach (var name in _addedAlgoChartObjects) { _chartObjects.RemoveObject(name); } }
protected override void OnStart() { state = new State(TimeFrame.Daily); lseries = new Dictionary <TimeFrame, Dictionary <string, MarketSeries> >(); rseries = new Dictionary <TimeFrame, Dictionary <string, MarketSeries> >(); lmm50 = new Dictionary <TimeFrame, Dictionary <string, ExponentialMovingAverage> >(); lmm200 = new Dictionary <TimeFrame, Dictionary <string, WeightedMovingAverage> >(); rmm200 = new Dictionary <TimeFrame, Dictionary <string, WeightedMovingAverage> >(); lmacd = new Dictionary <TimeFrame, Dictionary <string, MacdCrossOver> >(); rmacd = new Dictionary <TimeFrame, Dictionary <string, MacdCrossOver> >(); spaths = new Dictionary <string, string>(3) { { "PB", "C:\\Users\\Andrey\\Music\\Sounds\\sms-alert-1.wav" }, { "MMX", "C:\\Users\\Andrey\\Music\\Sounds\\sms-alert-4.wav" }, { "VCN", "C:\\Users\\Andrey\\Music\\Sounds\\sms-alert-3.wav" } }; Print("Initializing screener local state."); foreach (var tf in GetAllRequiredTimeFrames()) { InitializeIndicators(tf); } Print("Initialization finished."); var output = state.Render(); ChartObjects.RemoveObject("screener"); ChartObjects.DrawText("screener", output, StaticPosition.TopLeft, Colors.Black); }
public override void Calculate(int index) { if (index < 1) { // If first bar is first bar of the day set open if (MarketSeries.OpenTime[index].TimeOfDay == TimeSpan.Zero) { Open[index] = MarketSeries.Open[index]; } return; } DateTime openTime = MarketSeries.OpenTime[index]; DateTime lastOpenTime = MarketSeries.OpenTime[index - 1]; const string objectName = "messageNA"; if (!ApplicableTimeFrame(openTime, lastOpenTime)) { // Display message that timeframe is N/A const string text = "TimeFrame Not Applicable. Choose a lower Timeframe"; ChartObjects.DrawText(objectName, text, StaticPosition.TopLeft, Colors.Red); return; } // If TimeFrame chosen is applicable remove N/A message ChartObjects.RemoveObject(objectName); // Plot Daily Open and Close PlotDailyOpenClose(openTime, lastOpenTime, index); }
public override void Calculate(int index) { if (!IsRealTime) { return; } String output = ""; var rval = atr.Result.LastValue; double ratr; if (Symbol.PipSize == 0.0001) { ratr = Math.Round(rval * 10000, 1); } else if (Symbol.PipSize == 0.01) { ratr = Math.Round(rval * 100, 1); } else { ratr = 0; } output += string.Format("TP:\t{0}\n", ratr * 2); output += string.Format("SL:\t{0}\n", ratr * 4); output += string.Format("QTY:\t{0}", GetQuantity(ratr * 4)); ChartObjects.RemoveObject("scalpinginfo"); ChartObjects.DrawText("scalpinginfo", output, StaticPosition.TopLeft, Colors.DarkGreen); }
private void DrawRemainingTime(TimeSpan remainingTimeToNews) { if (ShowTimeLeftToNews) { if (remainingTimeToNews > TimeSpan.Zero) { ChartObjects.DrawText("countdown1", "Time left to news: " + FormatTime(remainingTimeToNews), StaticPosition.Right); } else { ChartObjects.RemoveObject("countdown1"); } } if (ShowTimeLeftToPlaceOrders) { var remainingTimeToOrders = remainingTimeToNews - TimeSpan.FromSeconds(SecondsBefore); if (remainingTimeToOrders > TimeSpan.Zero) { ChartObjects.DrawText("countdown2", "Time left to place orders: " + FormatTime(remainingTimeToOrders), StaticPosition.TopRight); } else { ChartObjects.RemoveObject("countdown2"); } } }
private void drawCircle(Fractal fractal) { if (drawCircles) { ChartObjects.DrawText(getCircleLabel(fractal), circle, fractal.index, fractal.value, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Aqua); } Fractal previous = fractal.getPreviousOfSameSide(); if (previous != null) { foreach (Fractal badFractal in fractal.getBadFractals()) { if (drawCircles) { ChartObjects.RemoveObject(getCircleLabel(badFractal)); } if (!highlightBadFractals) { ChartObjects.RemoveObject(getArrowLabel(badFractal)); } if (highlightBadFractals) { ChartObjects.DrawText(getCircleLabel(badFractal), circle, badFractal.index, badFractal.value, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Red); } } } }
protected override void OnBar() { // PB Signals if (EnablePB) { foreach (var tf in ParseTimeFrames(PBTimeFrames)) { foreach (var sym in symbols) { var timing = CalculateMarketTiming(sym, tf); var val = GetPBSignal(sym, tf, timing); var value = new State.Value("PB", sym, tf, timing, val); state.Update(value); if (EnableEmailAlerts) { HandleEmailAlerts(value); } if (EnableSoundAlerts) { HandleSoundAlerts(value); } } } } // MMX Signals if (EnableMMX) { foreach (var tf in ParseTimeFrames(MMXTimeFrames)) { foreach (var sym in symbols) { var timing = CalculateMarketTiming(sym, tf); var val = GetMMXSignal(sym, tf, timing); var value = new State.Value("MMX", sym, tf, timing, val); state.Update(value); if (EnableEmailAlerts) { HandleEmailAlerts(value); } if (EnableSoundAlerts) { HandleSoundAlerts(value); } } } } var output = state.Render(); ChartObjects.RemoveObject("screener"); ChartObjects.DrawText("screener", output, StaticPosition.TopLeft, Colors.Black); }
protected override void OnBar() { foreach (var sym in symbols) { var timing = CalculateMarketTiming(sym); if (EnablePB) { var val = GetPBSignal(sym, timing); var value = new State.Value("PB", sym, timing, val); state.Update(value); if (EnableEmailAlerts) { HandleEmailAlerts(value); } if (EnableSoundAlerts) { HandleSoundAlerts(value); } } //if (EnableAcc) { // var val = GetAccSignal(sym, timing); // var value = new State.Value("ACC", sym, timing, val); // state.Update(value); // if (EnableEmailAlerts) { // HandleEmailAlerts(value); // } // if (EnableSoundAlerts) { // HandleSoundAlerts(value); // } //} //if (EnableVcn) { // var val = GetVcnSignal(sym, timing); // var value = new State.Value("VCN", sym, timing, val); // state.Update(value); // if (EnableEmailAlerts) { // HandleEmailAlerts(value); // } // if (EnableSoundAlerts) { // HandleSoundAlerts(value); // } //} } var output = state.Render(); ChartObjects.RemoveObject("screener"); ChartObjects.DrawText("screener", output, StaticPosition.TopLeft, Colors.Black); }
protected override void OnStart() { state = new State(TFrame); lseries = new Dictionary <string, MarketSeries>(); rseries = new Dictionary <string, MarketSeries>(); lmm6 = new Dictionary <string, ExponentialMovingAverage>(); lmm18 = new Dictionary <string, ExponentialMovingAverage>(); lmm50 = new Dictionary <string, ExponentialMovingAverage>(); lmm100 = new Dictionary <string, ExponentialMovingAverage>(); rmm100 = new Dictionary <string, ExponentialMovingAverage>(); lmm200 = new Dictionary <string, SimpleMovingAverage>(); rmm200 = new Dictionary <string, SimpleMovingAverage>(); lmacd = new Dictionary <string, MacdCrossOver>(); rmacd = new Dictionary <string, MacdCrossOver>(); spaths = new Dictionary <string, string>(3); spaths.Add("MACD", "C:\\Users\\Andrey\\Music\\Sounds\\sms-alert-1.wav"); spaths.Add("ACC", "C:\\Users\\Andrey\\Music\\Sounds\\sms-alert-4.wav"); spaths.Add("VCN", "C:\\Users\\Andrey\\Music\\Sounds\\sms-alert-3.wav"); Print("Initializing screener local state."); foreach (var sym in symbols) { Print("Initializing data for: {0}/{1}.", sym, TFrame); var reftf = GetReferenceTimeframe(TFrame); var lmks = MarketData.GetSeries(sym, TFrame); var rmks = MarketData.GetSeries(sym, reftf); lmm6[sym] = Indicators.ExponentialMovingAverage(lmks.Close, 6); lmm18[sym] = Indicators.ExponentialMovingAverage(lmks.Close, 18); lmm50[sym] = Indicators.ExponentialMovingAverage(lmks.Close, 50); lmm100[sym] = Indicators.ExponentialMovingAverage(lmks.Close, 100); rmm100[sym] = Indicators.ExponentialMovingAverage(rmks.Close, 100); lmm200[sym] = Indicators.SimpleMovingAverage(lmks.Close, 200); rmm200[sym] = Indicators.SimpleMovingAverage(rmks.Close, 200); lmacd[sym] = Indicators.MacdCrossOver(lmks.Close, 26, 12, 9); rmacd[sym] = Indicators.MacdCrossOver(rmks.Close, 26, 12, 9); lseries[sym] = lmks; rseries[sym] = rmks; } Print("Initialization finished."); var output = state.Render(); ChartObjects.RemoveObject("screener"); ChartObjects.DrawText("screener", output, StaticPosition.TopLeft, Colors.Black); }
public override void Calculate(int index) { if (errorOccured) { ChartObjects.DrawText("errorlabel", errorMsg, StaticPosition.TopCenter, Colors.Red); return; } // get the last highest price value double high = (minuteSeries.High.LastValue); // get the last lowest price value double low = (minuteSeries.Low.LastValue); // difference between high and low devided by the current instruments pip size = sudden movement in pips double pips = (high - low) / Symbol.PipSize; string pipsVolatility = "Vol : " + pips.ToString("0.00") + " pips"; // display error message to screen. if (ShowVolatility) { ChartObjects.DrawText("volatilityMsg", pipsVolatility += lowerPosition, position, spreadTextColor); } // if pip movement > volatility setting if (Math.Ceiling(pips) > VolatilityPips) { if (AlertOn) { ChartObjects.DrawText("alertMsg", pipsVolatility, position, warningTextColor); } if (PlaySound) { if (MediaFile != string.Empty) { Notifications.PlaySound(MediaFile); } } } else { ChartObjects.RemoveObject("alertMsg"); } // if user wants to see the current bid/ask spread size, * feature seperate from volatility alert. if (ShowSpread) { var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2); string s = string.Format("{0:N2}", spread); ChartObjects.DrawText("spreadMsg", "\nSpread: " + s, position, spreadTextColor); } }
private TimingOld CalculateMarketTiming() { var local = CalculateTiming(lmacd, lma, MarketSeries); var reference = CalculateTiming(rmacd, rma, rseries); var msg = string.Format("Market timing: {0} {1}", reference, local); ChartObjects.RemoveObject("test"); ChartObjects.DrawText("test", msg, StaticPosition.TopCenter, Colors.Black); return(new TimingOld(reference, local)); }
private NewsItem DisplayUpcomingNews() { var upcomingNews = new List <NewsItem>(); upcomingNews = _newsItems.Where(x => x.UtcDateTime >= DateTime.UtcNow).Take(EventsToDisplay).ToList(); //remove old objects for (int i = 0; i < EventsToDisplay; i++) { ChartObjects.RemoveObject("NewsItem" + i.ToString()); } int objectId = 0; string verticalTab = ""; foreach (NewsItem newsItem in upcomingNews) { Colors color; switch (newsItem.Importance) { case Importance.High: color = Colors.Red; break; case Importance.Low: color = Colors.Yellow; break; case Importance.Medium: color = Colors.Orange; break; default: color = Colors.Black; break; } //Create The Newsstring with datetime on Current timezone (localmachine) var dateStr = (newsItem.UtcDateTime.Add(System.TimeZoneInfo.Local.BaseUtcOffset)).ToString("ddd HH:mm"); string news = string.Format("{0} - {1} - {2}", newsItem.Currency, dateStr, newsItem.Event); ChartObjects.DrawText("NewsItem" + objectId++.ToString(), verticalTab + " " + news, (StaticPosition)Position, color); verticalTab += Environment.NewLine; } //return the next upcomming event. //TODO: Don't trust CSV data, verify that this is the next upcoming order return(upcomingNews.First()); }
private void DisplayUpcomingNews() { var upcomingNews = _newsItems.Where(x => x.UtcDateTime >= DateTime.UtcNow).Take(EventsToDisplay).ToList(); var utcOffset = TimeZone.BaseUtcOffset; //remove old objects for (int i = 0; i < EventsToDisplay; i++) { ChartObjects.RemoveObject("NewsItem" + i.ToString()); } int objectId = 0; string verticalTab = ""; foreach (NewsItem newsItem in upcomingNews) { Colors color; switch (newsItem.Importance) { case Importance.High: color = Colors.Red; break; case Importance.Low: color = Colors.Yellow; break; case Importance.Medium: color = Colors.Orange; break; default: color = Colors.Black; break; } var dateStr = (newsItem.UtcDateTime.Add(utcOffset)).ToString("ddd HH:mm"); string news = string.Format("{0} - {1} - {2}", newsItem.Currency, dateStr, newsItem.Event); ChartObjects.DrawText("NewsItem" + objectId++.ToString(), verticalTab + " " + news, (StaticPosition)Position, color); verticalTab += Environment.NewLine; } }
/// <summary> /// Main method /// </summary> /// <param name="index"></param> public override void Calculate(int index) { if (!(_showPivots || _showLabels)) { ChartObjects.DrawText("msgShow", "Set \"Draw Labels\" or \"Draw Pivots\" to 1", StaticPosition.TopLeft, Colors.Red); return; } ChartObjects.RemoveObject("msgShow"); if (index <= 1) { _p[index] = 0; return; } if (GetTimeFrame(index) == Timeframe.na && _currentTimeFrame == Timeframe.na) { _p[index] = 0; return; } if (_currentTimeFrame == Timeframe.na) { _currentTimeFrame = GetTimeFrame(index); } bool daily = _currentTimeFrame < Timeframe.D1 && _dailyPivots; bool weekly = _currentTimeFrame < Timeframe.W1 && _weeklyPivots; if (!(daily || weekly)) { ChartObjects.DrawText("msg", "Incorrect Timeframe selection", StaticPosition.TopLeft, Colors.Red); return; } ChartObjects.RemoveObject("msg"); CalculatePivots(index, daily, weekly); if (ShowPivots == 1) { DrawPivots(index); } }
void OnGbpUsdUpdated() { float sumBid = 0; float sumAsk = 0; _askNo = 0; _bidNo = 0; var index = MarketSeries.Close.Count - 1; for (int i = 0; i < 100; i++) { ChartObjects.RemoveObject(i.ToString() + "ask"); ChartObjects.RemoveObject(i.ToString() + "bid"); } foreach (var entry in GBPUSD.AskEntries) { sumAsk += entry.Volume; } foreach (var entry in GBPUSD.BidEntries) { sumBid += entry.Volume; } string s = ""; foreach (var entry in GBPUSD.AskEntries) { double val = entry.Volume / sumAsk; int len = Math.Max(1, (int)(lineLen * val)); ChartObjects.DrawLine(_askNo.ToString() + "ask", index + 1, entry.Price, index + len, entry.Price, Colors.Red, lineThickness); s += "\n ask " + len.ToString(); _askNo++; } foreach (var entry in GBPUSD.BidEntries) { double val = entry.Volume / sumBid; int len = Math.Max(1, (int)(lineLen * val)); ChartObjects.DrawLine(_bidNo.ToString() + "bid", index + 1, entry.Price, index + len, entry.Price, Colors.Blue, lineThickness); s += "\n bid " + len.ToString(); _bidNo++; } }
//****************************************** public void CheckCandles() { if (LTF_Candle.Open.Last(0) > LTF_Candle.Close.Last(0)) { DailyCandleUp = false; ChartObjects.RemoveObject("theText"); ChartObjects.DrawText("theText", LTF + "_Candle" + Down, StaticPosition.BottomLeft, Colors.Red); } else if (LTF_Candle.Open.Last(0) < LTF_Candle.Close.Last(0)) { DailyCandleUp = true; ChartObjects.RemoveObject("theText"); ChartObjects.DrawText("theText", LTF + "_Candle" + " " + UP, StaticPosition.BottomLeft, Colors.Green); } if (MTF_Candle.Open.Last(0) > MTF_Candle.Close.Last(0)) { HourlyCandleUp = false; ChartObjects.RemoveObject("theText2"); ChartObjects.DrawText("theText2", MTF + "_Candle" + " " + Down, StaticPosition.BottomCenter, Colors.Red); } else if (MTF_Candle.Open.Last(0) < MTF_Candle.Close.Last(0)) { HourlyCandleUp = true; ChartObjects.RemoveObject("theText2"); ChartObjects.DrawText("theText2", MTF + "_Candle" + " " + UP, StaticPosition.BottomCenter, Colors.Green); } if (STF_Candle.Open.Last(0) > STF_Candle.Close.Last(0)) { m5CandleUp = false; ChartObjects.RemoveObject("theText3"); ChartObjects.DrawText("theText3", STF + "_Candle" + " " + Down, StaticPosition.BottomRight, Colors.Red); } else if (STF_Candle.Open.Last(0) < STF_Candle.Close.Last(0)) { m5CandleUp = true; ChartObjects.RemoveObject("theText3"); ChartObjects.DrawText("theText3", STF + "_Candle" + " " + UP, StaticPosition.BottomRight, Colors.Green); } }
private void RCN() { if (o_tm(TradeType.Buy) > 1) { double y = pnt_12(TradeType.Buy); ChartObjects.DrawHorizontalLine("bpoint", y, Colors.Yellow, 2, LineStyle.Dots); } else { ChartObjects.RemoveObject("bpoint"); } if (o_tm(TradeType.Sell) > 1) { double z = pnt_12(TradeType.Sell); ChartObjects.DrawHorizontalLine("spoint", z, Colors.HotPink, 2, LineStyle.Dots); } else { ChartObjects.RemoveObject("spoint"); } ChartObjects.DrawText("pan", A_cmt_calc(), StaticPosition.TopLeft, Colors.Tomato); }
//Draw the Action lines to illustrate the trades private void DrawDescisionLines() { if (activeDirectionCount(TradeType.Buy) > 1) { double y = AverageEntryPrice(TradeType.Buy); ChartObjects.DrawHorizontalLine("bpoint", y, Colors.Yellow, 2, LineStyle.Dots); } else { ChartObjects.RemoveObject("bpoint"); } if (activeDirectionCount(TradeType.Sell) > 1) { double z = AverageEntryPrice(TradeType.Sell); ChartObjects.DrawHorizontalLine("spoint", z, Colors.HotPink, 2, LineStyle.Dots); } else { ChartObjects.RemoveObject("spoint"); } ChartObjects.DrawText("pan", botText(), StaticPosition.TopLeft, Colors.Tomato); }
public override void Calculate(int index) { if (index < 1) { // If first bar is first bar of the day set open if (MarketSeries.OpenTime[index].TimeOfDay == TimeSpan.Zero) { OpenWeek[index] = MarketSeries.Open[index]; OpenMonth[index] = MarketSeries.Open[index]; OpenDay[index] = MarketSeries.Open[index]; return; } } DateTime openTime = MarketSeries.OpenTime[index]; DateTime lastOpenTime = MarketSeries.OpenTime[index - 1]; const string objectName = "messageNA"; if (!ApplicableTimeFrame(openTime, lastOpenTime)) { // Display message that timeframe is N/A const string text = "TimeFrame Not Applicable. Choose a lower Timeframe"; ChartObjects.DrawText(objectName, text, StaticPosition.TopLeft, Colors.Red); return; } // If TimeFrame chosen is applicable remove N/A message ChartObjects.RemoveObject(objectName); // Plot Daily Open and Close PlotDailyOpenClose(openTime, lastOpenTime, index); var name1 = "Dn"; var text1 = "Day Open : " + openprice1.ToString() + " \nWeek Open: " + openprice2.ToString() + " \nMonth Open:" + openprice3.ToString(); var staticPos = StaticPosition.TopRight; var color = Colors.Yellow; ChartObjects.DrawText(name1, text1, staticPos, color); }
private void DisplayStatusOnChart() { if (CountOfTradesOfType(TradeType.Buy) > 1) { var y = CalculateAveragePositionPrice(TradeType.Buy); ChartObjects.DrawHorizontalLine("bpoint", y, Colors.Yellow, 2, LineStyle.Dots); } else { ChartObjects.RemoveObject("bpoint"); } if (CountOfTradesOfType(TradeType.Sell) > 1) { var z = CalculateAveragePositionPrice(TradeType.Sell); ChartObjects.DrawHorizontalLine("spoint", z, Colors.HotPink, 2, LineStyle.Dots); } else { ChartObjects.RemoveObject("spoint"); } ChartObjects.DrawText("pan", GenerateStatusText(), StaticPosition.TopLeft, Colors.Tomato); }
// ------------------------------------------- // ---- Rendering // ------------------------------------------- private void Render() { var output = new List <String>(symbols.Length + 2); output.Add(string.Format("\t{0,-15}\t{1,-20}\t{2}", "Asset", "Timing", "Signals")); output.Add("\t----------------------------------------------------------------------------------------------------------"); foreach (var sym in symbols) { var asset = state.GetAsset(sym); var timing = asset.Timing; var timingStr = string.Format("{0},{1},{2},{3}", timing.D1, timing.H4, timing.H1, timing.M5); var signalsOutput = new HashSet <String>(); foreach (var signal in asset.Signals) { if (signal.IsUpTrend()) { signalsOutput.Add(string.Format("{0}(▲,{1},{2})", signal.Name, signal.TimeFrame, signal.Value)); } else { signalsOutput.Add(string.Format("{0}(▼,{1},{2})", signal.Name, signal.TimeFrame, signal.Value)); } } output.Add(string.Format("\t{0,-15}\t{1,-20}\t{2}", asset.Name, timingStr, String.Join(", ", signalsOutput))); var buffer = String.Join("\r\n", output); ChartObjects.RemoveObject("screener"); ChartObjects.DrawText("screener", buffer, StaticPosition.TopLeft, Colors.Black); } }
public override void Calculate(int index) { if (triggered) { PlayedNotificationLine[index] = Price; return; } if (BidOrAsk == 1) { BidTarget[index] = Price; } else { AskTarget[index] = Price; } if (IsRealTime) { var color = BidOrAsk == 1 ? BidColor : AskColor; var spotPrice = BidOrAsk == 1 ? Symbol.Bid : Symbol.Ask; var distance = Math.Round(Math.Abs(Price - spotPrice) / Symbol.PipSize, 1); ChartObjects.DrawText("distance", " " + distance + " pips left", index, Price, VerticalAlignment.Center, HorizontalAlignment.Right, color); if (spotPriceWasAbove && spotPrice <= Price || !spotPriceWasAbove && spotPrice >= Price) { var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows); Notifications.PlaySound(Path.Combine(windowsFolder, "Media", "tada.wav")); triggered = true; FillLine(BidTarget, double.NaN); FillLine(AskTarget, double.NaN); FillLine(PlayedNotificationLine, Price); ChartObjects.RemoveObject("distance"); PlayedNotifications.Add(CreateNotification()); } } }
////////////////////////////////////////////////// protected override void OnTimer() { //base.OnTimer(); //ChartObjects.DrawText("Inside", Squeeze, StaticPosition.BottomCenter, Colors.Red); ChartObjects.RemoveObject("Inside"); }
public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... //main[index] = Klt.Main[index]; if (SigOrHist) { Mac_D[index] = MacD.Signal[index] * Mac_factor; } else { Mac_D[index] = MacD.Histogram[index] * Mac_factor; } if (LR_Based == true) { LR_Slope.Result[index] = _momentum.Result[index]; RefreshData(); //moScillatorUp[index] = _momentum.Result[index]; //double momentum = LR_Slope.Result[index]; if (LR_Slope.Result[index] >= 0.0) { if (LR_Slope.Result.IsRising()) { moScillatorUp[index] = LR_Slope.Result[index]; } else { moScillatorUp2[index] = LR_Slope.Result[index]; } ChartObjects.RemoveObject("Direction"); ChartObjects.DrawText("Direction", UP, StaticPosition.BottomRight, Colors.Green); ChartObjects.DrawText("Direction1", Bullet, index, -1.2 * moScillatorUp[index], vAlign, hAlign, Colors.Green); } else { if (LR_Slope.Result.IsFalling()) { moScillatorDown[index] = (LR_Slope.Result[index]); } else { moScillatorDown2[index] = (LR_Slope.Result[index]); } ChartObjects.RemoveObject("Direction"); ChartObjects.DrawText("Direction", Down, StaticPosition.BottomRight, Colors.Red); ChartObjects.DrawText("Direction1", Bullet, index, 1.2 * moScillatorDown[index], vAlign, hAlign, Colors.Red); } } else { if (_momentum.Result[index] >= 100.0) { if (_momentum.Result.IsRising()) { moScillatorUp[index] = (_momentum.Result[index] - 100.0); } else { moScillatorUp2[index] = (_momentum.Result[index] - 100.0); } moScillatorUp[index] = (_momentum.Result[index] - 100.0); ChartObjects.RemoveObject("Direction"); ChartObjects.DrawText("Direction", UP, StaticPosition.BottomRight, Colors.Green); //ChartObjects.DrawText("Direction1", Bullet, index, -1.2 * moScillatorUp[index], vAlign, hAlign, Colors.Green); } else { if (_momentum.Result.IsFalling()) { moScillatorDown[index] = (_momentum.Result[index] - 100.0); } else { moScillatorDown2[index] = (_momentum.Result[index] - 100.0); } moScillatorDown[index] = (_momentum.Result[index] - 100.0); ChartObjects.RemoveObject("Direction"); ChartObjects.DrawText("Direction", Down, StaticPosition.BottomRight, Colors.Red); // ChartObjects.DrawText("Direction1", Bullet, index, 1.2 * moScillatorDown[index], vAlign, hAlign, Colors.Red); } } /// Keltner & Bollinger Calculations /// Seems like they need a separate Thread ? //klt_main[index] = Klt.Main[index]; //klt_top[index] = Klt.Top[index]; //klt_bottom[index] = Klt.Bottom[index]; //bb_main[index] = bb.Main[index]; //bb_top[index] = bb.Top[index]; //bb_bottom[index] = bb.Bottom[index]; if (bb.Top[index] < Klt.Top[index] && bb.Bottom[index] > Klt.Bottom[index]) { Squeeze_State = true; //ChartObjects.DrawText("Inside", Squeeze, StaticPosition.BottomCenter, Colors.Black); ChartObjects.DrawText("Direction1" + index, Squeeze, index, 0, vAlign, hAlign, Colors.Red); } else if (Squeeze_State) { ChartObjects.DrawText("Direction1" + index, Squeeze, index, 0, vAlign, hAlign, Colors.Green); //ChartObjects.RemoveObject("Inside"); //Timer.Stop(); Squeeze_State = false; Notifications.PlaySound("C:\\Sounds\\Bike Horn.wav"); //form1.ShowDialog(); } }
public override void Calculate(int index) { String outputHeader = "\t"; String outputValue = "\t"; if (EnableATRInfo) { var rval = atr.Result.LastValue; double val = 100; if (Symbol.PipSize == 0.0001) { val = Math.Round(rval * 10000, 1); } else if (Symbol.PipSize == 0.01) { val = Math.Round(rval * 100, 1); } else if (Symbol.PipSize == 0.1) { val = Math.Round(rval * 10, 1); } else { throw new Exception("Unexpected pip size."); } outputValue += string.Format("{0}\t|\t", val); outputHeader += string.Format("ATR\t|\t"); } if (EnableD1) { var value = CalculateTiming(macdD1, mmD1, seriesD1); outputHeader += string.Format("D1\t"); outputValue += string.Format("{0}({1})\t", TimingToArrow(value), value); } if (EnableH4) { var value = CalculateTiming(macdH4, mmH4, seriesH4); outputHeader += string.Format("H4\t"); outputValue += string.Format("{0}({1})\t", TimingToArrow(value), value); } if (EnableH1) { var value = CalculateTiming(macdH1, mmH1, seriesH1); outputValue += string.Format("{0}({1})\t", TimingToArrow(value), value); outputHeader += string.Format("H1\t"); } if (EnableM5) { var value = CalculateTiming(macdM5, mmM5, seriesM5); outputValue += string.Format("{0}({1})\t", TimingToArrow(value), value); outputHeader += string.Format("M5\t"); } String output = string.Format("{0}\n{1}", outputHeader, outputValue); ChartObjects.RemoveObject("timing"); ChartObjects.DrawText("timing", output, StaticPosition.TopCenter, Colors.Black); }
public override void Calculate(int index) { CO_Val = double.NaN; HL_Val = double.NaN; CO_Val = MarketSeries.Close[index] - MarketSeries.Open[index]; HL_Val = MarketSeries.High[index] - MarketSeries.Low[index]; CO_Series[index] = CO_Val; HL_Series[index] = HL_Val; ECO[index] = 100 * (EMA_CO_S.Result[index] / EMA_HL_S.Result[index]); if (Line) { ECO_Line[index] = ECO[index]; } else { if (ECO[index] > 0) { if (Functions.IsRising(ECO)) { ECO_Hist_Up[index] = ECO[index]; } else { ECO_Hist_Up2[index] = ECO[index]; } ChartObjects.RemoveObject("Direction"); ChartObjects.DrawText("Direction", UP, StaticPosition.BottomRight, Colors.Green); } else { if (Functions.IsFalling(ECO)) { ECO_Hist_Dn[index] = ECO[index]; } else { ECO_Hist_Dn2[index] = ECO[index]; } ChartObjects.RemoveObject("Direction"); ChartObjects.DrawText("Direction", Down, StaticPosition.BottomRight, Colors.Red); } } if (bb.Top[index] < Klt.Top[index] && bb.Bottom[index] > Klt.Bottom[index]) { Squeeze_State = true; ChartObjects.DrawText("Direction1" + index, Squeeze, index, 0, vAlign, hAlign, Colors.Red); } else if (Squeeze_State) { ChartObjects.DrawText("Direction1" + index, Squeeze, index, 0, vAlign, hAlign, Colors.Green); Squeeze_State = false; Notifications.PlaySound("C:\\Sounds\\Bike Horn.wav"); //Notifications.SendEmail(fromAddress, toAdress, subject, text); } }
protected override void OnStop() { Timer.Stop(); ChartObjects.RemoveObject(CopierTextObjectName); }
public override void Calculate(int index) { if (index < 1) { // If first bar is first bar of the day set open if (MarketSeries.OpenTime[index].TimeOfDay == TimeSpan.Zero) { Open[index] = MarketSeries.Open[index]; } return; } DateTime openTime = MarketSeries.OpenTime[index]; DateTime lastOpenTime = MarketSeries.OpenTime[index - 1]; const string objectName = "messageNA"; if (!ApplicableTimeFrame(openTime, lastOpenTime)) { // Display message that timeframe is N/A const string text = "TimeFrame Not Applicable. Choose a lower Timeframe"; ChartObjects.DrawText(objectName, text, StaticPosition.TopLeft, Colors.Red); return; } // If TimeFrame chosen is applicable remove N/A message ChartObjects.RemoveObject(objectName); // Plot Daily Open and Close PlotDailyOpenClose(openTime, lastOpenTime, index); string Side = "BUY"; double PipsWeek = 0; PipsWeek = (Symbol.Ask - openprice) / Symbol.PipSize; double Pips = 0; if (Symbol.Ask > openprice) { Pips = (Symbol.Ask - openprice) / Symbol.PipSize; } if (Symbol.Ask < openprice) { Pips = (openprice - Symbol.Ask) / Symbol.PipSize; Side = "SELL"; } double Profit = (Pips / 100) * 1000; double PL = Math.Round(Account.Equity - Account.Balance); var name1 = "Week"; var text1 = "Week Open : " + openprice.ToString() + "\n Week open pips: " + (int)PipsWeek + " Side: " + Side; var staticPos = StaticPosition.TopRight; var color = Colors.Red; ChartObjects.DrawText(name1, text1, staticPos, color); var name12 = "Pips"; var text12 = "Position P&L: " + PL + " \n Week open pips : " + (int)PipsWeek + " Side: " + Side + " \n Each 0.01 Lot earn => " + (int)Profit / 100 + " USD (Initial Deposit 100$)"; var staticPos12 = StaticPosition.BottomLeft; var color12 = Colors.DodgerBlue; ChartObjects.DrawText(name12, text12, staticPos12, color12); if (Set100Levels && MinLevel < MaxLevel) { for (int i = MinLevel; i < MaxLevel; i++) { ChartObjects.DrawHorizontalLine("Level100" + i, i * 100 * Symbol.PipSize, Colors.DodgerBlue, 2, LineStyle.Solid); } } if (Set500Levels && MinLevel < MaxLevel) { for (int i = MinLevel; i < MaxLevel; i++) { ChartObjects.DrawHorizontalLine("Level500" + i, i * 500 * Symbol.PipSize, Colors.YellowGreen, 3, LineStyle.Solid); } } }
protected override void OnTick() { if (_GoLong) { // Find Number of Open Positions With defined Label (Stop Mode) var _LNOP = Positions.FindAll(_LLabel); if (_LNOP != null) { foreach (var lnop in _LNOP) { _LongX++; } } // Find Number of Pending Orders with defined Label (Limit Mode) if (PendingOrders.Count != 0) { foreach (var _FPP in PendingOrders) { if (_FPP != null) { if (_FPP.Label == _LLabel) { _LongLX++; } } else { _LongLX++; } } } else { _LongLX++; } // Find if last position with this Label was profitable var _FLPP = History.FindLast(_LLabel); //Find Last Position Profit if (_FLPP != null) { if (_FLPP.NetProfit > 0) { _LongX++; _LongLX++; Stop(); } } //If there is no Position then Draw a line (Stop Mode) if (_LongX == 0 && Symbol.Ask <= _LongPrice && !_LModeL) { ChartObjects.DrawHorizontalLine(_LLabel, _LongPrice, Colors.SteelBlue, 2, LineStyle.DotsVeryRare); } //If there is no Position then Draw a line (Limit Mode) if (_LongLX == 0 && Symbol.Ask >= _LongPrice && _LModeL) { ChartObjects.DrawHorizontalLine(_LLabel, _LongPrice, Colors.SteelBlue, 2, LineStyle.DotsVeryRare); } //Execute Order - First the Stop Mode if (Symbol.Ask >= _LongPrice && _LongX == 0 && _LCurrentTries < _MaxTries && !_LModeL) { ExecuteMarketOrder(TradeType.Buy, Symbol, _LVolume, _LLabel, SLoss, TakeProfit); _LCurrentTries++; ChartObjects.RemoveObject(_LLabel); if (_OCOMode) { _GoShort = false; ChartObjects.RemoveObject(_SLabel); } } //Execute Order - Limit Mode if (Symbol.Ask >= _LongPrice && _LongLX == 0 && _LCurrentTries < _MaxTries && _LModeL) { PlaceLimitOrder(TradeType.Buy, Symbol, _LVolume, _LongPrice, _LLabel, SLoss, TakeProfit); _LCurrentTries++; ChartObjects.RemoveObject(_LLabel); if (_OCOMode) { _GoShort = false; ChartObjects.RemoveObject(_SLabel); } } //Find Total Profit on Positions Closed var _LPCO = History.FindAll(_LLabel); foreach (var lpco in _LPCO) { _LTCProfit += lpco.NetProfit; } //Add profit of current position if (_LongLX == 1 || _LongX == 1) { var _LFCP = Positions.Find(_LLabel); if (_LFCP != null) { _LTCProfit += _LFCP.NetProfit; } } ChartObjects.DrawText("Long Current Profit", "Long: Current Net Profit: " + Math.Round(_LTCProfit, 2).ToString() + " || Number of Tries: " + _LCurrentTries.ToString(), StaticPosition.TopRight, Colors.SteelBlue); _LTCProfit = 0; _LongX = 0; _LongLX = 0; } // Short Mode if (_GoShort) { //Find Number of Positions var _SNOP = Positions.FindAll(_SLabel); if (_SNOP != null) { foreach (var snop in _SNOP) { _ShortX++; } } //Find Number of Pending Orders //Find Number of Short Pendings if (PendingOrders.Count != 0) { foreach (var _FNSP in PendingOrders) { if (_FNSP != null) { if (_FNSP.Label == _SLabel) { _ShortLX++; //Print("ShortLX is {0}", _ShortLX); } } else { _ShortLX++; //Print("ShortLX is {0}", _ShortLX); } } } else { _ShortLX++; } // Find if last position with this Label was profitable var _FLPPS = History.FindLast(_SLabel); //Find Last Position Profit if (_FLPPS != null) { if (_FLPPS.NetProfit > 0) { _ShortX++; _ShortLX++; Stop(); } } if (_ShortX == 0 && Symbol.Bid >= _ShortPrice && !_LModeS) { ChartObjects.DrawHorizontalLine(_SLabel, _ShortPrice, Colors.Red, 2, LineStyle.DotsVeryRare); } if (_ShortLX == 0 && Symbol.Bid <= _ShortPrice && _LModeS) { ChartObjects.DrawHorizontalLine(_SLabel, _ShortPrice, Colors.Red, 2, LineStyle.DotsVeryRare); } //First Stop Mode if (Symbol.Bid <= _ShortPrice && _ShortX == 0 && _SCurrentTries < _MaxTries && !_LModeS) { ExecuteMarketOrder(TradeType.Sell, Symbol, _SVolume, _SLabel, SLoss, TakeProfit); _SCurrentTries++; ChartObjects.RemoveObject(_SLabel); if (_OCOMode) { _GoLong = false; ChartObjects.RemoveObject(_LLabel); } } //Limit Mode if (Symbol.Bid >= _ShortPrice && _ShortLX == 0 && _SCurrentTries < _MaxTries && !_LModeS) { PlaceLimitOrder(TradeType.Sell, Symbol, _SVolume, _ShortPrice, _SLabel, SLoss, TakeProfit); _SCurrentTries++; ChartObjects.RemoveObject(_SLabel); if (_OCOMode) { _GoLong = false; ChartObjects.RemoveObject(_LLabel); } } var _SPCO = History.FindAll(_SLabel); foreach (var spco in _SPCO) { _STCProfit += spco.NetProfit; } // Short - Find Current Profit if (_ShortX == 0 || _ShortLX == 0) { var _SFCP = Positions.Find(_SLabel); if (_SFCP != null) { _STCProfit += _SFCP.NetProfit; } } ChartObjects.DrawText("Short Current Profit", "Short: Current Net Profit: " + Math.Round(_STCProfit, 2).ToString() + " || Number of Tries: " + _SCurrentTries.ToString(), StaticPosition.TopLeft, Colors.Red); _STCProfit = 0; _ShortX = 0; _ShortLX = 0; } if (_IPS) { if (_SCurrentTries == _STryN) { _SVolume += _Volume; _STryN += _TryN; } if (_LCurrentTries == _LTryN) { _LVolume += _Volume; _LTryN += _TryN; } } }