//+------------------------------------------------------------------+ //| StartIndicator.mqh | //| Gunther Schulz | //| https://github.com/khramkov/MQL5-JSON-API | //+------------------------------------------------------------------+ #property copyright "Gunther Schulz" #property link "https://github.com/khramkov/MQL5-JSON-API" #define START_INDICATOR true int INDICATOR_DATA_PORT=15559; Socket indicatorDataSocket(context,ZMQ_PUSH); struct Indicator { long id; // Internal id string indicatorId; // UUID int indicatorHandle; // Internal id/handle int indicatorParamCount; // Number of parameters to be passed to the indicator int indicatorBufferCount; // Numnber of buffers to be returned bythe indicator }; Indicator indicators[]; int indicatorCount = 0; //+------------------------------------------------------------------+ //| Check if string is a representation of a number | //+------------------------------------------------------------------+ bool IsNumberAsString(string str) { // MQL5 seems to return true if the values are the same, no matter the data type, in this case comparing str and dbl/int. // (str "2.1" == double 2.1) will return true. double dbl = StringToDouble(str); int integer = StringToInteger(str); // Compaing to both int and double to cover both cases if(str==dbl || str==integer) return true; else return false; } //+------------------------------------------------------------------+ //| Get index of indicator handler array by indicator id string | //+------------------------------------------------------------------+ int GetIndicatorIdxByIndicatorId(string indicatorId) { for(int i=0; i= 0) { if(CopyBuffer(indicators[idx].indicatorHandle, i, fromDate, 1, values) < 0) { if(mControl.mGetLastError()) { CJAVal message; int lastError = mControl.mGetLastError(); string desc = mControl.mGetDesc(); mControl.Check(); message["error"]=(bool) true; message["lastError"]=(string) lastError; message["description"]=desc; message["function"]=(string) __FUNCTION__; string t=message.Serialize(); if(debug) Print(t); InformClientSocket(indicatorDataSocket,t); } } results[i] = DoubleToString(values[0]); } } CJAVal message; message["error"]=(bool) false; message["id"] = (string) id; message["data"].Set(results); string t=message.Serialize(); if(debug) Print(t); InformClientSocket(indicatorDataSocket,t); } //+------------------------------------------------------------------+