protected override void OnTimer() { if (lastHi > m.High.Maximum(1) && lastLo < m.Low.Minimum(1)) { return; } ChartObjects.RemoveAllObjects(); double prevHi = double.MinValue, prevLo = double.MaxValue; for (int i = 1; i <= DaysBackward; ++i) { double hi = m.High.Maximum(i); double lo = m.Low.Minimum(i); if (prevHi < hi) { DrawLine(MarketSeries.High, hi, 2, VerticalAlignment.Top); prevHi = hi; } if (prevLo > lo) { DrawLine(MarketSeries.Low, lo, -2, VerticalAlignment.Bottom); prevLo = lo; } } lastHi = m.High.Maximum(1); lastLo = m.Low.Minimum(1); }
private void ReDraw() { ChartObjects.RemoveAllObjects(); foreach (Alert alert in alerts) { if (MarketSeries.OpenTime.LastValue.AddMinutes(Period()) < alert.setup) { return; } if (!alert.inArgs) { continue; } Colors color; int periods = MarketSeries.OpenTime.Count - MarketSeries.OpenTime.GetIndexByTime(alert.setup); bool crossed = MarketSeries.Close.HasCrossedAbove(alert.price, periods) || MarketSeries.Close.HasCrossedBelow(alert.price, periods); bool near = Math.Abs(MarketSeries.Close.LastValue - alert.price) <= AlertDiapasone * Symbol.PipSize; if (near && Sound && alert.played > 0 && (alert.lastPlayed == null || DateTime.UtcNow.AddMinutes(-1) >= alert.lastPlayed)) { Notifications.PlaySound(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Ring.wav")); alert.lastPlayed = DateTime.UtcNow; --alert.played; } if (Visual && (crossed || near)) { color = Colors.Red; } else { color = Colors.CornflowerBlue; } ChartObjects.DrawText(string.Format("alert_{0}", alert.price), string.Format("| {0}{1}", alert.price, near ? string.Format(" ({0})", Math.Round(Math.Abs(MarketSeries.Close.LastValue - alert.price) / Symbol.PipSize), 1) : ""), MarketSeries.OpenTime.Count + 1, alert.price, VerticalAlignment.Center, HorizontalAlignment.Right, color); if (ContignousType == 0) { for (int j = MarketSeries.Close.Count - 1; j > 0 && alert.index == 0; --j) { if (MarketSeries.Low[j] <= alert.price && MarketSeries.High[j] >= alert.price) { alert.index = j; } } } else { alert.index = 1; } if (alert.index != 0) { ChartObjects.DrawLine(string.Format("alert_{0}_l", alert.price), alert.index, alert.price, MarketSeries.OpenTime.Count + 1, alert.price, color, Thickness, LineStyle.Dots); } } }
private void check() { DateTime?writeTime = null; lock (lockObject) { if (File.Exists(getFName())) { writeTime = File.GetLastWriteTime(getFName()); } if (lastModified == null || lastModified < writeTime) { ChartObjects.RemoveAllObjects(); alerts.Clear(); if (!load() || !parse()) { ChartObjects.DrawText("AlertsErrorMessage", string.Format("Alerts\n{0}", lastError), StaticPosition.TopRight, Colors.Red); } else { if (lastModified == null) { save(); } } } lastModified = writeTime; } }
public void draw() { ChartObjects.RemoveAllObjects(); var hAlign = HorizontalAlignment.Left; var color = Colors.White; streakTime = (int)(Server.Time - startTime).TotalMinutes; var targetEquity = startingBalance + profit; ChartObjects.DrawText("text", "Equity: " + Account.Equity + "/" + targetEquity, MarketSeries.Close.Count - 1, Symbol.Bid, VerticalAlignment.Top, hAlign, color); ChartObjects.DrawText("text2", "Time (min): " + streakTime + "/" + streakTimeavg + " | Trades: " + streakTrades + "/" + streakTradesAvg, MarketSeries.Close.Count - 1, Symbol.Bid, VerticalAlignment.Bottom, hAlign, color); var netPosition = 0.0; foreach (Position pos in this.Positions) { if (pos.TradeType == TradeType.Buy) { netPosition += pos.Volume; } else { netPosition -= pos.Volume; } } var pips = ((targetEquity - Account.Equity) / (netPosition * Symbol.PipValue)) * Symbol.PipSize; ChartObjects.DrawHorizontalLine("TP", Symbol.Bid + pips, Colors.White, 2, LineStyle.Lines); }
private void drawLine(List <int> segments) { ChartObjects.RemoveAllObjects(); int sz = segments.Count; for (int i = 0; i < sz - 1; i++) { int j0 = segments[i]; int j1 = segments[i + 1]; double a = stats[j1][j0].slope(); double b = stats[j1][j0].intercept(); ChartObjects.DrawLine("Segment-" + j0.ToString(), j0, a * j0 + b, j1, a * j1 + b, Colors.Aqua, 2, LineStyle.Solid); } }
public void draw() { readCSV(); ChartObjects.RemoveAllObjects(); foreach (Fields field in upcomingNews) { minutesToNews = (int)((field.newsTime - timeNow).TotalMinutes); if (field.impact == "High") { color = Colors.Red; } else if (field.impact == "Medium") { color = Colors.Orange; } else if (field.impact == "Low") { color = Colors.Yellow; } if (Symbol.Code.IndexOf(field.currency) == -1) { lineWidth = 1; } else { lineWidth = 2; } var hAlign = HorizontalAlignment.Left; ChartObjects.DrawText("text" + minutesToNews, field.newsTime + " " + field.detail, MarketSeries.Close.Count - 1, Symbol.Bid + (minutesToNews * Symbol.PipSize) / pipTime, VerticalAlignment.Top, hAlign, color); if (this.Positions.Count == 0) { ChartObjects.DrawText("Quiet Pairs", quietPairs, MarketSeries.Close.Count - 1, Symbol.Bid, VerticalAlignment.Bottom, hAlign, Colors.Aqua); } ChartObjects.DrawText("text2" + minutesToNews, field.newsTime + " " + field.detail, MarketSeries.Close.Count - 1, Symbol.Bid - (minutesToNews * Symbol.PipSize) / pipTime, VerticalAlignment.Bottom, hAlign, color); ChartObjects.DrawHorizontalLine("News " + minutesToNews, Symbol.Bid + (minutesToNews * Symbol.PipSize) / pipTime, color, lineWidth, LineStyle.Lines); ChartObjects.DrawHorizontalLine("News2 " + minutesToNews, Symbol.Bid - (minutesToNews * Symbol.PipSize) / pipTime, color, lineWidth, LineStyle.Lines); } }
protected override void Initialize() { //+------------------------------------------------ ExpiryDate = new DateTime(2018, 5, 18, 0, 0, 0); if (DateTime.Now > ExpiryDate) { ChartObjects.DrawText("TheText", Expired, StaticPosition.Center, Colors.Red); return; } //+------------------------------------------------ TheStart = DateTime.Parse(Cust_session_Start); ChartObjects.RemoveAllObjects(); //+--------------------------------------------------------------------------------+ }
private void UpdateLabels(bool fastUpdate) { ChartObjects.RemoveAllObjects(); int startIndex = fastUpdate ? Source.Count - 1000 : 0; int index; index = Source.Count - 2; while (index >= startIndex) { if (IsLocalExtremum(index, true)) { ChartObjects.DrawText("max_" + index, Source[index].ToString(format), index, Source[index], VerticalAlignment.Top, HorizontalAlignment.Center, color); index = index - Period; } else { index--; } } index = Source.Count - 2; while (index >= startIndex) { if (IsLocalExtremum(index, false)) { ChartObjects.DrawText("min_" + index, Source[index].ToString(format), index, Source[index], VerticalAlignment.Bottom, HorizontalAlignment.Center, color); index = index - Period; } else { index--; } } var lastIndex = Source.Count - 1; ChartObjects.DrawText("current", Source[lastIndex].ToString(format), lastIndex + 1, Source[lastIndex], VerticalAlignment.Center, HorizontalAlignment.Right, color); }
private void drawLines() { ChartObjects.RemoveAllObjects(); if (this.Positions.Find("Buy") != null && !modified) { if (recoveryMode) { ChartObjects.DrawHorizontalLine("TP", this.Positions[0].EntryPrice + tradeTP * Symbol.PipSize, Colors.Yellow, 2, LineStyle.Lines); } else { ChartObjects.DrawHorizontalLine("TP", this.Positions[0].EntryPrice + tradeTP * Symbol.PipSize, Colors.Green, 2, LineStyle.Lines); ChartObjects.DrawHorizontalLine("Recovery", this.Positions[0].EntryPrice + tradeTP / (1 + profitPercent / 100) * Symbol.PipSize, Colors.Yellow, 2, LineStyle.Lines); } } else if (this.Positions.Find("Sell") != null && !modified) { if (recoveryMode) { ChartObjects.DrawHorizontalLine("TP", this.Positions[0].EntryPrice - tradeTP * Symbol.PipSize, Colors.Yellow, 2, LineStyle.Lines); } else { ChartObjects.DrawHorizontalLine("TP", this.Positions[0].EntryPrice - tradeTP * Symbol.PipSize, Colors.Green, 2, LineStyle.Lines); ChartObjects.DrawHorizontalLine("Recovery", this.Positions[0].EntryPrice - tradeTP / (1 + profitPercent / 100) * Symbol.PipSize, Colors.Yellow, 2, LineStyle.Lines); } } if (this.Positions.Find("Buy") != null) { ChartObjects.DrawHorizontalLine("boxBottom", prevBoxBottom, Colors.Red, 2, LineStyle.Lines); } else if (this.Positions.Find("Sell") != null) { ChartObjects.DrawHorizontalLine("boxTop", prevBoxTop, Colors.Red, 2, LineStyle.Lines); } }
protected override void OnStop() { ChartObjects.RemoveAllObjects(); }
public override void Calculate(int index) { if (errorOccured) { ChartObjects.DrawText("errorlabel", "* Market Trading Clock *" + errorMsg, StaticPosition.TopCenter, Colors.Red); return; } var linePos = "\n\n"; // get all exhanges in display order var exchanges = from wq in widget.marketClocks.Exchanges orderby wq.DisplayOrder ascending select wq; // iterate through exchanges and draw objects onto chart Colors clockColor; foreach (var exchange in exchanges) { ChartObjects.DrawText("l_" + exchange.ExchangeName.ToString(), exchange.Label, widget.Position, clockColor = (exchange.IsOpen) ? widget.OpenColor : widget.ClosedColor); ChartObjects.DrawText("t_" + exchange.ExchangeName.ToString(), exchange.TimeLabel, widget.Position, clockColor = (exchange.IsOpen) ? widget.OpenColor : widget.ClosedColor); if (exchange.IsOpen) { ChartObjects.RemoveObject("mo_" + exchange.ExchangeName.ToString()); } } if (ShowTimeZonelabel) { if (IsLocalTimeZone) { ChartObjects.DrawText("tz", TimeZoneInfo.Local.DisplayName, StaticPosition.TopLeft, widget.OpenColor); } else { ChartObjects.DrawText("tz", "Exchange Local Time", StaticPosition.TopLeft, widget.OpenColor); } } // show exchange opening times when they are closed if user has chosen option. if (ShowOpeningTimes) { foreach (var exchange in exchanges.Where(x => x.IsOpen == false)) { if (exchange.ExchangeTime.DayOfWeek == DayOfWeek.Saturday || exchange.ExchangeTime.DayOfWeek == DayOfWeek.Sunday || exchange.ExchangeTime.DayOfWeek == DayOfWeek.Friday && exchange.ExchangeTime < exchange.Closses && exchange.ExchangeTime > exchange.Opens && exchange.ExchangeTime.DayOfWeek != DayOfWeek.Monday) { ChartObjects.DrawText("p_" + exchange.ExchangeName.ToString(), linePos + exchange.Label.Replace(exchange.ExchangeName, "Monday"), widget.Position, widget.OpenColor); } else { ChartObjects.DrawText("p_" + exchange.ExchangeName.ToString(), linePos + exchange.Label.Replace(exchange.ExchangeName, exchange.Opens.ToString(widget.marketClocks.ClockFormat)), widget.Position, widget.OpenColor); } } } // show exchange opening times when they are closed if user has chosen option. if (ShowClosingTimes) { foreach (var exchange in exchanges.Where(x => x.IsOpen)) { ChartObjects.DrawText("c_" + exchange.ExchangeName.ToString(), linePos + exchange.Label.Replace(exchange.ExchangeName, exchange.Closses.ToString(widget.marketClocks.ClockFormat)), widget.Position, widget.ClosedColor); } } // Play sound when market opens or closes try { if (exchanges.Any(x => x.MarketJustOpened())) { ChartObjects.RemoveAllObjects(); if (MarketAlert && MediaFile != string.Empty) { Notifications.PlaySound(MediaFile); } } } catch { // soft error continue showing clocks. ChartObjects.DrawText("errorlabel", errorMsg, StaticPosition.TopCenter, Colors.Red); Print("Market Trading Clock: " + "Media file path could be incorrect."); } // alert user just before market opens (value in mins set by user) returns exchange. if (AlertBeforeMarketOpens > 0) { if (ShowOpeningTimes) { linePos += "\n"; } IList <Exchange> ext = widget.marketClocks.IsMarketOpening(AlertBeforeMarketOpens); foreach (var ex in ext) { ChartObjects.DrawText("mo_" + ex.ExchangeName.ToString(), linePos + ex.Label.Replace(ex.ExchangeName, ex.OpeningMins()), StaticPosition.TopCenter, widget.OpenColor); } } // show message when market is closed for the weekend if (exchanges.All(x => x.IsOpen == false)) { if (this.Time.DayOfWeek == DayOfWeek.Saturday || this.Time.DayOfWeek == DayOfWeek.Sunday) { ChartObjects.DrawText("l8", string.Format("\n\n\n\n{0,40}", "- MARKETS CLOSED -"), StaticPosition.TopCenter, (Colors)Enum.Parse(typeof(Colors), OpenColor, true)); } } // FxPro inactivity message at midnight cyprus time. if (IsFxProBroker && widget.marketClocks.IsInactive(this.Server.Time)) { ChartObjects.DrawText("l8", string.Format("\n\n\n\n{0,60}", "- TRADING INACTIVE FOR 5 MINUTES -"), StaticPosition.TopCenter, (Colors)Enum.Parse(typeof(Colors), OpenColor, true)); } // debug //Print("FxPro Server Time: " + this.widget.FxProServerTime); //Print("local: " + exchanges.LastOrDefault().LocalTime.ToString()); //Print("opens: " + exchanges.LastOrDefault().Opens.ToString()); //Print("close: " + exchanges.LastOrDefault().Closses.ToString()); //Print("time offset from UTC: " + TimeZoneInfo.Local.BaseUtcOffset.Hours.ToString()); }
protected void onConnectionMessage(object sender, MessageReceivedEventArgs e) { string encoded = null; Message msg = new Message(); //ChartObjects.DrawText("meho", "ALL ARE WELCOME", StaticPosition.TopLeft, Colors.LimeGreen); //Print(Thread.CurrentThread.Name); switch (e.Message) { case Message.OPEN: Print("Connection allowed by the server"); msg.action = Message.FEED_CHANNELS; msg.channel = null; msg.data = null; encoded = JsonConvert.SerializeObject(msg); transport.Send(encoded.ToString()); break; case Message.HEARTBEAT: Print("Heartbeat"); break; default: dynamic d = JObject.Parse(e.Message); string action = d.action.ToString(); //Print(action.ToUpperInvariant()); switch (action) { case Message.FEED_CHANNELS: Print("FEED CHANNELS {0}", d.data); foreach (var channel in d.data) { msg.action = Message.CHANNEL_CONNECT; msg.data = channel; msg.channel = null; encoded = JsonConvert.SerializeObject(msg); transport.Send(encoded.ToString()); } break; case Message.CHANNEL_CONNECT: Print("CHANNEL CONNECTED {0}", d.channel.ToString()); msg.action = Message.FEED_SNAPSHOT; msg.channel = d.channel.ToString(); msg.data = MaxItems; encoded = JsonConvert.SerializeObject(msg); transport.Send(encoded.ToString()); break; case Message.FEED_INSERT: string channelo = d.channel.ToString(); switch (channelo) { case "twitter": int idx = 0; string sep = ""; string msgg = FormatTwitterMessage(d.data); messages.Insert(0, msgg); messages.RemoveAt(messages.Count - 1); Print("FEED INSERT FOR TWITTER {0}", msgg); ChartObjects.RemoveAllObjects(); foreach (string mmsg in messages) { ChartObjects.DrawText("meh" + (idx++), sep + mmsg, StaticPosition.TopLeft, Colors.LimeGreen); sep += FeedItemSeparator; } break; default: //Print("\t\tUNHANDLED channel {0}", channelo); break; } break; case Message.FEED_SNAPSHOT: Print("FEED SNAPSHOT for {0}", d.channel.ToString()); string chl = d.channel.ToString(); switch (chl) { case "twitter": int Index = 0; string Separatorr = ""; Print("SNASHOT TWITTER RECEIVED"); foreach (var item in d.data) { string NewsItem = FormatTwitterMessage(item); ChartObjects.RemoveObject("meh" + Index); ChartObjects.DrawText("meh" + (Index++), Separatorr + NewsItem.ToString(), StaticPosition.TopLeft, Colors.LimeGreen); Separatorr += FeedItemSeparator; messages.Insert(0, NewsItem); Print("TWITTER SNAPSHOT ITEM {0} - {1}", Index, NewsItem); } break; default: //Print("\t\tUNHANDLED channel {0}", chl); break; } break; default: string chal = d.channel.ToString(); //Print("\tUNHANDLED action {0} for channel {1}", action, chal); break; } break; } }
public override void Calculate(int index) { if (index <= 1) { Pivot[index] = 0; return; } if (_currentTimeFrame == Timeframe.na) { _currentTimeFrame = GetTimeFrame(index); } if (_currentTimeFrame == Timeframe.na) { Pivot[index] = 0; return; } bool daily = _currentTimeFrame < Timeframe.D1 && _showDailyPivots; bool weekly = _currentTimeFrame < Timeframe.W1 && _showWeeklyPivots; bool monthly = _currentTimeFrame < Timeframe.M1 && _showMonthlyPivots; if (!(daily || weekly || monthly)) { ChartObjects.DrawText("msg", "Incorrect Timeframe selection", StaticPosition.TopLeft, Colors.Red); return; } ChartObjects.RemoveAllObjects(); int currentDay = MarketSeries.OpenTime[index].Day; int previousDay = MarketSeries.OpenTime[index - 1].Day; DayOfWeek currentDayWk = MarketSeries.OpenTime[index].DayOfWeek; bool sameDay = currentDay == previousDay; bool calculateValues = Pivot[index - 1] == Pivot[index - 2] && !sameDay && (daily && currentDayWk != DayOfWeek.Saturday || weekly && currentDayWk == DayOfWeek.Monday || monthly && currentDay == 1); if (!calculateValues) { // Same values for the day Pivot[index] = Pivot[index - 1]; R1[index] = R1[index - 1]; S1[index] = S1[index - 1]; // Display additional pivots according to user input if (NoPiv >= 2) { R2[index] = R2[index - 1]; S2[index] = S2[index - 1]; } if (NoPiv >= 3) { R3[index] = R3[index - 1]; S3[index] = S3[index - 1]; } // Set high & low for next cycle if (MarketSeries.High[index] > _high) { _high = MarketSeries.High[index]; } if (MarketSeries.Low[index] < _low) { _low = MarketSeries.Low[index]; } } //if (calculateValues) else { _close = MarketSeries.Close[index - 1]; CalculatePivots(index); // reset high & low _high = double.MinValue; _low = double.MaxValue; } }