From de6b4f054651734ff53a9c5043de597fa49b753c Mon Sep 17 00:00:00 2001 From: Gunther Schulz Date: Thu, 30 Apr 2020 18:25:01 +0200 Subject: [PATCH] add support for plot labels for chart indicator lines cleanup --- Experts/JsonAPI.mq5 | 9 ++------- Indicators/JsonAPIIndicator.mq5 | 12 +++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/Experts/JsonAPI.mq5 b/Experts/JsonAPI.mq5 index aca5741..3ba75f4 100644 --- a/Experts/JsonAPI.mq5 +++ b/Experts/JsonAPI.mq5 @@ -32,11 +32,6 @@ #include #include #include -//#include -//#include -//#include -// Starts an Expert Advisor with specified parameters -//#include // Set ports and host for ZeroMQ string HOST="*"; @@ -274,7 +269,6 @@ void StreamPriceData(){ string symbol=symbolSubscriptions[i].symbol; string chartTF=symbolSubscriptions[i].chartTf; datetime lastBar=symbolSubscriptions[i].lastBar; - //Print(symbol," ", chartTF," ",lastBar); CJAVal Data; ENUM_TIMEFRAMES period = GetTimeframe(chartTF); @@ -676,6 +670,7 @@ void AddChartIndicator(CJAVal &dataObject){ string chartIndicatorId=dataObject["indicatorChartId"].ToStr(); int chartIndicatorSubWindow=dataObject["chartIndicatorSubWindow"].ToInt(); string shortname = dataObject["style"]["shortname"].ToStr(); + string linelabel = dataObject["style"]["linelabel"].ToStr(); string colorstyle = dataObject["style"]["color"].ToStr(); string linetype = dataObject["style"]["linetype"].ToStr(); string linestyle = dataObject["style"]["linestyle"].ToStr(); @@ -684,7 +679,7 @@ void AddChartIndicator(CJAVal &dataObject){ int idx = GetChartWindowIdxByChartWindowId(chartIdStr); long ChartId = chartWindows[idx].id; - double chartIndicatorHandle = iCustom(ChartSymbol(ChartId),ChartPeriod(ChartId),"JsonAPIIndicator",chartIndicatorId,shortname,colorstyle,linetype,linestyle,linewidth); + double chartIndicatorHandle = iCustom(ChartSymbol(ChartId),ChartPeriod(ChartId),"JsonAPIIndicator",chartIndicatorId,shortname,linelabel,colorstyle,linetype,linestyle,linewidth); if(ChartIndicatorAdd(ChartId, chartIndicatorSubWindow, chartIndicatorHandle)){ chartWindows[idx].indicatorId = chartIndicatorId; diff --git a/Indicators/JsonAPIIndicator.mq5 b/Indicators/JsonAPIIndicator.mq5 index 2de3347..184a01f 100644 --- a/Indicators/JsonAPIIndicator.mq5 +++ b/Indicators/JsonAPIIndicator.mq5 @@ -22,7 +22,8 @@ Socket chartSubscriptionSocket(context,ZMQ_SUB); //--- input parameters input string IndicatorId=""; -input string ShortName="JsonAPI"; +input string ShortName="JsonAPI"; +input string LineLabel="Value"; input string ColorSyle = "clrRed"; input string LineType = "DRAW_LINE"; input string LineStyle = "STYLE_SOLID"; @@ -53,18 +54,20 @@ int OnInit() //--- indicator buffers mapping; ArraySetAsSeries(Buffer,true); SetIndexBuffer(0,Buffer,INDICATOR_DATA); + SetIndexBuffer(1,Buffer,INDICATOR_CALCULATIONS); color colorstyle = StringToColor(ColorSyle); int linetype = StringToEnumInt(LineType); int linestyle = StringToEnumInt(LineStyle); - SetStyle(ShortName, colorstyle, linetype, linestyle, LineWidth); + SetStyle(ShortName, LineLabel, colorstyle, linetype, linestyle, LineWidth); //--- return(INIT_SUCCEEDED); } -void SetStyle(string shortname, color colorstyle, int linetype, int linestyle, int linewidth) { +void SetStyle(string shortname, string linelabel, color colorstyle, int linetype, int linestyle, int linewidth) { IndicatorSetString(INDICATOR_SHORTNAME,shortname); + PlotIndexSetString(0,PLOT_LABEL,linelabel); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colorstyle); PlotIndexSetInteger(0,PLOT_DRAW_TYPE,linetype); PlotIndexSetInteger(0,PLOT_LINE_STYLE,linestyle); @@ -145,8 +148,7 @@ void CheckMessages(){ // Request recived if(chartMsg.size()>0){ - // Handle subscription SubscriptionHandler(). - Print(chartMsg.getData()); + // Handle subscription SubscriptionHandler() SubscriptionHandler(chartMsg); ChartRedraw(ChartID()); }