add support for plot labels for chart indicator lines

cleanup
This commit is contained in:
Gunther Schulz
2020-04-30 18:55:49 +02:00
parent 2c77099430
commit de6b4f0546
2 changed files with 9 additions and 12 deletions
+2 -7
View File
@@ -32,11 +32,6 @@
#include <Json.mqh> #include <Json.mqh>
#include <StringToEnumInt.mqh> #include <StringToEnumInt.mqh>
#include <ControlErrors.mqh> #include <ControlErrors.mqh>
//#include <ChartObjects\ChartObject.mqh>
//#include<Canvas\Canvas.mqh>
//#include <Graphics\Graphic.mqh>
// Starts an Expert Advisor with specified parameters
//#include <Expert.mqh>
// Set ports and host for ZeroMQ // Set ports and host for ZeroMQ
string HOST="*"; string HOST="*";
@@ -274,7 +269,6 @@ void StreamPriceData(){
string symbol=symbolSubscriptions[i].symbol; string symbol=symbolSubscriptions[i].symbol;
string chartTF=symbolSubscriptions[i].chartTf; string chartTF=symbolSubscriptions[i].chartTf;
datetime lastBar=symbolSubscriptions[i].lastBar; datetime lastBar=symbolSubscriptions[i].lastBar;
//Print(symbol," ", chartTF," ",lastBar);
CJAVal Data; CJAVal Data;
ENUM_TIMEFRAMES period = GetTimeframe(chartTF); ENUM_TIMEFRAMES period = GetTimeframe(chartTF);
@@ -676,6 +670,7 @@ void AddChartIndicator(CJAVal &dataObject){
string chartIndicatorId=dataObject["indicatorChartId"].ToStr(); string chartIndicatorId=dataObject["indicatorChartId"].ToStr();
int chartIndicatorSubWindow=dataObject["chartIndicatorSubWindow"].ToInt(); int chartIndicatorSubWindow=dataObject["chartIndicatorSubWindow"].ToInt();
string shortname = dataObject["style"]["shortname"].ToStr(); string shortname = dataObject["style"]["shortname"].ToStr();
string linelabel = dataObject["style"]["linelabel"].ToStr();
string colorstyle = dataObject["style"]["color"].ToStr(); string colorstyle = dataObject["style"]["color"].ToStr();
string linetype = dataObject["style"]["linetype"].ToStr(); string linetype = dataObject["style"]["linetype"].ToStr();
string linestyle = dataObject["style"]["linestyle"].ToStr(); string linestyle = dataObject["style"]["linestyle"].ToStr();
@@ -684,7 +679,7 @@ void AddChartIndicator(CJAVal &dataObject){
int idx = GetChartWindowIdxByChartWindowId(chartIdStr); int idx = GetChartWindowIdxByChartWindowId(chartIdStr);
long ChartId = chartWindows[idx].id; 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)){ if(ChartIndicatorAdd(ChartId, chartIndicatorSubWindow, chartIndicatorHandle)){
chartWindows[idx].indicatorId = chartIndicatorId; chartWindows[idx].indicatorId = chartIndicatorId;
+6 -4
View File
@@ -23,6 +23,7 @@ Socket chartSubscriptionSocket(context,ZMQ_SUB);
//--- input parameters //--- input parameters
input string IndicatorId=""; input string IndicatorId="";
input string ShortName="JsonAPI"; input string ShortName="JsonAPI";
input string LineLabel="Value";
input string ColorSyle = "clrRed"; input string ColorSyle = "clrRed";
input string LineType = "DRAW_LINE"; input string LineType = "DRAW_LINE";
input string LineStyle = "STYLE_SOLID"; input string LineStyle = "STYLE_SOLID";
@@ -53,18 +54,20 @@ int OnInit()
//--- indicator buffers mapping; //--- indicator buffers mapping;
ArraySetAsSeries(Buffer,true); ArraySetAsSeries(Buffer,true);
SetIndexBuffer(0,Buffer,INDICATOR_DATA); SetIndexBuffer(0,Buffer,INDICATOR_DATA);
SetIndexBuffer(1,Buffer,INDICATOR_CALCULATIONS);
color colorstyle = StringToColor(ColorSyle); color colorstyle = StringToColor(ColorSyle);
int linetype = StringToEnumInt(LineType); int linetype = StringToEnumInt(LineType);
int linestyle = StringToEnumInt(LineStyle); int linestyle = StringToEnumInt(LineStyle);
SetStyle(ShortName, colorstyle, linetype, linestyle, LineWidth); SetStyle(ShortName, LineLabel, colorstyle, linetype, linestyle, LineWidth);
//--- //---
return(INIT_SUCCEEDED); 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); IndicatorSetString(INDICATOR_SHORTNAME,shortname);
PlotIndexSetString(0,PLOT_LABEL,linelabel);
PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colorstyle); PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,colorstyle);
PlotIndexSetInteger(0,PLOT_DRAW_TYPE,linetype); PlotIndexSetInteger(0,PLOT_DRAW_TYPE,linetype);
PlotIndexSetInteger(0,PLOT_LINE_STYLE,linestyle); PlotIndexSetInteger(0,PLOT_LINE_STYLE,linestyle);
@@ -145,8 +148,7 @@ void CheckMessages(){
// Request recived // Request recived
if(chartMsg.size()>0){ if(chartMsg.size()>0){
// Handle subscription SubscriptionHandler(). // Handle subscription SubscriptionHandler()
Print(chartMsg.getData());
SubscriptionHandler(chartMsg); SubscriptionHandler(chartMsg);
ChartRedraw(ChartID()); ChartRedraw(ChartID());
} }