add support for plot labels for chart indicator lines

cleanup
This commit is contained in:
Gunther Schulz
2020-04-30 18:25:01 +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 <StringToEnumInt.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
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;
+7 -5
View File
@@ -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());
}