// Profitabul Levels for Quantower // // Draws your Profitabul key levels (call wall, put wall, zero gamma, max gamma strike, // key gamma level) on the chart and refreshes them every minute. // // Install: in Quantower, open the Algo Lab (or Visual Studio with the Quantower // indicator template), create an indicator project, replace its class with this // file and build it. Then add "Profitabul Levels" to a chart and paste an API // key from Profitabul, Settings > Integrations (a read-only key is enough). // // Uses GET https://compute.profitabul.ai/v1/plugin/levels?symbol=, // which answers one "label,price" line per level. using System; using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.Net.Http; using System.Threading.Tasks; using TradingPlatform.BusinessLayer; namespace ProfitabulLevels { public class ProfitabulLevels : Indicator { private static readonly HttpClient Http = new HttpClient { Timeout = TimeSpan.FromSeconds(15) }; [InputParameter("API key (Settings > Integrations)", 0)] public string ApiKey = string.Empty; [InputParameter("Symbol override (empty = chart symbol)", 1)] public string SymbolOverride = string.Empty; [InputParameter("Refresh (seconds)", 2, 30, 3600, 10, 0)] public int RefreshSeconds = 60; [InputParameter("Call wall color", 3)] public Color CallWallColor = Color.LimeGreen; [InputParameter("Put wall color", 4)] public Color PutWallColor = Color.Red; [InputParameter("Other levels color", 5)] public Color OtherColor = Color.Gold; public string ApiBaseUrl = "https://compute.profitabul.ai"; private readonly object sync = new object(); private List> levels = new List>(); private DateTime lastFetchUtc = DateTime.MinValue; private bool fetching; private readonly Font font = new Font("Arial", 9); public ProfitabulLevels() { Name = "Profitabul Levels"; Description = "Profitabul key levels: call wall, put wall, zero gamma, max gamma strike and key gamma level."; SeparateWindow = false; } protected override void OnUpdate(UpdateArgs args) { if (fetching || (DateTime.UtcNow - lastFetchUtc).TotalSeconds < Math.Max(30, RefreshSeconds)) return; fetching = true; lastFetchUtc = DateTime.UtcNow; Task.Run(FetchAsync); } private string RootSymbol() { if (!string.IsNullOrWhiteSpace(SymbolOverride)) return SymbolOverride.Trim().ToUpperInvariant(); string name = (Symbol?.Root ?? Symbol?.Name ?? string.Empty).ToUpperInvariant(); switch (name) { case "MNQ": return "NQ"; case "MES": return "ES"; case "M2K": return "RTY"; case "MGC": return "GC"; default: return name; } } private async Task FetchAsync() { try { if (string.IsNullOrWhiteSpace(ApiKey)) return; string url = ApiBaseUrl.TrimEnd('/') + "/v1/plugin/levels?symbol=" + Uri.EscapeDataString(RootSymbol()); using (var request = new HttpRequestMessage(HttpMethod.Get, url)) { request.Headers.TryAddWithoutValidation("Authorization", "Bearer " + ApiKey.Trim()); request.Headers.TryAddWithoutValidation("User-Agent", "Profitabul-Quantower/1.0"); using (var response = await Http.SendAsync(request).ConfigureAwait(false)) { if (!response.IsSuccessStatusCode) return; string body = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var parsed = new List>(); foreach (string raw in body.Split('\n')) { string line = raw.Trim(); if (line.Length == 0 || line.StartsWith("#")) continue; int comma = line.LastIndexOf(','); if (comma > 0 && double.TryParse(line.Substring(comma + 1), NumberStyles.Float, CultureInfo.InvariantCulture, out double price)) parsed.Add(new KeyValuePair(line.Substring(0, comma), price)); } lock (sync) levels = parsed; } } } catch { // Keep the last levels on a failed refresh. } finally { fetching = false; } } public override void OnPaintChart(PaintChartEventArgs args) { base.OnPaintChart(args); if (CurrentChart == null) return; List> snapshot; lock (sync) snapshot = new List>(levels); Graphics graphics = args.Graphics; var window = CurrentChart.MainWindow; Rectangle area = args.Rectangle; foreach (var level in snapshot) { Color color = level.Key == "Call wall" ? CallWallColor : level.Key == "Put wall" ? PutWallColor : OtherColor; float y = (float)window.CoordinatesConverter.GetChartY(level.Value); if (y < area.Top || y > area.Bottom) continue; using (var pen = new Pen(color, 2) { DashStyle = System.Drawing.Drawing2D.DashStyle.Dash }) using (var brush = new SolidBrush(color)) { graphics.DrawLine(pen, area.Left, y, area.Right, y); string label = level.Key + " " + level.Value.ToString("0.##", CultureInfo.InvariantCulture); SizeF size = graphics.MeasureString(label, font); graphics.DrawString(label, font, brush, area.Right - size.Width - 60, y - size.Height - 1); } } } } }