From 9c8ba497d019674cbfe27c5234b1e1798a7f1262 Mon Sep 17 00:00:00 2001 From: Viacheslav Demydiuk Date: Sun, 28 Jan 2024 16:19:37 +0200 Subject: [PATCH] MQL5: completed implement mql functions with new protocol --- mq5/MtApi5.mq5 | 6509 ++++++++++++------------------------------------ 1 file changed, 1606 insertions(+), 4903 deletions(-) diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5 index 93fe1fec..faaaab9a 100644 --- a/mq5/MtApi5.mq5 +++ b/mq5/MtApi5.mq5 @@ -7,6 +7,7 @@ #include #include #include +#include #import "MT5Connector.dll" bool initExpert(int expertHandle, int port, string& err); @@ -20,7 +21,7 @@ #import ///-------------------------------------------------------------------------------------- - bool sendIntResponse(int expertHandle, int response, string& err) +/* bool sendIntResponse(int expertHandle, int response, string& err) { return true; } @@ -113,7 +114,9 @@ bool getBooleanValue(int expertHandle, int paramIndex, bool& res, string& err) { return true; - } + } + +*/ //--------------------------------------------------------------------------------------- @@ -148,6 +151,9 @@ bool _is_ticks_locked = false; string PARAM_SEPARATOR = ";"; +typedef string (*TExecutionFunc)(); +//CHashMap cmd_handlers; + int OnInit() { int result = init(); @@ -413,76 +419,76 @@ int executeCommand() response = Execute_PositionGetSymbol(); break; case 8: //PositionSelect - Execute_PositionSelect(); + response = Execute_PositionSelect(); break; case 9: //PositionGetDouble - Execute_PositionGetDouble(); + response = Execute_PositionGetDouble(); break; case 10: //PositionGetInteger - Execute_PositionGetInteger(); + response =Execute_PositionGetInteger(); break; case 11: //PositionGetString - Execute_PositionGetString(); + response = Execute_PositionGetString(); break; case 12: //OrdersTotal - Execute_OrdersTotal(); + response = Execute_OrdersTotal(); break; case 13: //OrderGetTicket - Execute_OrderGetTicket(); + response = Execute_OrderGetTicket(); break; case 14: //OrderSelect - Execute_OrderSelect(); + response = Execute_OrderSelect(); break; case 15: //OrderGetDouble - Execute_OrderGetDouble(); + response = Execute_OrderGetDouble(); break; case 16: //OrderGetInteger - Execute_OrderGetInteger(); + response = Execute_OrderGetInteger(); break; case 17: //OrderGetString - Execute_OrderGetString(); + response = Execute_OrderGetString(); break; case 18: //HistorySelect - Execute_HistorySelect(); + response = Execute_HistorySelect(); break; case 19: //HistorySelectByPosition - Execute_HistorySelectByPosition(); + response = Execute_HistorySelectByPosition(); break; case 20: //HistoryOrderSelect - Execute_HistoryOrderSelect(); + response = Execute_HistoryOrderSelect(); break; case 21: //HistoryOrdersTotal - Execute_HistoryOrdersTotal(); + response = Execute_HistoryOrdersTotal(); break; case 22: //HistoryOrderGetTicket - Execute_HistoryOrderGetTicket(); + response = Execute_HistoryOrderGetTicket(); break; case 23: //HistoryOrderGetDouble - Execute_HistoryOrderGetDouble(); + response = Execute_HistoryOrderGetDouble(); break; case 24: //HistoryOrderGetInteger - Execute_HistoryOrderGetInteger(); + response = Execute_HistoryOrderGetInteger(); break; case 25: //HistoryOrderGetString - Execute_HistoryOrderGetString(); + response = Execute_HistoryOrderGetString(); break; case 26: //HistoryDealSelect - Execute_HistoryDealSelect(); + response = Execute_HistoryDealSelect(); break; case 27: //HistoryDealsTotal - Execute_HistoryDealsTotal(); + response = Execute_HistoryDealsTotal(); break; case 28: //HistoryDealGetTicket - Execute_HistoryDealGetTicket(); + response = Execute_HistoryDealGetTicket(); break; case 29: //HistoryDealGetDouble - Execute_HistoryDealGetDouble(); + response = Execute_HistoryDealGetDouble(); break; case 30: //HistoryDealGetInteger - Execute_HistoryDealGetInteger(); + response = Execute_HistoryDealGetInteger(); break; case 31: //HistoryDealGetString - Execute_HistoryDealGetString(); + response = Execute_HistoryDealGetString(); break; case 32: //AccountInfoDouble response = Execute_AccountInfoDouble(); @@ -494,400 +500,400 @@ int executeCommand() response = Execute_AccountInfoString(); break; case 35: //SeriesInfoInteger - Execute_SeriesInfoInteger(); + response = Execute_SeriesInfoInteger(); break; case 36: //Bars - Execute_Bars(); + response = Execute_Bars(); break; case 1036: //Bars2 - Execute_Bars2(); + response = Execute_Bars2(); break; case 37: //BarsCalculated - Execute_BarsCalculated(); + response = Execute_BarsCalculated(); break; case 40: //CopyBuffer - Execute_CopyBuffer(); + response = Execute_CopyBuffer(); break; case 1040: //CopyBuffer1 - Execute_CopyBuffer1(); + response = Execute_CopyBuffer1(); break; case 1140: //CopyBuffer2 - Execute_CopyBuffer2(); + response = Execute_CopyBuffer2(); break; case 41: //CopyRates - Execute_CopyRates(); + response = Execute_CopyRates(); break; case 1041: //CopyRates1 - Execute_CopyRates1(); + response = Execute_CopyRates1(); break; case 1141: //CopyRates2 - Execute_CopyRates2(); + response = Execute_CopyRates2(); break; case 42: //CopyTime - Execute_CopyTime(); + response = Execute_CopyTime(); break; case 1042: //CopyTime1 - Execute_CopyTime1(); + response = Execute_CopyTime1(); break; case 1142: //CopyTime2 - Execute_CopyTime2(); + response = Execute_CopyTime2(); break; case 43: //CopyOpen - Execute_CopyOpen(); + response = Execute_CopyOpen(); break; case 1043: //CopyOpen1 - Execute_CopyOpen1(); + response = Execute_CopyOpen1(); break; case 1143: //CopyOpen2 - Execute_CopyOpen2(); + response = Execute_CopyOpen2(); break; case 44: //CopyHigh - Execute_CopyHigh(); + response = Execute_CopyHigh(); break; case 1044: //CopyHigh1 - Execute_CopyHigh1(); + response = Execute_CopyHigh1(); break; case 1144: //CopyHigh2 - Execute_CopyHigh2(); + response = Execute_CopyHigh2(); break; case 45: //CopyLow - Execute_CopyLow(); + response = Execute_CopyLow(); break; case 1045: //CopyLow1 - Execute_CopyLow1(); + response = Execute_CopyLow1(); break; case 1145: //CopyLow2 - Execute_CopyLow2(); + response = Execute_CopyLow2(); break; case 46: //CopyClose - Execute_CopyClose(); + response = Execute_CopyClose(); break; case 1046: //CopyClose1 - Execute_CopyClose1(); + response = Execute_CopyClose1(); break; case 1146: //CopyClose2 - Execute_CopyClose2(); + response = Execute_CopyClose2(); break; case 47: //CopyTickVolume - Execute_CopyTickVolume(); + response = Execute_CopyTickVolume(); break; case 1047: //CopyTickVolume1 - Execute_CopyTickVolume1(); + response = Execute_CopyTickVolume1(); break; case 1147: //CopyTickVolume2 - Execute_CopyTickVolume2(); + response = Execute_CopyTickVolume2(); break; case 48: //CopyRealVolume - Execute_CopyRealVolume(); + response = Execute_CopyRealVolume(); break; case 1048: //CopyRealVolume1 - Execute_CopyRealVolume1(); + response = Execute_CopyRealVolume1(); break; case 1148: //CopyRealVolume2 - Execute_CopyRealVolume2(); + response = Execute_CopyRealVolume2(); break; case 49: //CopySpread - Execute_CopySpread(); + response = Execute_CopySpread(); break; case 1049: //CopySpread1 - Execute_CopySpread1(); + response = Execute_CopySpread1(); break; case 1149: //CopySpread2 - Execute_CopySpread2(); + response = Execute_CopySpread2(); break; case 50: //SymbolsTotal - Execute_SymbolsTotal(); + response = Execute_SymbolsTotal(); break; case 51: //SymbolName - Execute_SymbolName(); + response = Execute_SymbolName(); break; case 52: //SymbolSelect - Execute_SymbolSelect(); + response = Execute_SymbolSelect(); break; case 53: //SymbolIsSynchronized - Execute_SymbolIsSynchronized(); + response = Execute_SymbolIsSynchronized(); break; case 54: //SymbolInfoDouble - Execute_SymbolInfoDouble(); + response = Execute_SymbolInfoDouble(); break; case 55: //SymbolInfoInteger - Execute_SymbolInfoInteger(); + response = Execute_SymbolInfoInteger(); break; case 56: //SymbolInfoString - Execute_SymbolInfoString(); + response = Execute_SymbolInfoString(); break; // case 57: //SymbolInfoTick // break; case 58: //SymbolInfoSessionQuote - Execute_SymbolInfoSessionQuote(); + response = Execute_SymbolInfoSessionQuote(); break; case 59: //SymbolInfoSessionTrade - Execute_SymbolInfoSessionTrade(); + response = Execute_SymbolInfoSessionTrade(); break; case 60: //MarketBookAdd - Execute_MarketBookAdd(); + response = Execute_MarketBookAdd(); break; case 61: //MarketBookRelease - Execute_MarketBookRelease(); + response = Execute_MarketBookRelease(); break; // case 62: //MarketBookGet // break; case 65: //PositionOpen - Execute_PositionOpen(false); + response = Execute_PositionOpen(false); break; // case 1065: //PositionOpenWithResult // Execute_PositionOpen(true); // break; case 6066: //PositionModify - Execute_PositionModify(); + response = Execute_PositionModify(); break; case 6067: //PositionClosePartial_bySymbol - Execute_PositionClosePartial_bySymbol(); + response = Execute_PositionClosePartial_bySymbol(); break; case 6068: //Execute_PositionClosePartial_byTicket - Execute_PositionClosePartial_byTicket(); + response = Execute_PositionClosePartial_byTicket(); break; case 66: //BacktestingReady - Execute_BacktestingReady(); + response = Execute_BacktestingReady(); break; case 67: //IsTesting - Execute_IsTesting(); + response = Execute_IsTesting(); break; case 68: //Print - Execute_Print(); + response = Execute_Print(); break; case 69: //PositionSelectByTicket - Execute_PositionSelectByTicket(); + response = Execute_PositionSelectByTicket(); break; case 70: //ObjectCreate - Execute_ObjectCreate(); + response = Execute_ObjectCreate(); break; case 71: //ObjectName - Execute_ObjectName(); + response = Execute_ObjectName(); break; case 72: //ObjectDelete - Execute_ObjectDelete(); + response = Execute_ObjectDelete(); break; case 73: //ObjectsDeleteAll - Execute_ObjectsDeleteAll(); + response = Execute_ObjectsDeleteAll(); break; case 74: //ObjectFind - Execute_ObjectFind(); + response = Execute_ObjectFind(); break; case 75: //ObjectGetTimeByValue - Execute_ObjectGetTimeByValue(); + response = Execute_ObjectGetTimeByValue(); break; case 76: //ObjectGetValueByTime - Execute_ObjectGetValueByTime(); + response = Execute_ObjectGetValueByTime(); break; case 77: //ObjectMove - Execute_ObjectMove(); + response = Execute_ObjectMove(); break; case 78: //ObjectsTotal - Execute_ObjectsTotal(); + response = Execute_ObjectsTotal(); break; case 79: //ObjectGetDouble - Execute_ObjectGetDouble(); + response = Execute_ObjectGetDouble(); break; case 80: //ObjectGetInteger - Execute_ObjectGetInteger(); + response = Execute_ObjectGetInteger(); break; case 81: //ObjectGetString - Execute_ObjectGetString(); + response = Execute_ObjectGetString(); break; case 82: //ObjectSetDouble - Execute_ObjectSetDouble(); + response = Execute_ObjectSetDouble(); break; case 83: //ObjectSetInteger - Execute_ObjectSetInteger(); + response = Execute_ObjectSetInteger(); break; case 84: //ObjectSetString - Execute_ObjectSetString(); + response = Execute_ObjectSetString(); break; case 88: //iAC - Execute_iAC(); + response = Execute_iAC(); break; case 89: //iAD - Execute_iAD(); + response = Execute_iAD(); break; case 90: //iADX - Execute_iADX(); + response = Execute_iADX(); break; case 91: //iADXWilder - Execute_iADXWilder(); + response = Execute_iADXWilder(); break; case 92: //iAlligator - Execute_iAlligator(); + response = Execute_iAlligator(); break; case 93: //iAMA - Execute_iAMA(); + response = Execute_iAMA(); break; case 94: //iAO - Execute_iAO(); + response = Execute_iAO(); break; case 95: //iATR - Execute_iATR(); + response = Execute_iATR(); break; case 96: //iBearsPower - Execute_iBearsPower(); + response = Execute_iBearsPower(); break; case 97: //iBands - Execute_iBands(); + response = Execute_iBands(); break; case 98: //iBullsPower - Execute_iBullsPower(); + response = Execute_iBullsPower(); break; case 99: //iCCI - Execute_iCCI(); + response = Execute_iCCI(); break; case 100: //iChaikin - Execute_iChaikin(); + response = Execute_iChaikin(); break; // case 101: //iCustom // break; case 102: //iDEMA - Execute_iDEMA(); + response = Execute_iDEMA(); break; case 103: //iDeMarker - Execute_iDeMarker(); + response = Execute_iDeMarker(); break; case 104: //iEnvelopes - Execute_iEnvelopes(); + response = Execute_iEnvelopes(); break; case 105: //iForce - Execute_iForce(); + response = Execute_iForce(); break; case 106: //iFractals - Execute_iFractals(); + response = Execute_iFractals(); break; case 107: //iFrAMA - Execute_iFrAMA(); + response = Execute_iFrAMA(); break; case 108: //iGator - Execute_iGator(); + response = Execute_iGator(); break; case 109: //iIchimoku - Execute_iIchimoku(); + response = Execute_iIchimoku(); break; case 110: //iBWMFI - Execute_iBWMFI(); + response = Execute_iBWMFI(); break; case 111: //iMomentum - Execute_iMomentum(); + response = Execute_iMomentum(); break; case 112: //iMFI - Execute_iMFI(); + response = Execute_iMFI(); break; case 113: //iMA - Execute_iMA(); + response = Execute_iMA(); break; case 114: //iOsMA - Execute_iOsMA(); + response = Execute_iOsMA(); break; case 115: //iMACD - Execute_iMACD(); + response = Execute_iMACD(); break; case 116: //iOBV - Execute_iOBV(); + response = Execute_iOBV(); break; case 117: //iSAR - Execute_iSAR(); + response = Execute_iSAR(); break; case 118: //iRSI - Execute_iRSI(); + response = Execute_iRSI(); break; case 119: //iRVI - Execute_iRVI(); + response = Execute_iRVI(); break; case 120: //iStdDev - Execute_iStdDev(); + response = Execute_iStdDev(); break; case 121: //iStochastic - Execute_iStochastic(); + response = Execute_iStochastic(); break; case 122: //iTEMA - Execute_iTEMA(); + response = Execute_iTEMA(); break; case 123: //iTriX - Execute_iTriX(); + response = Execute_iTriX(); break; case 124: //iWPR - Execute_iWPR(); + response = Execute_iWPR(); break; case 125: //iVIDyA - Execute_iVIDyA(); + response = Execute_iVIDyA(); break; case 126: //iVolumes - Execute_iVolumes(); + response = Execute_iVolumes(); break; case 127: //TimeCurrent - Execute_TimeCurrent(); + response = Execute_TimeCurrent(); break; case 128: //TimeTradeServer - Execute_TimeTradeServer(); + response = Execute_TimeTradeServer(); break; case 129: //TimeLocal - Execute_TimeLocal(); + response = Execute_TimeLocal(); break; case 130: //TimeGMT - Execute_TimeGMT(); + response = Execute_TimeGMT(); break; case 131: //IndicatorRelease - Execute_IndicatorRelease(); + response = Execute_IndicatorRelease(); break; case 132: //GetLastError - Execute_GetLastError(); + response = Execute_GetLastError(); break; case 136: //Alert - Execute_Alert(); + response = Execute_Alert(); break; case 143: //ResetLastError - Execute_ResetLastError(); + response = Execute_ResetLastError(); break; case 146: //GlobalVariableCheck - Execute_GlobalVariableCheck(); + response = Execute_GlobalVariableCheck(); break; case 147: //GlobalVariableTime - Execute_GlobalVariableTime(); + response = Execute_GlobalVariableTime(); break; case 148: //GlobalVariableDel - Execute_GlobalVariableDel(); + response = Execute_GlobalVariableDel(); break; case 149: //GlobalVariableGet - Execute_GlobalVariableGet(); + response = Execute_GlobalVariableGet(); break; case 150: //GlobalVariableName - Execute_GlobalVariableName(); + response = Execute_GlobalVariableName(); break; case 151: //GlobalVariableSet - Execute_GlobalVariableSet(); + response = Execute_GlobalVariableSet(); break; case 152: //GlobalVariablesFlush - Execute_GlobalVariablesFlush(); + response = Execute_GlobalVariablesFlush(); break; case 153: //TerminalInfoString - Execute_TerminalInfoString(); + response = Execute_TerminalInfoString(); break; case 154: //GlobalVariableTemp - Execute_GlobalVariableTemp(); + response = Execute_GlobalVariableTemp(); break; case 156: //GlobalVariableSetOnCondition - Execute_GlobalVariableSetOnCondition(); + response = Execute_GlobalVariableSetOnCondition(); break; case 157: //GlobalVariablesDeleteAll - Execute_GlobalVariablesDeleteAll(); + response = Execute_GlobalVariablesDeleteAll(); break; case 158: //GlobalVariablesTotal - Execute_GlobalVariablesTotal(); + response = Execute_GlobalVariablesTotal(); break; case 159: //UnlockTiks - Execute_UnlockTicks(); + response = Execute_UnlockTicks(); break; case 160: //PositionCloseAll - Execute_PositionCloseAll(); + response = Execute_PositionCloseAll(); break; case 161: //TesterStop - Execute_TesterStop(); + response = Execute_TesterStop(); break; case 204: //TerminalInfoInteger Execute_TerminalInfoInteger(); @@ -896,97 +902,97 @@ int executeCommand() Execute_TerminalInfoDouble(); break; case 206: //ChartId - Execute_ChartId(); + response = Execute_ChartId(); break; case 207: //ChartRedraw - Execute_ChartRedraw(); + response = Execute_ChartRedraw(); break; case 236: //ChartApplyTemplate - Execute_ChartApplyTemplate(); + response = Execute_ChartApplyTemplate(); break; case 237: //ChartApplyTemplate - Execute_ChartSaveTemplate(); + response = Execute_ChartSaveTemplate(); break; case 238: //ChartWindowFind - Execute_ChartWindowFind(); + response = Execute_ChartWindowFind(); break; case 241: //ChartOpen - Execute_ChartOpen(); + response = Execute_ChartOpen(); break; case 242: //ChartFirst - Execute_ChartFirst(); + response = Execute_ChartFirst(); break; case 243: //ChartFirst - Execute_ChartNext(); + response = Execute_ChartNext(); break; case 244: //ChartClose - Execute_ChartClose(); + response = Execute_ChartClose(); break; case 245: //ChartFirst - Execute_ChartSymbol(); + response = Execute_ChartSymbol(); break; case 246: //ChartPeriod - Execute_ChartPeriod(); + response = Execute_ChartPeriod(); break; case 247: //ChartSetDouble - Execute_ChartSetDouble(); + response = Execute_ChartSetDouble(); break; case 248: //ChartSetInteger - Execute_ChartSetInteger(); + response = Execute_ChartSetInteger(); break; case 249: //ChartSetString - Execute_ChartSetString(); + response = Execute_ChartSetString(); break; case 250: //ChartGetDouble - Execute_ChartGetDouble(); + response = Execute_ChartGetDouble(); break; case 251: //ChartGetInteger - Execute_ChartGetInteger(); + response = Execute_ChartGetInteger(); break; case 252: //ChartGetString - Execute_ChartGetString(); + response = Execute_ChartGetString(); break; case 253: //ChartNavigate - Execute_ChartNavigate(); + response = Execute_ChartNavigate(); break; case 254: //ChartIndicatorDelete - Execute_ChartIndicatorDelete(); + response = Execute_ChartIndicatorDelete(); break; case 255: //ChartIndicatorName - Execute_ChartIndicatorName(); + response = Execute_ChartIndicatorName(); break; case 256: //ChartIndicatorsTotal - Execute_ChartIndicatorsTotal(); + response = Execute_ChartIndicatorsTotal(); break; case 257: //ChartWindowOnDropped - Execute_ChartWindowOnDropped(); + response = Execute_ChartWindowOnDropped(); break; case 258: //ChartPriceOnDropped - Execute_ChartPriceOnDropped(); + response = Execute_ChartPriceOnDropped(); break; case 259: //ChartTimeOnDropped - Execute_ChartTimeOnDropped(); + response = Execute_ChartTimeOnDropped(); break; case 260: //ChartXOnDropped - Execute_ChartXOnDropped(); + response = Execute_ChartXOnDropped(); break; case 261: //ChartYOnDropped - Execute_ChartYOnDropped(); + response = Execute_ChartYOnDropped(); break; case 262: //ChartSetSymbolPeriod - Execute_ChartSetSymbolPeriod(); + response = Execute_ChartSetSymbolPeriod(); break; case 263: //ChartScreenShot - Execute_ChartScreenShot(); + response = Execute_ChartScreenShot(); break; case 264: //WindowBarsPerChart - Execute_WindowBarsPerChart(); + response = Execute_WindowBarsPerChart(); break; case 280: //ChartIndicatorAdd - Execute_ChartIndicatorAdd(); + response = Execute_ChartIndicatorAdd(); break; case 281: //ChartIndicatorGet - Execute_ChartIndicatorGet(); + response = Execute_ChartIndicatorGet(); break; default: { @@ -999,9 +1005,7 @@ int executeCommand() if (response != "") { if (!sendResponse(ExpertHandle, response, _response_error)) - { - PrintResponseError("sendResponse", _response_error); \ - } + PrintFormat("[ERROR] response: %s", _response_error); } return (commandType); @@ -1026,44 +1030,16 @@ public: } }; -#define GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(get_func, argument_id, argument, func_name, argument_name) if (!get_func(ExpertHandle, argument_id, argument, _error)) \ - { \ - PrintParamError(func_name, argument_name, _error); \ - sendErrorResponse(ExpertHandle, -1, _error, _response_error); \ - return; \ - } \ - -#define GET_INT_VALUE(argument_id, argument, argument_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getIntValue, argument_id, argument, __FUNCTION__, argument_name) -#define GET_LONG_VALUE(argument_id, argument, argument_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getLongValue, argument_id, argument, __FUNCTION__, argument_name) -#define GET_STRING_VALUE(argument_id, argument, argument_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getStringValue, argument_id, argument, __FUNCTION__, argument_name) -#define GET_DOUBLE_VALUE(argument_id, argument, argument_name) GET_VALUE_OR_RETURN_WITH_SENDING_ERROR(getDoubleValue, argument_id, argument, __FUNCTION__, argument_name) - -#define SEND_RESPONSE_OR_PRINT_ERROR(send_func, response, cmd_name) if (!send_func(ExpertHandle, response, _response_error)) \ - { \ - PrintResponseError(cmd_name, _response_error); \ - } - -#define SEND_VOID_RESPONSE if (!sendVoidResponse(ExpertHandle, _response_error)) \ - { \ - PrintResponseError(__FUNCTION__, _response_error); \ - } - -#define SEND_INT_RESPONSE(response) SEND_RESPONSE_OR_PRINT_ERROR(sendIntResponse, response, __FUNCTION__) -#define SEND_LONG_RESPONSE(response) SEND_RESPONSE_OR_PRINT_ERROR(sendLongResponse, response, __FUNCTION__) -#define SEND_ULONG_RESPONSE(response) SEND_RESPONSE_OR_PRINT_ERROR(sendULongResponse, response, __FUNCTION__) -#define SEND_BOOL_RESPONSE(response) SEND_RESPONSE_OR_PRINT_ERROR(sendBooleanResponse, response, __FUNCTION__) -#define SEND_DOUBLE_RESPONSE(response) SEND_RESPONSE_OR_PRINT_ERROR(sendDoubleResponse, response, __FUNCTION__) -#define SEND_STRING_RESPONSE(response) SEND_RESPONSE_OR_PRINT_ERROR(sendStringResponse, response, __FUNCTION__) - #define PRINT_MSG_AND_RETURN_VALUE(msg,value) PrintFormat("%s: %s",__FUNCTION__,msg);return value - #define GET_JSON_PAYLOAD(json) auto_ptr json(GetJsonPayload()); if (json.p == NULL) { return CreateErrorResponse(-1, "Failed to get payload"); } #define CHECK_JSON_VALUE(json, name_value) if (json.p.getValue(name_value) == NULL) { PRINT_MSG_AND_RETURN_VALUE(StringFormat("failed to get %s from JSON!", name_value), CreateErrorResponse(-1, (StringFormat("Undefinded mandatory parameter %s", name_value)))); } #define GET_INT_JSON_VALUE(json, name_value, return_value) CHECK_JSON_VALUE(json, name_value); int return_value = json.p.getInt(name_value) +#define GET_UINT_JSON_VALUE(json, name_value, return_value) CHECK_JSON_VALUE(json, name_value); uint return_value = json.p.getInt(name_value) #define GET_DOUBLE_JSON_VALUE(json, name_value, return_value) CHECK_JSON_VALUE(json, name_value); double return_value = json.p.getDouble(name_value) #define GET_LONG_JSON_VALUE(json, name_value, return_value) CHECK_JSON_VALUE(json, name_value); long return_value = json.p.getLong(name_value) #define GET_ULONG_JSON_VALUE(json, name_value, return_value) CHECK_JSON_VALUE(json, name_value); ulong return_value = json.p.getLong(name_value) #define GET_STRING_JSON_VALUE(json, name_value, return_value) CHECK_JSON_VALUE(json, name_value); string return_value = json.p.getString(name_value) +#define GET_BOOL_JSON_VALUE(json, name_value, return_value) CHECK_JSON_VALUE(json, name_value); bool return_value = json.p.getBool(name_value) //------------------------------------------------------------- string Execute_GetQuote() { @@ -1080,10 +1056,7 @@ string Execute_Request() StringInit(request, 1000, 0); if (!getPayload(ExpertHandle, request, _error)) - { - PrintParamError("Request", "Request", _error); return CreateErrorResponse(-1, "Failed to get request"); - } string response = ""; if (request != "") @@ -1110,7 +1083,7 @@ JSONObject* GetJsonPayload() if (!getPayload(ExpertHandle, payload, _error)) { - PrintParamError("GetPayload", "GetPayload", _error); + PrintFormat("%s [ERROR]: %s", __FUNCTION__, _error); return NULL; } @@ -1355,166 +1328,78 @@ string Execute_HistoryOrderGetDouble() return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_HistoryOrderGetInteger() +string Execute_HistoryOrderGetInteger() { - ulong ticket_number; - int property_id; + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "TicketNumber", ticket_number); + GET_INT_JSON_VALUE(jo, "PropertyId", property_id); - if (!getULongValue(ExpertHandle, 0, ticket_number, _error)) - { - PrintParamError("HistoryOrderGetInteger", "ticket_number", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, property_id, _error)) - { - PrintParamError("HistoryOrderGetInteger", "property_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendLongResponse(ExpertHandle, HistoryOrderGetInteger(ticket_number, (ENUM_ORDER_PROPERTY_INTEGER)property_id), _response_error)) - { - PrintResponseError("HistoryOrderGetInteger", _response_error); - } + long result = HistoryOrderGetInteger(ticket_number, (ENUM_ORDER_PROPERTY_INTEGER)property_id); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_HistoryOrderGetString() +string Execute_HistoryOrderGetString() { - ulong ticket_number; - int property_id; + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "TicketNumber", ticket_number); + GET_INT_JSON_VALUE(jo, "PropertyId", property_id); - if (!getULongValue(ExpertHandle, 0, ticket_number, _error)) - { - PrintParamError("HistoryOrderGetString", "ticket_number", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, property_id, _error)) - { - PrintParamError("HistoryOrderGetString", "property_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendStringResponse(ExpertHandle, HistoryOrderGetString(ticket_number, (ENUM_ORDER_PROPERTY_STRING)property_id), _response_error)) - { - PrintResponseError("HistoryOrderGetString", _response_error); - } + string result = HistoryOrderGetString(ticket_number, (ENUM_ORDER_PROPERTY_STRING)property_id); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_HistoryDealSelect() +string Execute_HistoryDealSelect() { - ulong ticket; - - if (!getULongValue(ExpertHandle, 0, ticket, _error)) - { - PrintParamError("HistoryDealSelect", "ticket", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "Ticket", ticket); - if (!sendBooleanResponse(ExpertHandle, HistoryDealSelect(ticket), _response_error)) - { - PrintResponseError("HistoryDealSelect", _response_error); - } + bool result = HistoryDealSelect(ticket); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_HistoryDealsTotal() +string Execute_HistoryDealsTotal() { - if (!sendIntResponse(ExpertHandle, HistoryDealsTotal(), _response_error)) - { - PrintResponseError("HistoryDealsTotal", _response_error); - } + int result = HistoryDealsTotal(); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_HistoryDealGetTicket() +string Execute_HistoryDealGetTicket() { - uint index; + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "Index", index); - if (!getIntValue(ExpertHandle, 0, index, _error)) - { - PrintParamError("HistoryDealGetTicket", "index", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendULongResponse(ExpertHandle, HistoryDealGetTicket(index), _response_error)) - { - PrintResponseError("HistoryDealGetTicket", _response_error); - } + ulong result = HistoryDealGetTicket(index); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_HistoryDealGetDouble() +string Execute_HistoryDealGetDouble() { - ulong ticket_number; - int property_id; + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "TicketNumber", ticket_number); + GET_INT_JSON_VALUE(jo, "PropertyId", property_id); - if (!getULongValue(ExpertHandle, 0, ticket_number, _error)) - { - PrintParamError("HistoryDealGetDouble", "ticket_number", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, property_id, _error)) - { - PrintParamError("HistoryDealGetDouble", "property_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendDoubleResponse(ExpertHandle, HistoryDealGetDouble(ticket_number, (ENUM_DEAL_PROPERTY_DOUBLE)property_id), _response_error)) - { - PrintResponseError("HistoryDealGetDouble", _response_error); - } + double result = HistoryDealGetDouble(ticket_number, (ENUM_DEAL_PROPERTY_DOUBLE)property_id); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_HistoryDealGetInteger() +string Execute_HistoryDealGetInteger() { - ulong ticket_number; - int property_id; + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "TicketNumber", ticket_number); + GET_INT_JSON_VALUE(jo, "PropertyId", property_id); - if (!getULongValue(ExpertHandle, 0, ticket_number, _error)) - { - PrintParamError("HistoryDealGetInteger", "ticket_number", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, property_id, _error)) - { - PrintParamError("HistoryDealGetInteger", "property_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendLongResponse(ExpertHandle, HistoryDealGetInteger(ticket_number, (ENUM_DEAL_PROPERTY_INTEGER)property_id), _response_error)) - { - PrintResponseError("HistoryDealGetInteger", _response_error); - } + long result = HistoryDealGetInteger(ticket_number, (ENUM_DEAL_PROPERTY_INTEGER)property_id); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_HistoryDealGetString() +string Execute_HistoryDealGetString() { - ulong ticket_number; - int property_id; + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "TicketNumber", ticket_number); + GET_INT_JSON_VALUE(jo, "PropertyId", property_id); - if (!getULongValue(ExpertHandle, 0, ticket_number, _error)) - { - PrintParamError("HistoryDealGetString", "ticket_number", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, property_id, _error)) - { - PrintParamError("HistoryDealGetString", "property_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendStringResponse(ExpertHandle, HistoryDealGetString(ticket_number, (ENUM_DEAL_PROPERTY_STRING)property_id), _response_error)) - { - PrintResponseError("HistoryDealGetString", _response_error); - } + string result = HistoryDealGetString(ticket_number, (ENUM_DEAL_PROPERTY_STRING)property_id); + return CreateSuccessResponse(new JSONString(result)); } string Execute_AccountInfoDouble() @@ -1544,1837 +1429,798 @@ string Execute_AccountInfoString() return CreateSuccessResponse(new JSONString(result)); } -void Execute_SeriesInfoInteger() +string Execute_SeriesInfoInteger() { - string symbol; - int timeframe; - int prop_id; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SeriesInfoInteger", "property_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("SeriesInfoInteger", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, prop_id, _error)) - { - PrintParamError("SeriesInfoInteger", "prop_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendLongResponse(ExpertHandle, SeriesInfoInteger(symbol, (ENUM_TIMEFRAMES)timeframe, (ENUM_SERIES_INFO_INTEGER)prop_id), _response_error)) - { - PrintResponseError("SeriesInfoInteger", _response_error); - } + long result = SeriesInfoInteger(symbol, (ENUM_TIMEFRAMES)timeframe, (ENUM_SERIES_INFO_INTEGER)prop_id); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_Bars() +string Execute_Bars() { - string symbol; - int timeframe; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("Bars", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("Bars", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, Bars(symbol, (ENUM_TIMEFRAMES)timeframe), _response_error)) - { - PrintResponseError("Bars", _response_error); - } + int result = Bars(symbol, (ENUM_TIMEFRAMES)timeframe); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_Bars2() +string Execute_Bars2() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("Bars", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("Bars", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("Bars", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("Bars", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, Bars(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time), _response_error)) - { - PrintResponseError("Bars", _response_error); - } + int result = Bars(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_BarsCalculated() +string Execute_BarsCalculated() { - int indicator_handle; + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "IndicatorHandle", indicator_handle); - if (!getIntValue(ExpertHandle, 0, indicator_handle, _error)) - { - PrintParamError("BarsCalculated", "indicator_handle", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, BarsCalculated(indicator_handle), _response_error)) - { - PrintResponseError("BarsCalculated", _response_error); - } + int result = BarsCalculated(indicator_handle); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_CopyBuffer() +string Execute_CopyBuffer() { - int indicator_handle; - int buffer_num; - int start_pos; - int count; + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "IndicatorHandle", indicator_handle); + GET_INT_JSON_VALUE(jo, "BufferNum", buffer_num); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); + double buffer[]; - - if (!getIntValue(ExpertHandle, 0, indicator_handle, _error)) - { - PrintParamError("CopyBuffer", "indicator_handle", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, buffer_num, _error)) - { - PrintParamError("CopyBuffer", "buffer_num", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyBuffer", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyBuffer", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - int copied = CopyBuffer(indicator_handle, buffer_num, start_pos, count, buffer); - if (!sendDoubleArrayResponse(ExpertHandle, buffer, copied, _response_error)) - { - PrintResponseError("CopyBuffer", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(buffer[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyBuffer1() +string Execute_CopyBuffer1() { - int indicator_handle; - int buffer_num; - int start_time; - int count; - - if (!getIntValue(ExpertHandle, 0, indicator_handle, _error)) - { - PrintParamError("CopyBuffer", "indicator_handle", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, buffer_num, _error)) - { - PrintParamError("CopyBuffer", "buffer_num", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyBuffer", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyBuffer", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "IndicatorHandle", indicator_handle); + GET_INT_JSON_VALUE(jo, "BufferNum", buffer_num); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); double buffer[]; - int copied = CopyBuffer(indicator_handle, buffer_num, (datetime)start_time, count, buffer); + int copied = CopyBuffer(indicator_handle, buffer_num, start_time, count, buffer); - if (!sendDoubleArrayResponse(ExpertHandle, buffer, copied, _response_error)) - { - PrintResponseError("CopyBuffer", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(buffer[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyBuffer2() +string Execute_CopyBuffer2() { - int indicator_handle; - int buffer_num; - int start_time; - int stop_time; - - if (!getIntValue(ExpertHandle, 0, indicator_handle, _error)) - { - PrintParamError("CopyBuffer", "indicator_handle", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, buffer_num, _error)) - { - PrintParamError("CopyBuffer", "buffer_num", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyBuffer", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyBuffer", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "IndicatorHandle", indicator_handle); + GET_INT_JSON_VALUE(jo, "BufferNum", buffer_num); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + double buffer[]; - int copied = CopyBuffer(indicator_handle, buffer_num, (datetime)start_time, (datetime)stop_time, buffer); + int copied = CopyBuffer(indicator_handle, buffer_num, start_time, stop_time, buffer); - if (!sendDoubleArrayResponse(ExpertHandle, buffer, copied, _response_error)) - { - PrintResponseError("CopyBuffer", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(buffer[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyRates() +string Execute_CopyRates() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyRates", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyRates", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyRates", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyRates", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - MqlRates rates[]; - int copied = CopyRates(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, rates); - - if (!sendMqlRatesArrayResponse(ExpertHandle, rates, copied, _response_error)) - { - PrintResponseError("CopyRates", _response_error); - } -} - -void Execute_CopyRates1() -{ - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyRates", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyRates", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyRates", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyRates", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); MqlRates rates[]; - int copied = CopyRates(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, rates); - - if (!sendMqlRatesArrayResponse(ExpertHandle, rates, copied, _response_error)) - { - PrintResponseError("CopyRates", _response_error); - } + int copied = CopyRates(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, rates); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, MqlRatesToJson(rates[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyRates2() +string Execute_CopyRates1() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyRates", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyRates", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyRates", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyRates", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); MqlRates rates[]; - int copied = CopyRates(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, rates); - - if (!sendMqlRatesArrayResponse(ExpertHandle, rates, copied, _response_error)) - { - PrintResponseError("CopyRates", _response_error); - } + int copied = CopyRates(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, rates); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, MqlRatesToJson(rates[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyTime() +string Execute_CopyRates2() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + + MqlRates rates[]; + int copied = CopyRates(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, rates); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyTime", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyTime", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyTime", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyTime", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, MqlRatesToJson(rates[i])); + + return CreateSuccessResponse(jaresult); +} + +string Execute_CopyTime() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); datetime time_array[]; - int copied = CopyTime(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, time_array); + int copied = CopyTime(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, time_array); - if (!sendLongArrayResponse(ExpertHandle, time_array, copied, _response_error)) - { - PrintResponseError("CopyTime", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(time_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyTime1() +string Execute_CopyTime1() { - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyTime", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyTime", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyTime", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyTime", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); datetime time_array[]; - int copied = CopyTime(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, time_array); + int copied = CopyTime(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, time_array); - if (!sendLongArrayResponse(ExpertHandle, time_array, copied, _response_error)) - { - PrintResponseError("CopyTime", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(time_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyTime2() +string Execute_CopyTime2() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyTime", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyTime", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyTime", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyTime", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); datetime time_array[]; - int copied = CopyTime(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, time_array); - - if (!sendLongArrayResponse(ExpertHandle, time_array, copied, _response_error)) - { - PrintResponseError("CopyTime", _response_error); - } + int copied = CopyTime(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, time_array); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(time_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyOpen() +string Execute_CopyOpen() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyOpen", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyOpen", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyOpen", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyOpen", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - double open_array[]; - int copied = CopyOpen(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, open_array); - - if (!sendDoubleArrayResponse(ExpertHandle, open_array, copied, _response_error)) - { - PrintResponseError("CopyOpen", _response_error); - } -} - -void Execute_CopyOpen1() -{ - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyOpen", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyOpen", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyOpen", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyOpen", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); double open_array[]; - int copied = CopyOpen(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, open_array); + int copied = CopyOpen(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, open_array); - if (!sendDoubleArrayResponse(ExpertHandle, open_array, copied, _response_error)) - { - PrintResponseError("CopyOpen", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(open_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyOpen2() +string Execute_CopyOpen1() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyOpen", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyOpen", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyOpen", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyOpen", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); double open_array[]; - int copied = CopyOpen(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, open_array); - - if (!sendDoubleArrayResponse(ExpertHandle, open_array, copied, _response_error)) - { - PrintResponseError("CopyOpen", _response_error); - } + int copied = CopyOpen(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, open_array); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(open_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyHigh() +string Execute_CopyOpen2() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyHigh", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyHigh", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyHigh", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyHigh", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + + double open_array[]; + int copied = CopyOpen(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, open_array); + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(open_array[i])); + + return CreateSuccessResponse(jaresult); +} + +string Execute_CopyHigh() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); + double high_array[]; - int copied = CopyHigh(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, high_array); - - if (!sendDoubleArrayResponse(ExpertHandle, high_array, copied, _response_error)) - { - PrintResponseError("CopyHigh", _response_error); - } + int copied = CopyHigh(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, high_array); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(high_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyHigh1() +string Execute_CopyHigh1() { - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyHigh", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyHigh", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyHigh", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyHigh", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); + double high_array[]; int copied = CopyHigh(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, high_array); - if (!sendDoubleArrayResponse(ExpertHandle, high_array, copied, _response_error)) - { - PrintResponseError("CopyHigh", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(high_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyHigh2() +string Execute_CopyHigh2() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyHigh", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyHigh", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyHigh", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyHigh", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + double high_array[]; - int copied = CopyHigh(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, high_array); - - if (!sendDoubleArrayResponse(ExpertHandle, high_array, copied, _response_error)) - { - PrintResponseError("CopyHigh", _response_error); - } + int copied = CopyHigh(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, high_array); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(high_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyLow() +string Execute_CopyLow() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyLow", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyLow", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyLow", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyLow", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); + double low_array[]; - int copied = CopyLow(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, low_array); - - if (!sendDoubleArrayResponse(ExpertHandle, low_array, copied, _response_error)) - { - PrintResponseError("CopyLow", _response_error); - } -} - -void Execute_CopyLow1() -{ - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); + int copied = CopyLow(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, low_array); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyLow", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyLow", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyLow", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyLow", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - double low_array[]; - int copied = CopyLow(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, low_array); - - if (!sendDoubleArrayResponse(ExpertHandle, low_array, copied, _response_error)) - { - PrintResponseError("CopyLow", _response_error); - } -} - -void Execute_CopyLow2() -{ - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyLow", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyLow", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyLow", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyLow", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - double low_array[]; - int copied = CopyLow(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, low_array); - - if (!sendDoubleArrayResponse(ExpertHandle, low_array, copied, _response_error)) - { - PrintResponseError("CopyLow", _response_error); - } -} - -void Execute_CopyClose() -{ - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(low_array[i])); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyClose", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyClose", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyClose", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyClose", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - double close_array[]; - int copied = CopyClose(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, close_array); - - if (!sendDoubleArrayResponse(ExpertHandle, close_array, copied, _response_error)) - { - PrintResponseError("CopyClose", _response_error); - } + return CreateSuccessResponse(jaresult); } -void Execute_CopyClose1() +string Execute_CopyLow1() { - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyClose", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyClose", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyClose", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyClose", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - double close_array[]; - int copied = CopyClose(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, close_array); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); - if (!sendDoubleArrayResponse(ExpertHandle, close_array, copied, _response_error)) - { - PrintResponseError("CopyClose", _response_error); - } + double low_array[]; + int copied = CopyLow(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, low_array); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(low_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyClose2() +string Execute_CopyLow2() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyClose", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyClose", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyClose", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyClose", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - double close_array[]; - int copied = CopyClose(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, close_array); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); - if (!sendDoubleArrayResponse(ExpertHandle, close_array, copied, _response_error)) - { - PrintResponseError("CopyClose", _response_error); - } + double low_array[]; + int copied = CopyLow(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, low_array); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(low_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyTickVolume() +string Execute_CopyClose() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); + + double close_array[]; + int copied = CopyClose(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, close_array); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyTickVolume", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyTickVolume", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyTickVolume", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyTickVolume", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(close_array[i])); + + return CreateSuccessResponse(jaresult); +} + +string Execute_CopyClose1() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); + + double close_array[]; + int copied = CopyClose(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, close_array); + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(close_array[i])); + + return CreateSuccessResponse(jaresult); +} + +string Execute_CopyClose2() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + + double close_array[]; + int copied = CopyClose(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, close_array); + + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(close_array[i])); + + return CreateSuccessResponse(jaresult); +} + +string Execute_CopyTickVolume() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); + long volume_array[]; - int copied = CopyTickVolume(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, volume_array); + int copied = CopyTickVolume(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, volume_array); - if (!sendLongArrayResponse(ExpertHandle, volume_array, copied, _response_error)) - { - PrintResponseError("CopyTickVolume", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(volume_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyTickVolume1() +string Execute_CopyTickVolume1() { - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyTickVolume", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyTickVolume", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyTickVolume", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _response_error)) - { - PrintParamError("CopyTickVolume", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); + long volume_array[]; - int copied = CopyTickVolume(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, volume_array); + int copied = CopyTickVolume(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, volume_array); - if (!sendLongArrayResponse(ExpertHandle, volume_array, copied, _response_error)) - { - PrintResponseError("CopyTickVolume", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(volume_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyTickVolume2() +string Execute_CopyTickVolume2() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyTickVolume", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyTickVolume", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyTickVolume", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyTickVolume", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + long volume_array[]; int copied = CopyTickVolume(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, volume_array); - if (!sendLongArrayResponse(ExpertHandle, volume_array, copied, _response_error)) - { - PrintResponseError("CopyTickVolume", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(volume_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyRealVolume() +string Execute_CopyRealVolume() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyRealVolume", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyRealVolume", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopyRealVolume", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyRealVolume", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); + long volume_array[]; int copied = CopyRealVolume(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, volume_array); - if (!sendLongArrayResponse(ExpertHandle, volume_array, copied, _response_error)) - { - PrintResponseError("CopyRealVolume", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(volume_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyRealVolume1() +string Execute_CopyRealVolume1() { - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyRealVolume", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyRealVolume", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyRealVolume", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopyRealVolume", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); + long volume_array[]; - int copied = CopyRealVolume(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, volume_array); + int copied = CopyRealVolume(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, volume_array); - if (!sendLongArrayResponse(ExpertHandle, volume_array, copied, _response_error)) - { - PrintResponseError("CopyRealVolume", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(volume_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopyRealVolume2() +string Execute_CopyRealVolume2() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopyRealVolume", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopyRealVolume", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopyRealVolume", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopyRealVolume", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + long volume_array[]; - int copied = CopyRealVolume(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, volume_array); + int copied = CopyRealVolume(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, volume_array); - if (!sendLongArrayResponse(ExpertHandle, volume_array, copied, _response_error)) - { - PrintResponseError("CopyRealVolume", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(volume_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopySpread() +string Execute_CopySpread() { - string symbol; - int timeframe; - int start_pos; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopySpread", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopySpread", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_pos, _error)) - { - PrintParamError("CopySpread", "start_pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopySpread", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartPos", start_pos); + GET_INT_JSON_VALUE(jo, "Count", count); + int spread_array[]; int copied = CopySpread(symbol, (ENUM_TIMEFRAMES)timeframe, start_pos, count, spread_array); - if (!sendIntArrayResponse(ExpertHandle, spread_array, copied, _response_error)) - { - PrintResponseError("CopySpread", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(spread_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopySpread1() +string Execute_CopySpread1() { - string symbol; - int timeframe; - int start_time; - int count; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopySpread", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopySpread", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopySpread", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, count, _error)) - { - PrintParamError("CopySpread", "count", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "Count", count); int spread_array[]; - int copied = CopySpread(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, spread_array); + int copied = CopySpread(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, count, spread_array); - if (!sendIntArrayResponse(ExpertHandle, spread_array, copied, _response_error)) - { - PrintResponseError("CopySpread", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(spread_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_CopySpread2() +string Execute_CopySpread2() { - string symbol; - int timeframe; - int start_time; - int stop_time; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("CopySpread", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("CopySpread", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, start_time, _error)) - { - PrintParamError("CopySpread", "start_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, stop_time, _error)) - { - PrintParamError("CopySpread", "stop_time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); + GET_INT_JSON_VALUE(jo, "StartTime", start_time); + GET_INT_JSON_VALUE(jo, "StopTime", stop_time); + int spread_array[]; - int copied = CopySpread(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, spread_array); + int copied = CopySpread(symbol, (ENUM_TIMEFRAMES)timeframe, (datetime)start_time, (datetime)stop_time, spread_array); - if (!sendIntArrayResponse(ExpertHandle, spread_array, copied, _response_error)) - { - PrintResponseError("CopySpread", _response_error); - } + JSONArray* jaresult = new JSONArray(); + for(int i = 0; i < copied; i++) + jaresult.put(i, new JSONNumber(spread_array[i])); + + return CreateSuccessResponse(jaresult); } -void Execute_SymbolsTotal() +string Execute_SymbolsTotal() { - bool selected; - - if (!getBooleanValue(ExpertHandle, 0, selected, _error)) - { - PrintParamError("SymbolsTotal", "selected", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_BOOL_JSON_VALUE(jo, "Selected", selected); - if (!sendIntResponse(ExpertHandle, SymbolsTotal(selected), _error)) - { - PrintResponseError("SymbolsTotal", _response_error); - } + int result = SymbolsTotal(selected); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_SymbolName() +string Execute_SymbolName() { - bool selected; - int pos; + GET_JSON_PAYLOAD(jo); + GET_BOOL_JSON_VALUE(jo, "Selected", selected); + GET_INT_JSON_VALUE(jo, "Pos", pos); - if (!getIntValue(ExpertHandle, 0, pos, _error)) - { - PrintParamError("SymbolName", "pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getBooleanValue(ExpertHandle, 1, selected, _error)) - { - PrintParamError("SymbolName", "selected", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendStringResponse(ExpertHandle, SymbolName(pos, selected), _error)) - { - PrintResponseError("SymbolName", _response_error); - } + string result = SymbolName(pos, selected); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_SymbolSelect() +string Execute_SymbolSelect() { - string symbol; - bool select; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_BOOL_JSON_VALUE(jo, "Select", select); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolSelect", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getBooleanValue(ExpertHandle, 1, select, _error)) - { - PrintParamError("SymbolSelect", "select", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendBooleanResponse(ExpertHandle, SymbolSelect(symbol, select), _response_error)) - { - PrintResponseError("SymbolSelect", _response_error); - } + bool result = SymbolSelect(symbol, select); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_SymbolIsSynchronized() +string Execute_SymbolIsSynchronized() { - string symbol; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolIsSynchronized", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendBooleanResponse(ExpertHandle, SymbolIsSynchronized(symbol), _response_error)) - { - PrintResponseError("SymbolIsSynchronized", _response_error); - } + bool result = SymbolIsSynchronized(symbol); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_SymbolInfoDouble() +string Execute_SymbolInfoDouble() { - string symbol; - int prop_id; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolInfoDouble", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, prop_id, _error)) - { - PrintParamError("SymbolInfoDouble", "prop_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendDoubleResponse(ExpertHandle, SymbolInfoDouble(symbol, (ENUM_SYMBOL_INFO_DOUBLE)prop_id), _response_error)) - { - PrintResponseError("SymbolInfoDouble", _response_error); - } + double result = SymbolInfoDouble(symbol, (ENUM_SYMBOL_INFO_DOUBLE)prop_id); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_SymbolInfoInteger() +string Execute_SymbolInfoInteger() { - string symbol; - int prop_id; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolInfoInteger", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, prop_id, _error)) - { - PrintParamError("SymbolInfoInteger", "prop_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendLongResponse(ExpertHandle, SymbolInfoInteger(symbol, (ENUM_SYMBOL_INFO_INTEGER)prop_id), _response_error)) - { - PrintResponseError("SymbolInfoInteger", _response_error); - } + long result = SymbolInfoInteger(symbol, (ENUM_SYMBOL_INFO_INTEGER)prop_id); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_SymbolInfoString() +string Execute_SymbolInfoString() { - string symbol; - int prop_id; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolInfoString", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, prop_id, _error)) - { - PrintParamError("SymbolInfoString", "prop_id", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); - if (!sendStringResponse(ExpertHandle, SymbolInfoString(symbol, (ENUM_SYMBOL_INFO_STRING)prop_id), _response_error)) - { - PrintResponseError("SymbolInfoString", _response_error); - } + string result = SymbolInfoString(symbol, (ENUM_SYMBOL_INFO_STRING)prop_id); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_SymbolInfoSessionQuote() + // !!!!! TODO !!!!!! +string Execute_SymbolInfoSessionQuote() { - string symbol; - int day_of_week; - uint session_index; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "DayOfWeek", day_of_week); + GET_UINT_JSON_VALUE(jo, "SessionIndex", session_index); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolInfoSessionQuote", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, day_of_week, _error)) - { - PrintParamError("SymbolInfoSessionQuote", "day_of_week", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getUIntValue(ExpertHandle, 2, session_index, _error)) - { - PrintParamError("SymbolInfoSessionQuote", "session_index", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - datetime from; datetime to; - bool retVal = SymbolInfoSessionQuote(symbol, (ENUM_DAY_OF_WEEK)day_of_week, session_index, from, to); + bool ok = SymbolInfoSessionQuote(symbol, (ENUM_DAY_OF_WEEK)day_of_week, session_index, from, to); + + JSONObject* result_value_jo = new JSONObject(); + result_value_jo.put("RetVal", new JSONBool(ok)); + JSONObject* info_jo = new JSONObject(); + info_jo.put("From", new JSONNumber(from)); + info_jo.put("To", new JSONNumber(to)); + result_value_jo.put("Result", info_jo); - if (!sendStringResponse(ExpertHandle, ResultToString(retVal, from, to), _response_error)) - { - PrintResponseError("SymbolInfoSessionQuote", _response_error); - } + return CreateSuccessResponse(result_value_jo); } -void Execute_SymbolInfoSessionTrade() + // !!!!! TODO !!!!!! +string Execute_SymbolInfoSessionTrade() { - string symbol; - int day_of_week; - uint session_index; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "DayOfWeek", day_of_week); + GET_UINT_JSON_VALUE(jo, "SessionIndex", session_index); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("SymbolInfoSessionTrade", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, day_of_week, _error)) - { - PrintParamError("SymbolInfoSessionTrade", "day_of_week", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getUIntValue(ExpertHandle, 2, session_index, _error)) - { - PrintParamError("SymbolInfoSessionTrade", "session_index", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - datetime from; datetime to; - bool retVal = SymbolInfoSessionTrade(symbol, (ENUM_DAY_OF_WEEK)day_of_week, session_index, from, to); - - if (!sendStringResponse(ExpertHandle, ResultToString(retVal, from, to), _response_error)) - { - PrintResponseError("SymbolInfoSessionTrade", _response_error); - } -} - -void Execute_MarketBookAdd() -{ - string symbol; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("MarketBookAdd", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + bool ok = SymbolInfoSessionTrade(symbol, (ENUM_DAY_OF_WEEK)day_of_week, session_index, from, to); - if (!sendBooleanResponse(ExpertHandle, MarketBookAdd(symbol), _response_error)) - { - PrintResponseError("MarketBookAdd", _response_error); - } + JSONObject* result_value_jo = new JSONObject(); + result_value_jo.put("RetVal", new JSONBool(ok)); + JSONObject* info_jo = new JSONObject(); + info_jo.put("From", new JSONNumber(from)); + info_jo.put("To", new JSONNumber(to)); + result_value_jo.put("Result", info_jo); + + return CreateSuccessResponse(result_value_jo); } -void Execute_MarketBookRelease() +string Execute_MarketBookAdd() { - string symbol; - StringInit(symbol, 100, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("MarketBookRelease", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendBooleanResponse(ExpertHandle, MarketBookRelease(symbol), _response_error)) - { - PrintResponseError("MarketBookRelease", _response_error); - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + + bool result = MarketBookAdd(symbol); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_PositionModify() +string Execute_MarketBookRelease() { - ulong ticket; - double sl; - double tp; - - if (!getULongValue(ExpertHandle, 0, ticket, _error)) - { - PrintParamError("PositionModify", "ticket", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 1, sl, _error)) - { - PrintParamError("PositionModify", "sl", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 2, tp, _error)) - { - PrintParamError("PositionModify", "tp", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + + bool result = MarketBookRelease(symbol); + return CreateSuccessResponse(new JSONBool(result)); +} +string Execute_PositionModify() +{ + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "Ticket", ticket); + GET_DOUBLE_JSON_VALUE(jo, "Sl", sl); + GET_DOUBLE_JSON_VALUE(jo, "Tp", tp); + CTrade trade; bool ok = trade.PositionModify(ticket,sl,tp); Print("command PositionModify: result = ", ok); - - if (!sendBooleanResponse(ExpertHandle, ok, _response_error)) - { - PrintResponseError("PositionModify", _response_error); - } + + return CreateSuccessResponse(new JSONBool(ok)); } -void Execute_PositionClosePartial_bySymbol() +string Execute_PositionClosePartial_bySymbol() { - string symbol; - double volume; - ulong deviation; - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("PositionClosePartial (1)", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 1, volume, _error)) - { - PrintParamError("PositionClosePartial (1)", "volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getULongValue(ExpertHandle, 2, deviation, _error)) - { - PrintParamError("PositionClosePartial (1)", "deviation", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_DOUBLE_JSON_VALUE(jo, "Volume", volume); + GET_ULONG_JSON_VALUE(jo, "Deviation", deviation); + CTrade trade; bool ok = trade.PositionClosePartial(symbol, volume, deviation); #ifdef __DEBUG_LOG__ Print("command PositionClosePartial (1): result = ", ok); -#endif +#endif - if (!sendBooleanResponse(ExpertHandle, ok, _response_error)) - { - PrintResponseError("PositionClosePartial (1)", _response_error); - } + return CreateSuccessResponse(new JSONBool(ok)); } -void Execute_PositionClosePartial_byTicket() +string Execute_PositionClosePartial_byTicket() { - ulong ticket; - double volume; - ulong deviation; - - if (!getULongValue(ExpertHandle, 0, ticket, _error)) - { - PrintParamError("PositionClosePartial (2)", "ticket", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 1, volume, _error)) - { - PrintParamError("PositionClosePartial (2)", "volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getULongValue(ExpertHandle, 2, deviation, _error)) - { - PrintParamError("PositionClosePartial (2)", "deviation", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "Ticket", ticket); + GET_DOUBLE_JSON_VALUE(jo, "Volume", volume); + GET_ULONG_JSON_VALUE(jo, "Deviation", deviation); + CTrade trade; bool ok = trade.PositionClosePartial(ticket, volume, deviation); #ifdef __DEBUG_LOG__ Print("command PositionClosePartial (2): result = ", ok); -#endif +#endif - if (!sendBooleanResponse(ExpertHandle, ok, _response_error)) - { - PrintResponseError("PositionClosePartial (2)", _response_error); - } + return CreateSuccessResponse(new JSONBool(ok)); } -void Execute_PositionOpen(bool isTradeResultRequired) +string Execute_PositionOpen(bool isTradeResultRequired) { - string symbol; - int order_type; - double volume; - double price; - double sl; - double tp; - string comment; - StringInit(symbol, 100, 0); - StringInit(comment, 1000, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("PositionOpen", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, order_type, _error)) - { - PrintParamError("PositionOpen", "order_type", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 2, volume, _error)) - { - PrintParamError("PositionOpen", "volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 3, price, _error)) - { - PrintParamError("PositionOpen", "price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 4, sl, _error)) - { - PrintParamError("PositionOpen", "sl", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 5, tp, _error)) - { - PrintParamError("PositionOpen", "tp", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 6, comment, _error)) - { - PrintParamError("PositionOpen", "comment", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "OrderType", order_type); + GET_DOUBLE_JSON_VALUE(jo, "Volume", volume); + GET_DOUBLE_JSON_VALUE(jo, "Price", price); + GET_DOUBLE_JSON_VALUE(jo, "Sl", sl); + GET_DOUBLE_JSON_VALUE(jo, "Tp", tp); + GET_STRING_JSON_VALUE(jo, "Comment", comment); - -#ifdef __DEBUG_LOG__ +#ifdef __DEBUG_LOG__ PrintFormat("%s: symbol = %s, order_type = %d, volume = %f, price = %f, sl = %f, tp = %f, comment = %s", __FUNCTION__, symbol, order_type, volume, price, sl, tp, comment); -#endif +#endif CTrade trade; bool ok = trade.PositionOpen(symbol, (ENUM_ORDER_TYPE)order_type, volume, price, sl, tp, comment); + +#ifdef __DEBUG_LOG__ + Print("command PositionOpen: result = ", ok); +#endif + if (isTradeResultRequired) { MqlTradeResult tradeResult={0}; trade.Result(tradeResult); - if (!sendStringResponse(ExpertHandle, ResultToString(ok, tradeResult), _response_error)) - { - PrintResponseError("PositionOpen", _response_error); - } + return CreateSuccessResponse(MqlTradeResultToJson(tradeResult)); } - else - { - if (!sendBooleanResponse(ExpertHandle, ok, _response_error)) - { - PrintResponseError("PositionOpen", _response_error); - } - } - - Print("command PositionOpen: result = ", ok); + + return CreateSuccessResponse(new JSONBool(ok)); } -void Execute_BacktestingReady() +string Execute_BacktestingReady() { bool retVal = false; if (IsTesting()) @@ -3384,2776 +2230,954 @@ void Execute_BacktestingReady() retVal = true; } - if (!sendBooleanResponse(ExpertHandle, retVal, _response_error)) - { - PrintResponseError("BacktestingReady", _response_error); - } + return CreateSuccessResponse(new JSONBool(retVal)); } -void Execute_IsTesting() +string Execute_IsTesting() { - if (!sendBooleanResponse(ExpertHandle, IsTesting(), _response_error)) - { - PrintResponseError("IsTesting", _response_error); - } + return CreateSuccessResponse(new JSONBool(IsTesting())); } -void Execute_Print() +string Execute_Print() { - string printMsg; - StringInit(printMsg, 1000, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "PrintMsg", printMsg); + + Print(printMsg); + return CreateSuccessResponse(new JSONBool(true)); +} - if (!getStringValue(ExpertHandle, 0, printMsg, _error)) - { - PrintParamError("Print", "printMsg", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } +string Execute_PositionSelectByTicket() +{ + GET_JSON_PAYLOAD(jo); + GET_ULONG_JSON_VALUE(jo, "Ticket", ticket); + + bool result = PositionSelectByTicket(ticket); + return CreateSuccessResponse(new JSONBool(result)); +} + +// !!!!!!!!!!!!!!!!!!!! TODO !!!!!!!!!!!!!!!!!!!!!!!! +string Execute_ObjectCreate() +{ + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "Type", type); + GET_INT_JSON_VALUE(jo, "Nwin", nwin); + + CHECK_JSON_VALUE(jo, "Time"); + CHECK_JSON_VALUE(jo, "Price"); + + datetime times[30]; + double prices[30]; + ArrayInitialize(times, EMPTY_VALUE); + ArrayInitialize(prices, EMPTY_VALUE); + + JSONArray* times_jo = jo.p.getArray("Times"); + for(int i = 0; i < times_jo.size(); i++) + times[i] = (datetime) times_jo.getInt(i); - Print(printMsg); - if (!sendBooleanResponse(ExpertHandle, true, _response_error)) - { - PrintResponseError("Print", _response_error); - } + JSONArray* prices_jo = jo.p.getArray("Prices"); + for(int i = 0; i < prices_jo.size(); i++) + prices[i] = prices_jo.getDouble(i); + + bool result = ObjectCreate(chartId, name, (ENUM_OBJECT)type, nwin, + times[0], prices[0], times[1], prices[1], times[2], prices[2], + times[3], prices[3], times[4], prices[4], times[5], prices[5], + times[6], prices[6], times[7], prices[7], times[8], prices[8], + times[9], prices[9], times[10], prices[10], times[11], prices[11], + times[12], prices[12], times[13], prices[13], times[14], prices[14], + times[15], prices[15], times[16], prices[16], times[17], prices[17], + times[18], prices[18], times[19], prices[19], times[20], prices[20], + times[21], prices[21], times[22], prices[22], times[23], prices[23], + times[24], prices[24], times[25], prices[25], times[26], prices[26], + times[27], prices[27], times[28], prices[28], times[29], prices[29]); + + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_PositionSelectByTicket() +string Execute_ObjectName() { - ulong ticket; - if (!getULongValue(ExpertHandle, 0, ticket, _error)) - { - PrintParamError("PositionSelectByTicket", "ticket", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_INT_JSON_VALUE(jo, "Pos", pos); + GET_INT_JSON_VALUE(jo, "SubWindow", subWindow); + GET_INT_JSON_VALUE(jo, "Type", type); - if (!sendBooleanResponse(ExpertHandle, PositionSelectByTicket(ticket), _response_error)) - { - PrintResponseError("PositionSelectByTicket", _response_error); - } + string result = ObjectName(chartId, pos, subWindow, type); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_ObjectCreate() +string Execute_ObjectDelete() { - int nParameter = 0; - long chartId; - string name; - int type; - int nwin; - int time1; - double price1; - int arrTime[29]; - double arrPrice[29]; - StringInit(name, 200, 0); - - if (!getIntValue(ExpertHandle, 0, nParameter, _error)) - { - PrintParamError("ObjectCreate", "nParameter", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!getLongValue(ExpertHandle, 1, chartId, _error)) - { - PrintParamError("ObjectCreate", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 2, name, _error)) - { - PrintParamError("ObjectCreate", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, type, _error)) - { - PrintParamError("ObjectCreate", "type", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, nwin, _error)) - { - PrintParamError("ObjectCreate", "nwin", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, time1, _error)) - { - PrintParamError("ObjectCreate", "time1", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 6, price1, _error)) - { - PrintParamError("ObjectCreate", "price1", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - ArrayInitialize(arrTime, 0); - ArrayInitialize(arrPrice, 0); - for(int i = 0; i * 2 + 6 < nParameter; i++) - { - if (!getIntValue(ExpertHandle, i * 2 + 7, arrTime[i], _error)) - { - PrintParamError("ObjectCreate", "time" + IntegerToString(i * 2 + 7), _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - else if (!getDoubleValue(ExpertHandle, i * 2 + 8, arrPrice[i], _error)) - { - PrintParamError("ObjectCreate", "price" + IntegerToString(i * 2 + 8), _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - } - - if (!sendBooleanResponse(ExpertHandle - ,ObjectCreate(chartId, name, (ENUM_OBJECT)type, nwin, (datetime)time1, price1 - ,(datetime)arrTime[0], arrPrice[0],(datetime)arrTime[1], arrPrice[1],(datetime)arrTime[2], arrPrice[2],(datetime)arrTime[3], arrPrice[3],(datetime)arrTime[4], arrPrice[4],(datetime)arrTime[5], arrPrice[5] - ,(datetime)arrTime[6], arrPrice[6],(datetime)arrTime[7], arrPrice[7],(datetime)arrTime[8], arrPrice[8],(datetime)arrTime[9], arrPrice[9],(datetime)arrTime[10], arrPrice[10],(datetime)arrTime[11], arrPrice[11] - ,(datetime)arrTime[12], arrPrice[12],(datetime)arrTime[13], arrPrice[13],(datetime)arrTime[14], arrPrice[14],(datetime)arrTime[15], arrPrice[15],(datetime)arrTime[16], arrPrice[16],(datetime)arrTime[17], arrPrice[17] - ,(datetime)arrTime[18], arrPrice[18],(datetime)arrTime[19], arrPrice[19],(datetime)arrTime[20], arrPrice[20],(datetime)arrTime[21], arrPrice[21],(datetime)arrTime[22], arrPrice[22],(datetime)arrTime[23], arrPrice[23] - ,(datetime)arrTime[24], arrPrice[24],(datetime)arrTime[25], arrPrice[25],(datetime)arrTime[26], arrPrice[26],(datetime)arrTime[27], arrPrice[27],(datetime)arrTime[28], arrPrice[28]) - , _response_error)) - { - PrintResponseError("ObjectCreate", _response_error); - } + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + + bool result = ObjectDelete(chartId, name); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ObjectName() +string Execute_ObjectsDeleteAll() { - long chartId; - int pos; - int subWindow; - int type; - - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectName", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, pos, _error)) - { - PrintParamError("ObjectName", "pos", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, subWindow, _error)) - { - PrintParamError("ObjectName", "subWindow", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, type, _error)) - { - PrintParamError("ObjectName", "type", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_INT_JSON_VALUE(jo, "SubWindow", subWindow); + GET_INT_JSON_VALUE(jo, "Type", type); - if (!sendStringResponse(ExpertHandle, ObjectName(chartId, pos, subWindow, type), _error)) - { - PrintResponseError("ObjectName", _response_error); - } + int result = ObjectsDeleteAll(chartId, subWindow, type); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectDelete() +string Execute_ObjectFind() { - long chartId; - string name; - StringInit(name, 200, 0); - - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectDelete", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectDelete", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendBooleanResponse(ExpertHandle, ObjectDelete(chartId, name), _response_error)) - { - PrintResponseError("ObjectDelete", _response_error); - } + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + + int result = ObjectFind(chartId, name); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectsDeleteAll() +string Execute_ObjectGetTimeByValue() { - long chartId; - int subWindow; - int type; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_DOUBLE_JSON_VALUE(jo, "Value", value); + GET_INT_JSON_VALUE(jo, "lineId", lineId); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectsDeleteAll", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, subWindow, _error)) - { - PrintParamError("ObjectsDeleteAll", "subWindow", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, type, _error)) - { - PrintParamError("ObjectsDeleteAll", "type", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, ObjectsDeleteAll(chartId, subWindow, type), _error)) - { - PrintResponseError("ObjectsDeleteAll", _response_error); - } + int result = (int)ObjectGetTimeByValue(chartId, name, value, lineId); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectFind() +string Execute_ObjectGetValueByTime() { - long chartId; - string name; - StringInit(name, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "Time", time); + GET_INT_JSON_VALUE(jo, "lineId", lineId); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectFind", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectFind", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, ObjectFind(chartId, name), _error)) - { - PrintResponseError("ObjectFind", _response_error); - } + double result = ObjectGetValueByTime(chartId, name, (datetime)time, lineId); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectGetTimeByValue() +string Execute_ObjectMove() { - long chartId; - string name; - double value; - int lineId; - StringInit(name, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "PointIndex", pointIndex); + GET_INT_JSON_VALUE(jo, "Time", time); + GET_DOUBLE_JSON_VALUE(jo, "Price", price); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectGetTimeByValue", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectGetTimeByValue", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 2, value, _error)) - { - PrintParamError("ObjectGetTimeByValue", "value", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, lineId, _error)) - { - PrintParamError("ObjectGetTimeByValue", "lineId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, (int)ObjectGetTimeByValue(chartId, name, value, lineId), _error)) - { - PrintResponseError("ObjectGetTimeByValue", _response_error); - } + bool result = ObjectMove(chartId, name, pointIndex, (datetime)time, price); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ObjectGetValueByTime() +string Execute_ObjectsTotal() { - long chartId; - string name; - int time; - int lineId; - StringInit(name, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_INT_JSON_VALUE(jo, "SubWindow", subWindow); + GET_INT_JSON_VALUE(jo, "Type", type); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectGetValueByTime", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectGetValueByTime", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, time, _error)) - { - PrintParamError("ObjectGetValueByTime", "time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, lineId, _error)) - { - PrintParamError("ObjectGetValueByTime", "lineId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendDoubleResponse(ExpertHandle, ObjectGetValueByTime(chartId, name, (datetime)time, lineId), _error)) - { - PrintResponseError("ObjectGetValueByTime", _response_error); - } + int result = ObjectsTotal(chartId, subWindow, type); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectMove() +string Execute_ObjectGetDouble() { - long chartId; - string name; - int pointIndex; - int time; - double price; - StringInit(name, 200, 0); - - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectMove", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectMove", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, pointIndex, _error)) - { - PrintParamError("ObjectMove", "pointIndex", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, time, _error)) - { - PrintParamError("ObjectMove", "time", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 4, price, _error)) - { - PrintParamError("ObjectMove", "price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendBooleanResponse(ExpertHandle, ObjectMove(chartId, name, pointIndex, (datetime)time, price), _error)) - { - PrintResponseError("ObjectMove", _response_error); - } + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "PropId", propId); + + double result = ObjectGetDouble(chartId, name, (ENUM_OBJECT_PROPERTY_DOUBLE)propId); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectsTotal() +string Execute_ObjectGetInteger() { - long chartId; - int subWindow; - int type; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "PropId", propId); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectsTotal", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, subWindow, _error)) - { - PrintParamError("ObjectsTotal", "subWindow", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, type, _error)) - { - PrintParamError("ObjectsTotal", "type", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, ObjectsTotal(chartId, subWindow, type), _error)) - { - PrintResponseError("ObjectsTotal", _response_error); - } + long result = ObjectGetInteger(chartId, name, (ENUM_OBJECT_PROPERTY_INTEGER)propId); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectGetDouble() +string Execute_ObjectGetString() { - long chartId; - string name; - int propId; - StringInit(name, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "PropId", propId); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectGetDouble", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectGetDouble", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, propId, _error)) - { - PrintParamError("ObjectGetDouble", "propId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendDoubleResponse(ExpertHandle, ObjectGetDouble(chartId, name, (ENUM_OBJECT_PROPERTY_DOUBLE)propId), _error)) - { - PrintResponseError("ObjectGetDouble", _response_error); - } + string result = ObjectGetString(chartId, name, (ENUM_OBJECT_PROPERTY_STRING)propId); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_ObjectGetInteger() +string Execute_ObjectSetDouble() { - long chartId; - string name; - int propId; - StringInit(name, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "PropId", propId); + GET_DOUBLE_JSON_VALUE(jo, "PropValue", propValue); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectGetInteger", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectGetInteger", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, propId, _error)) - { - PrintParamError("ObjectGetInteger", "propId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendLongResponse(ExpertHandle, ObjectGetInteger(chartId, name, (ENUM_OBJECT_PROPERTY_INTEGER)propId), _error)) - { - PrintResponseError("ObjectGetInteger", _response_error); - } + bool result = ObjectSetDouble(chartId, name, (ENUM_OBJECT_PROPERTY_DOUBLE)propId, propValue); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ObjectGetString() +string Execute_ObjectSetInteger() { - long chartId; - string name; - int propId; - StringInit(name, 200, 0); - - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectGetString", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectGetString", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, propId, _error)) - { - PrintParamError("ObjectGetString", "propId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendStringResponse(ExpertHandle, ObjectGetString(chartId, name, (ENUM_OBJECT_PROPERTY_STRING)propId), _error)) - { - PrintResponseError("ObjectGetString", _response_error); - } + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "PropId", propId); + GET_LONG_JSON_VALUE(jo, "PropValue", propValue); + + long result = ObjectSetInteger(chartId, name, (ENUM_OBJECT_PROPERTY_INTEGER)propId, propValue); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectSetDouble() +string Execute_ObjectSetString() { - long chartId; - string name; - int propId; - double propValue; - StringInit(name, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chartId); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_INT_JSON_VALUE(jo, "PropId", propId); + GET_STRING_JSON_VALUE(jo, "PropValue", propValue); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectSetDouble", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectSetDouble", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, propId, _error)) - { - PrintParamError("ObjectSetDouble", "propId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 3, propValue, _error)) - { - PrintParamError("ObjectSetDouble", "propValue", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendBooleanResponse(ExpertHandle, ObjectSetDouble(chartId, name, (ENUM_OBJECT_PROPERTY_DOUBLE)propId, propValue), _error)) - { - PrintResponseError("ObjectSetDouble", _response_error); - } + bool result = ObjectSetString(chartId, name, (ENUM_OBJECT_PROPERTY_STRING)propId, propValue); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ObjectSetInteger() +string Execute_iAC() { - long chartId; - string name; - int propId; - long propValue; - StringInit(name, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectSetInteger", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectSetInteger", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, propId, _error)) - { - PrintParamError("ObjectSetInteger", "propId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getLongValue(ExpertHandle, 3, propValue, _error)) - { - PrintParamError("ObjectSetInteger", "propValue", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendBooleanResponse(ExpertHandle, ObjectSetInteger(chartId, name, (ENUM_OBJECT_PROPERTY_INTEGER)propId, propValue), _error)) - { - PrintResponseError("ObjectSetInteger", _response_error); - } + int result = iAC(symbol, (ENUM_TIMEFRAMES)period); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ObjectSetString() +string Execute_iAD() { - long chartId; - string name; - int propId; - string propValue; - StringInit(name, 200, 0); - StringInit(propValue, 1000, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "AppliedVolue", applied_volume); - if (!getLongValue(ExpertHandle, 0, chartId, _error)) - { - PrintParamError("ObjectSetString", "chartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, name, _error)) - { - PrintParamError("ObjectSetString", "name", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, propId, _error)) - { - PrintParamError("ObjectSetString", "propId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 3, propValue, _error)) - { - PrintParamError("ObjectSetString", "propValue", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + int result = iAD(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iADX() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "AdxPeriod", adx_period); - if (!sendBooleanResponse(ExpertHandle, ObjectSetString(chartId, name, (ENUM_OBJECT_PROPERTY_STRING)propId, propValue), _error)) - { - PrintResponseError("ObjectSetString", _response_error); - } + int result = iADX(symbol, (ENUM_TIMEFRAMES)period, adx_period); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iAC() +string Execute_iADXWilder() { - string symbol; - int period; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iAC", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iAC", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, iAC(symbol, (ENUM_TIMEFRAMES)period), _error)) - { - PrintResponseError("iAC", _response_error); - } -} - -void Execute_iAD() -{ - string symbol; - int period; - int applied_volume; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iAD", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iAD", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, applied_volume, _error)) - { - PrintParamError("iAD", "applied_volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "AdxPeriod", adx_period); - if (!sendIntResponse(ExpertHandle, - iAD(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume), - _error)) - { - PrintResponseError("iAD", _response_error); - } + int result = iADXWilder(symbol, (ENUM_TIMEFRAMES)period, adx_period); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iADX() +string Execute_iAlligator() { - string symbol; - int period; - int adx_period; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iADX", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iADX", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, adx_period, _error)) - { - PrintParamError("iADX", "adx_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "JawPeriod", jaw_period); + GET_INT_JSON_VALUE(jo, "JawShift", jaw_shift); + GET_INT_JSON_VALUE(jo, "TeethPeriod", teeth_period); + GET_INT_JSON_VALUE(jo, "TeethShift", teeth_shift); + GET_INT_JSON_VALUE(jo, "LipsPeriod", lips_period); + GET_INT_JSON_VALUE(jo, "LipsShift", lips_shift); + GET_INT_JSON_VALUE(jo, "MaMethod", ma_method); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iADX(symbol, (ENUM_TIMEFRAMES)period, adx_period), - _error)) - { - PrintResponseError("iADX", _response_error); - } + int result = iAlligator(symbol, (ENUM_TIMEFRAMES)period, jaw_period, jaw_shift, teeth_period, teeth_shift, + lips_period, lips_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iADXWilder() +string Execute_iAMA() { - string symbol; - int period; - int adx_period; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iADXWilder", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iADXWilder", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, adx_period, _error)) - { - PrintParamError("iADXWilder", "adx_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "AmaPeriod", ama_period); + GET_INT_JSON_VALUE(jo, "FastMaPeriod", fast_ma_period); + GET_INT_JSON_VALUE(jo, "SlowMaPeriod", slow_ma_period); + GET_INT_JSON_VALUE(jo, "AmaShift", ama_shift); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iADXWilder(symbol, (ENUM_TIMEFRAMES)period, adx_period), - _error)) - { - PrintResponseError("iADXWilder", _response_error); - } + int result = iAMA(symbol, (ENUM_TIMEFRAMES)period, ama_period, fast_ma_period, slow_ma_period, ama_shift, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iAlligator() +string Execute_iAO() { - string symbol; - int period; - int jaw_period; - int jaw_shift; - int teeth_period; - int teeth_shift; - int lips_period; - int lips_shift; - int ma_method; - int applied_price; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iAlligator", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iAlligator", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, jaw_period, _error)) - { - PrintParamError("iAlligator", "jaw_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, jaw_shift, _error)) - { - PrintParamError("iAlligator", "jaw_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, teeth_period, _error)) - { - PrintParamError("iAlligator", "teeth_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, teeth_shift, _error)) - { - PrintParamError("iAlligator", "teeth_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 6, lips_period, _error)) - { - PrintParamError("iAlligator", "lips_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 7, lips_shift, _error)) - { - PrintParamError("iAlligator", "lips_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 8, ma_method, _error)) - { - PrintParamError("iAlligator", "ma_method", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 9, applied_price, _error)) - { - PrintParamError("iAlligator", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + int result = iAO(symbol, (ENUM_TIMEFRAMES)period); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iATR() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); - if (!sendIntResponse(ExpertHandle, - iAlligator(symbol, (ENUM_TIMEFRAMES)period, jaw_period, jaw_shift, teeth_period, teeth_shift, - lips_period, lips_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iAlligator", _response_error); - } + int result = iATR(symbol, (ENUM_TIMEFRAMES)period, ma_period); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iAMA() +string Execute_iBearsPower() { - string symbol; - int period; - int ama_period; - int fast_ma_period; - int slow_ma_period; - int ama_shift; - int applied_price; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iAMA", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iAMA", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ama_period, _error)) - { - PrintParamError("iAMA", "ama_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, fast_ma_period, _error)) - { - PrintParamError("iAMA", "fast_ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, slow_ma_period, _error)) - { - PrintParamError("iAMA", "slow_ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, ama_shift, _error)) - { - PrintParamError("iAMA", "ama_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 6, applied_price, _error)) - { - PrintParamError("iAMA", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + int result = iBearsPower(symbol, (ENUM_TIMEFRAMES)period, ma_period); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iBands() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "BandsPeriod", bands_period); + GET_INT_JSON_VALUE(jo, "BandsShift", bands_shift); + GET_DOUBLE_JSON_VALUE(jo, "Deviation", deviation); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iAMA(symbol, (ENUM_TIMEFRAMES)period, ama_period, fast_ma_period, slow_ma_period, ama_shift, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iAMA", _response_error); - } + int result = iBands(symbol, (ENUM_TIMEFRAMES)period, bands_period, bands_shift, deviation, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iAO() +string Execute_iBullsPower() { - string symbol; - int period; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iAO", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iAO", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iAO(symbol, (ENUM_TIMEFRAMES)period), - _error)) - { - PrintResponseError("iAO", _response_error); - } + int result = iBullsPower(symbol, (ENUM_TIMEFRAMES)period, ma_period); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iATR() +string Execute_iCCI() { - string symbol; - int period; - int ma_period; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iATR", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iATR", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iATR", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - - if (!sendIntResponse(ExpertHandle, - iATR(symbol, (ENUM_TIMEFRAMES)period, ma_period), - _error)) - { - PrintResponseError("iATR", _response_error); - } + int result = iCCI(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_PRICE) applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iBearsPower() +string Execute_iChaikin() { - string symbol; - int period; - int ma_period; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "FastMaPeriod", fast_ma_period); + GET_INT_JSON_VALUE(jo, "SlowMaPeriod", slow_ma_period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "AppliedVolume", applied_volume); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iBearsPower", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iBearsPower", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iBearsPower", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - - if (!sendIntResponse(ExpertHandle, - iBearsPower(symbol, (ENUM_TIMEFRAMES)period, ma_period), - _error)) - { - PrintResponseError("iBearsPower", _response_error); - } + int result = iChaikin(symbol, (ENUM_TIMEFRAMES)period, fast_ma_period, slow_ma_period, (ENUM_MA_METHOD)ma_period, (ENUM_APPLIED_VOLUME) applied_volume); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iBands() +string Execute_iDEMA() { - string symbol; - int period; - int bands_period; - int bands_shift; - double deviation; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iBands", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iBands", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, bands_period, _error)) - { - PrintParamError("iBands", "bands_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 3, bands_shift, _error)) - { - PrintParamError("iBands", "bands_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getDoubleValue(ExpertHandle, 4, deviation, _error)) - { - PrintParamError("iBands", "deviation", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 5, applied_price, _error)) - { - PrintParamError("iBands", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "MaShift", ma_shift); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iBands(symbol, (ENUM_TIMEFRAMES)period, bands_period, bands_shift, deviation, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iBands", _response_error); - } + int result = iDEMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_APPLIED_PRICE) applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iBullsPower() +string Execute_iDeMarker() { - string symbol; - int period; - int ma_period; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iBullsPower", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iBullsPower", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iBullsPower", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - - if (!sendIntResponse(ExpertHandle, - iBullsPower(symbol, (ENUM_TIMEFRAMES)period, ma_period), - _error)) - { - PrintResponseError("iBullsPower", _response_error); - } + int result = iDeMarker(symbol, (ENUM_TIMEFRAMES)period, ma_period); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iCCI() +string Execute_iEnvelopes() { - string symbol; - int period; - int ma_period; - int applied_price; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "MaShift", ma_shift); + GET_INT_JSON_VALUE(jo, "MaMethod", ma_method); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); + GET_DOUBLE_JSON_VALUE(jo, "Deviation", deviation); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iCCI", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iCCI", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iCCI", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 3, applied_price, _error)) - { - PrintParamError("iCCI", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - - if (!sendIntResponse(ExpertHandle, - iCCI(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_PRICE) applied_price), - _error)) - { - PrintResponseError("iCCI", _response_error); - } + int result = iEnvelopes(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price, deviation); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iChaikin() +string Execute_iForce() { - string symbol; - int period; - int fast_ma_period; - int slow_ma_period; - int ma_period; - int applied_volume; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iChaikin", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iChaikin", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, fast_ma_period, _error)) - { - PrintParamError("iChaikin", "fast_ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, slow_ma_period, _error)) - { - PrintParamError("iChaikin", "slow_ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, ma_period, _error)) - { - PrintParamError("iChaikin", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 5, applied_volume, _error)) - { - PrintParamError("iChaikin", "applied_volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "MaMethod", ma_method); + GET_INT_JSON_VALUE(jo, "AppliedVolume", applied_volume); - if (!sendIntResponse(ExpertHandle, - iChaikin(symbol, (ENUM_TIMEFRAMES)period, fast_ma_period, slow_ma_period, (ENUM_MA_METHOD)ma_period, (ENUM_APPLIED_VOLUME) applied_volume), - _error)) - { - PrintResponseError("iChaikin", _response_error); - } + int result = iForce(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_VOLUME)applied_volume); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iDEMA() +string Execute_iFractals() { - string symbol; - int period; - int ma_period; - int ma_shift; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iDEMA", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iDEMA", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iDEMA", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 3, ma_shift, _error)) - { - PrintParamError("iDEMA", "ma_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 4, applied_price, _error)) - { - PrintParamError("iDEMA", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - - if (!sendIntResponse(ExpertHandle, - iDEMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_APPLIED_PRICE) applied_price), - _error)) - { - PrintResponseError("iDEMA", _response_error); - } -} - -void Execute_iDeMarker() -{ - string symbol; - int period; - int ma_period; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iDeMarker", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iDeMarker", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iDeMarker", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } + int result = iFractals(symbol, (ENUM_TIMEFRAMES)period); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iFrAMA() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "MaShift", ma_shift); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iDeMarker(symbol, (ENUM_TIMEFRAMES)period, ma_period), - _error)) - { - PrintResponseError("iDeMarker", _response_error); - } -} - -void Execute_iEnvelopes() -{ - string symbol; - int period; - int ma_period; - int ma_shift; - int ma_method; - int applied_price; - double deviation; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iEnvelopes", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iEnvelopes", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iEnvelopes", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 3, ma_shift, _error)) - { - PrintParamError("iEnvelopes", "ma_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 4, ma_method, _error)) - { - PrintParamError("iEnvelopes", "ma_method", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 5, applied_price, _error)) - { - PrintParamError("iEnvelopes", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getDoubleValue(ExpertHandle, 6, deviation, _error)) - { - PrintParamError("iEnvelopes", "deviation", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - - if (!sendIntResponse(ExpertHandle, - iEnvelopes(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price, deviation), - _error)) - { - PrintResponseError("iEnvelopes", _response_error); - } -} - -void Execute_iForce() -{ - string symbol; - int period; - int ma_period; - int ma_method; - int applied_volume; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iForce", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iForce", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iForce", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 3, ma_method, _error)) - { - PrintParamError("iForce", "ma_method", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - if (!getIntValue(ExpertHandle, 4, applied_volume, _error)) - { - PrintParamError("iForce", "applied_volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - } - - if (!sendIntResponse(ExpertHandle, - iForce(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_VOLUME)applied_volume), - _error)) - { - PrintResponseError("iForce", _response_error); - } -} - -void Execute_iFractals() -{ - string symbol; - int period; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iFractals", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iFractals", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iFractals(symbol, (ENUM_TIMEFRAMES)period), - _error)) - { - PrintResponseError("iFractals", _response_error); - } -} - -void Execute_iFrAMA() -{ - string symbol; - int period; - int ma_period; - int ma_shift; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iFrAMA", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iFrAMA", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iFrAMA", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, ma_shift, _error)) - { - PrintParamError("iFrAMA", "ma_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, applied_price, _error)) - { - PrintParamError("iFrAMA", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iFrAMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iFrAMA", _response_error); - } + int result = iFrAMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iGator() +string Execute_iGator() { - string symbol; - int period; - int jaw_period; - int jaw_shift; - int teeth_period; - int teeth_shift; - int lips_period; - int lips_shift; - int ma_method; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iGator", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iGator", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, jaw_period, _error)) - { - PrintParamError("iGator", "jaw_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, jaw_shift, _error)) - { - PrintParamError("iGator", "jaw_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, teeth_period, _error)) - { - PrintParamError("iGator", "teeth_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, teeth_shift, _error)) - { - PrintParamError("iGator", "teeth_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 6, lips_period, _error)) - { - PrintParamError("iGator", "lips_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 7, lips_shift, _error)) - { - PrintParamError("iGator", "lips_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 8, ma_method, _error)) - { - PrintParamError("iGator", "ma_method", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 9, applied_price, _error)) - { - PrintParamError("iGator", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iGator(symbol, (ENUM_TIMEFRAMES)period, jaw_period, jaw_shift, teeth_period, teeth_shift, lips_period, lips_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iGator", _response_error); - } -} - -void Execute_iIchimoku() -{ - string symbol; - int period; - int tenkan_sen; - int kijun_sen; - int senkou_span_b; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iIchimoku", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iIchimoku", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, tenkan_sen, _error)) - { - PrintParamError("iIchimoku", "tenkan_sen", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, kijun_sen, _error)) - { - PrintParamError("iIchimoku", "kijun_sen", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, senkou_span_b, _error)) - { - PrintParamError("iIchimoku", "senkou_span_b", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iIchimoku(symbol, (ENUM_TIMEFRAMES)period, tenkan_sen, kijun_sen, senkou_span_b), - _error)) - { - PrintResponseError("iIchimoku", _response_error); - } -} - -void Execute_iBWMFI() -{ - string symbol; - int period; - int applied_volume; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iBWMFI", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iBWMFI", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, applied_volume, _error)) - { - PrintParamError("iBWMFI", "applied_volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iBWMFI(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume), - _error)) - { - PrintResponseError("iBWMFI", _response_error); - } -} - -void Execute_iMomentum() -{ - string symbol; - int period; - int mom_period; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iMomentum", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iMomentum", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, mom_period, _error)) - { - PrintParamError("iMomentum", "mom_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, applied_price, _error)) - { - PrintParamError("iMomentum", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iMomentum(symbol, (ENUM_TIMEFRAMES)period, mom_period, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iMomentum", _response_error); - } -} - -void Execute_iMFI() -{ - string symbol; - int period; - int ma_period; - int applied_volume; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iMFI", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iMFI", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iMFI", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, applied_volume, _error)) - { - PrintParamError("iMFI", "applied_volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iMFI(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_VOLUME)applied_volume), - _error)) - { - PrintResponseError("iMFI", _response_error); - } -} - -void Execute_iMA() -{ - string symbol; - int period; - int ma_period; - int ma_shift; - int ma_method; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iMA", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iMA", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iMA", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, ma_shift, _error)) - { - PrintParamError("iMA", "ma_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, ma_method, _error)) - { - PrintParamError("iMA", "ma_method", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, applied_price, _error)) - { - PrintParamError("iMA", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iMA", _response_error); - } -} - -void Execute_iOsMA() -{ - string symbol; - int period; - int fast_ema_period; - int slow_ema_period; - int signal_period; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iOsMA", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iOsMA", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, fast_ema_period, _error)) - { - PrintParamError("iOsMA", "fast_ema_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, slow_ema_period, _error)) - { - PrintParamError("iOsMA", "slow_ema_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, signal_period, _error)) - { - PrintParamError("iOsMA", "signal_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, applied_price, _error)) - { - PrintParamError("iOsMA", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iOsMA(symbol, (ENUM_TIMEFRAMES)period, fast_ema_period, slow_ema_period, signal_period, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iOsMA", _response_error); - } -} - -void Execute_iMACD() -{ - string symbol; - int period; - int fast_ema_period; - int slow_ema_period; - int signal_period; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iMACD", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iMACD", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, fast_ema_period, _error)) - { - PrintParamError("iMACD", "fast_ema_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, slow_ema_period, _error)) - { - PrintParamError("iMACD", "slow_ema_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, signal_period, _error)) - { - PrintParamError("iMACD", "signal_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, applied_price, _error)) - { - PrintParamError("iMACD", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iMACD(symbol, (ENUM_TIMEFRAMES)period, fast_ema_period, slow_ema_period, signal_period, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iMACD", _response_error); - } -} - -void Execute_iOBV() -{ - string symbol; - int period; - int applied_volume; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iOBV", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iOBV", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, applied_volume, _error)) - { - PrintParamError("iOBV", "applied_volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "JawPeriod", jaw_period); + GET_INT_JSON_VALUE(jo, "JawShift", jaw_shift); + GET_INT_JSON_VALUE(jo, "TeethPeriod", teeth_period); + GET_INT_JSON_VALUE(jo, "TeethShift", teeth_shift); + GET_INT_JSON_VALUE(jo, "LipsPeriod", lips_period); + GET_INT_JSON_VALUE(jo, "LipsShift", lips_shift); + GET_INT_JSON_VALUE(jo, "MaMethod", ma_method); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iOBV(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume), - _error)) - { - PrintResponseError("iOBV", _response_error); - } + int result = iGator(symbol, (ENUM_TIMEFRAMES)period, jaw_period, jaw_shift, + teeth_period, teeth_shift, lips_period, lips_shift, + (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iSAR() +string Execute_iIchimoku() { - string symbol; - int period; - double step; - double maximum; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iSAR", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iSAR", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 2, step, _error)) - { - PrintParamError("iSAR", "step", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getDoubleValue(ExpertHandle, 3, maximum, _error)) - { - PrintParamError("iSAR", "maximum", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iSAR(symbol, (ENUM_TIMEFRAMES)period, step, maximum), - _error)) - { - PrintResponseError("iSAR", _response_error); - } -} - -void Execute_iRSI() -{ - string symbol; - int period; - int ma_period; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iRSI", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iRSI", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iRSI", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, applied_price, _error)) - { - PrintParamError("iRSI", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "TenkanSen", tenkan_sen); + GET_INT_JSON_VALUE(jo, "KijunSen", kijun_sen); + GET_INT_JSON_VALUE(jo, "SenkouSpanB", senkou_span_b); - if (!sendIntResponse(ExpertHandle, - iRSI(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iRSI", _response_error); - } + int result = iIchimoku(symbol, (ENUM_TIMEFRAMES)period, tenkan_sen, kijun_sen, senkou_span_b); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iRVI() +string Execute_iBWMFI() { - string symbol; - int period; - int ma_period; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "AppliedVolume", applied_volume); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iRVI", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iRVI", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iRVI", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + int result = iBWMFI(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iMomentum() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MomPeriod", mom_period); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iRVI(symbol, (ENUM_TIMEFRAMES)period, ma_period), - _error)) - { - PrintResponseError("iRVI", _response_error); - } + int result = iMomentum(symbol, (ENUM_TIMEFRAMES)period, mom_period, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iStdDev() +string Execute_iMFI() { - string symbol; - int period; - int ma_period; - int ma_shift; - int ma_method; - int applied_price; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iStdDev", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iStdDev", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iStdDev", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, ma_shift, _error)) - { - PrintParamError("iStdDev", "ma_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, ma_method, _error)) - { - PrintParamError("iStdDev", "ma_method", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, applied_price, _error)) - { - PrintParamError("iStdDev", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iStdDev(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iStdDev", _response_error); - } -} - -void Execute_iStochastic() -{ - string symbol; - int period; - int Kperiod; - int Dperiod; - int slowing; - int ma_method; - int price_field; - StringInit(symbol, 200, 0); - - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iStochastic", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iStochastic", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, Kperiod, _error)) - { - PrintParamError("iStochastic", "Kperiod", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, Dperiod, _error)) - { - PrintParamError("iStochastic", "Dperiod", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, slowing, _error)) - { - PrintParamError("iStochastic", "slowing", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, ma_method, _error)) - { - PrintParamError("iStochastic", "ma_method", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 6, price_field, _error)) - { - PrintParamError("iStochastic", "price_field", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iStochastic(symbol, (ENUM_TIMEFRAMES)period, Kperiod, Dperiod, slowing, (ENUM_MA_METHOD)slowing, (ENUM_STO_PRICE)price_field), - _error)) - { - PrintResponseError("iStochastic", _response_error); - } -} - -void Execute_iTEMA() -{ - string symbol; - int period; - int ma_period; - int ma_shift; - int applied_price; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "AppliedVolume", applied_volume); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iTEMA", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iTEMA", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iTEMA", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, ma_shift, _error)) - { - PrintParamError("iTEMA", "ma_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, applied_price, _error)) - { - PrintParamError("iTEMA", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iTEMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iTEMA", _response_error); - } + int result = iMFI(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_VOLUME)applied_volume); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iTriX() +string Execute_iMA() { - string symbol; - int period; - int ma_period; - int applied_price; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "MaShift", ma_shift); + GET_INT_JSON_VALUE(jo, "MaMethod", ma_method); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iTriX", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iTriX", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, ma_period, _error)) - { - PrintParamError("iTriX", "ma_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, applied_price, _error)) - { - PrintParamError("iTriX", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iTriX(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iTriX", _response_error); - } + int result = iMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iWPR() +string Execute_iOsMA() { - string symbol; - int period; - int calc_period; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "FastEmaPeriod", fast_ema_period); + GET_INT_JSON_VALUE(jo, "SlowEmaPeriod", slow_ema_period); + GET_INT_JSON_VALUE(jo, "SignalPeriod", signal_period); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iWPR", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iWPR", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, calc_period, _error)) - { - PrintParamError("iWPR", "calc_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } + int result = iOsMA(symbol, (ENUM_TIMEFRAMES)period, fast_ema_period, slow_ema_period, signal_period, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iMACD() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "FastEmaPeriod", fast_ema_period); + GET_INT_JSON_VALUE(jo, "SlowEmaPeriod", slow_ema_period); + GET_INT_JSON_VALUE(jo, "SignalPeriod", signal_period); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); - if (!sendIntResponse(ExpertHandle, - iWPR(symbol, (ENUM_TIMEFRAMES)period, calc_period), - _error)) - { - PrintResponseError("iWPR", _response_error); - } + int result = iMACD(symbol, (ENUM_TIMEFRAMES)period, fast_ema_period, slow_ema_period, signal_period, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iVIDyA() +string Execute_iOBV() { - string symbol; - int period; - int cmo_period; - int ema_period; - int ma_shift; - int applied_price; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "AppliedVolume", applied_volume); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iVIDyA", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iVIDyA", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, cmo_period, _error)) - { - PrintParamError("iVIDyA", "cmo_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 3, ema_period, _error)) - { - PrintParamError("iVIDyA", "ema_period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 4, ma_shift, _error)) - { - PrintParamError("iVIDyA", "ma_shift", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 5, applied_price, _error)) - { - PrintParamError("iVIDyA", "applied_price", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iVIDyA(symbol, (ENUM_TIMEFRAMES)period, cmo_period, ema_period, ma_shift, (ENUM_APPLIED_PRICE)applied_price), - _error)) - { - PrintResponseError("iVIDyA", _response_error); - } + int result = iOBV(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_iVolumes() +string Execute_iSAR() { - string symbol; - int period; - int applied_volume; - StringInit(symbol, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_DOUBLE_JSON_VALUE(jo, "Step", step); + GET_DOUBLE_JSON_VALUE(jo, "Mamimum", maximum); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("iVolumes", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, period, _error)) - { - PrintParamError("iVolumes", "period", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 2, applied_volume, _error)) - { - PrintParamError("iVolumes", "applied_volume", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, - iVolumes(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume), - _error)) - { - PrintResponseError("iVolumes", _response_error); - } + int result = iSAR(symbol, (ENUM_TIMEFRAMES)period, step, maximum); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_TimeCurrent() +string Execute_iRSI() { - if (!sendLongResponse(ExpertHandle, TimeCurrent(), _response_error)) - { - PrintResponseError("TimeCurrent", _response_error); - } -} - -void Execute_TimeTradeServer() -{ - if (!sendLongResponse(ExpertHandle, TimeTradeServer(), _response_error)) - { - PrintResponseError("TimeTradeServer", _response_error); - } -} - -void Execute_TimeLocal() -{ - if (!sendLongResponse(ExpertHandle, TimeLocal(), _response_error)) - { - PrintResponseError("TimeLocal", _response_error); - } -} - -void Execute_TimeGMT() -{ - if (!sendLongResponse(ExpertHandle, TimeGMT(), _response_error)) - { - PrintResponseError("TimeGMT", _response_error); - } -} - -void Execute_IndicatorRelease() -{ - int indicator_handle; - GET_INT_VALUE(0, indicator_handle, "indicator_handle"); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); -#ifdef __DEBUG_LOG__ - PrintFormat("%s: indicator_handle = %d", __FUNCTION__, indicator_handle); -#endif - - if (!sendBooleanResponse(ExpertHandle, IndicatorRelease(indicator_handle), _error)) - { - PrintResponseError("IndicatorRelease", _response_error); - } + int result = iRSI(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_GetLastError() +string Execute_iRVI() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + + int result = iRVI(symbol, (ENUM_TIMEFRAMES)period, ma_period); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iStdDev() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "MaShift", ma_shift); + GET_INT_JSON_VALUE(jo, "MaMethod", ma_method); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); + + int result = iStdDev(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_MA_METHOD)ma_method, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iStochastic() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "Kperiod", Kperiod); + GET_INT_JSON_VALUE(jo, "Dperiod", Dperiod); + GET_INT_JSON_VALUE(jo, "Slowing", slowing); + GET_INT_JSON_VALUE(jo, "MaMethod", ma_method); + GET_INT_JSON_VALUE(jo, "PriceField", price_field); + + int result = iStochastic(symbol, (ENUM_TIMEFRAMES)period, Kperiod, Dperiod, slowing, (ENUM_MA_METHOD)slowing, (ENUM_STO_PRICE)price_field); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iTEMA() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "MaShift", ma_shift); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); + + int result = iTEMA(symbol, (ENUM_TIMEFRAMES)period, ma_period, ma_shift, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iTriX() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "MaPeriod", ma_period); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); + + int result = iTriX(symbol, (ENUM_TIMEFRAMES)period, ma_period, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iWPR() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "CalcPeriod", calc_period); + + int result = iWPR(symbol, (ENUM_TIMEFRAMES)period, calc_period); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iVIDyA() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "CmoPeriod", cmo_period); + GET_INT_JSON_VALUE(jo, "EmaPeriod", ema_period); + GET_INT_JSON_VALUE(jo, "MaShift", ma_shift); + GET_INT_JSON_VALUE(jo, "AppliedPrice", applied_price); + + int result = iVIDyA(symbol, (ENUM_TIMEFRAMES)period, cmo_period, ema_period, ma_shift, (ENUM_APPLIED_PRICE)applied_price); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_iVolumes() +{ + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); + GET_INT_JSON_VALUE(jo, "AppliedVolume", applied_volume); + + int result = iVolumes(symbol, (ENUM_TIMEFRAMES)period, (ENUM_APPLIED_VOLUME)applied_volume); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_TimeCurrent() +{ + long result = TimeCurrent(); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_TimeTradeServer() +{ + long result = TimeTradeServer(); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_TimeLocal() +{ + long result = TimeLocal(); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_TimeGMT() +{ + long result = TimeGMT(); + return CreateSuccessResponse(new JSONNumber(result)); +} + +string Execute_IndicatorRelease() +{ + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "IndicatorHandle", indicator_handle); + + bool result = IndicatorRelease(indicator_handle); + return CreateSuccessResponse(new JSONBool(result)); +} + +string Execute_GetLastError() { int last_error = GetLastError(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: last_error = %d", __FUNCTION__, last_error); -#endif - - SEND_INT_RESPONSE(last_error); + return CreateSuccessResponse(new JSONNumber(last_error)); } -void Execute_Alert() +string Execute_Alert() { - string message; - StringInit(message, 1000); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Message", message); - GET_STRING_VALUE(0, message, "message") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: message = %s", __FUNCTION__, message); -#endif - Alert(message); - - SEND_VOID_RESPONSE + return CreateSuccessResponse(); } -void Execute_ResetLastError() +string Execute_ResetLastError() { ResetLastError(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: called", __FUNCTION__); -#endif - - SEND_VOID_RESPONSE + return CreateSuccessResponse(); } -void Execute_GlobalVariableCheck() +string Execute_GlobalVariableCheck() { - string name; - StringInit(name, 500); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Name", name); - GET_STRING_VALUE(0, name, "name") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: name = %s", __FUNCTION__, name); -#endif - - bool res = GlobalVariableCheck(name); - - SEND_BOOL_RESPONSE(res) + bool result = GlobalVariableCheck(name); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_GlobalVariableTime() +string Execute_GlobalVariableTime() { - string name; - StringInit(name, 500); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Name", name); - GET_STRING_VALUE(0, name, "name") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: name = %s", __FUNCTION__, name); -#endif - - datetime time = GlobalVariableTime(name); - - SEND_INT_RESPONSE((int)time) + datetime result = GlobalVariableTime(name); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_GlobalVariableDel() +string Execute_GlobalVariableDel() { - string name; - StringInit(name, 500); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Name", name); - GET_STRING_VALUE(0, name, "name") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: name = %s", __FUNCTION__, name); -#endif - - bool res = GlobalVariableDel(name); - - SEND_BOOL_RESPONSE(res) + bool result = GlobalVariableDel(name); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_GlobalVariableGet() +string Execute_GlobalVariableGet() { - string name; - StringInit(name, 500); - - GET_STRING_VALUE(0, name, "name") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: name = %s", __FUNCTION__, name); -#endif + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Name", name); - double res = GlobalVariableGet(name); - - SEND_DOUBLE_RESPONSE(res) + double result = GlobalVariableGet(name); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_GlobalVariableName() +string Execute_GlobalVariableName() { - int index; + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "Index", index); - GET_INT_VALUE(0, index, "index") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: index = %d", __FUNCTION__, index); -#endif - - string name = GlobalVariableName(index); - - SEND_STRING_RESPONSE(name) + string result = GlobalVariableName(index); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_GlobalVariableSet() +string Execute_GlobalVariableSet() { - string name; - double value; - StringInit(name, 500); - - GET_STRING_VALUE(0, name, "name") - GET_DOUBLE_VALUE(1, value, "value") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: name = %s, value = %f", __FUNCTION__, name, value); -#endif + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_DOUBLE_JSON_VALUE(jo, "Value", value); - datetime res = GlobalVariableSet(name, value); - - SEND_INT_RESPONSE((int)res) + datetime result = GlobalVariableSet(name, value); + return CreateSuccessResponse(new JSONNumber((int)result)); } -void Execute_GlobalVariablesFlush() +string Execute_GlobalVariablesFlush() { -#ifdef __DEBUG_LOG__ - PrintFormat("%s: called.", __FUNCTION__); -#endif - GlobalVariablesFlush(); - - SEND_VOID_RESPONSE + return CreateSuccessResponse(); } -void Execute_ChartOpen() +string Execute_ChartOpen() { - string symbol; - int timeframe; - StringInit(symbol, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Timeframe", timeframe); - if (!getStringValue(ExpertHandle, 0, symbol, _error)) - { - PrintParamError("ChartOpen", "symbol", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getIntValue(ExpertHandle, 1, timeframe, _error)) - { - PrintParamError("ChartOpen", "timeframe", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - - if (!sendLongResponse(ExpertHandle, ChartOpen(symbol, (ENUM_TIMEFRAMES)timeframe), _response_error)) - { - PrintResponseError("ChartOpen", _response_error); - } + long result = ChartOpen(symbol, (ENUM_TIMEFRAMES)timeframe); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartFirst() +string Execute_ChartFirst() { - if (!sendLongResponse(ExpertHandle, ChartFirst(), _response_error)) - { - PrintResponseError("ChartFirst", _response_error); - } + long result = ChartFirst(); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartNext() +string Execute_ChartNext() { - long ChartId; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); - if (!getLongValue(ExpertHandle, 0, ChartId, _error)) - { - PrintParamError("ChartFirst", "ChartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendLongResponse(ExpertHandle, ChartNext(ChartId), _response_error)) - { - PrintResponseError("ChartFirst", _response_error); - } + long result = ChartNext(chart_id); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartClose() +string Execute_ChartClose() { - long chart_id; - GET_LONG_VALUE(0, chart_id, "chart_id") + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d", __FUNCTION__, chart_id); -#endif - bool result = ChartClose(chart_id); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartSymbol() +string Execute_ChartSymbol() { - long ChartId; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); - if (!getLongValue(ExpertHandle, 0, ChartId, _error)) - { - PrintParamError("ChartSymbol", "ChartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendStringResponse(ExpertHandle, ChartSymbol(ChartId), _response_error)) - { - PrintResponseError("ChartSymbol", _response_error); - } + string result = ChartSymbol(chart_id); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_ChartPeriod() +string Execute_ChartPeriod() { - long chart_id; - GET_LONG_VALUE(0, chart_id, "chart_id") + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d", __FUNCTION__, chart_id); -#endif - - ENUM_TIMEFRAMES period = ChartPeriod(chart_id); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: period = %s", __FUNCTION__, EnumToString(period)); -#endif - - SEND_INT_RESPONSE((int)period) + ENUM_TIMEFRAMES result = ChartPeriod(chart_id); + return CreateSuccessResponse(new JSONNumber((int)result)); } -void Execute_ChartSetDouble() +string Execute_ChartSetDouble() { - long chart_id; - int prop_id; - double value; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); + GET_DOUBLE_JSON_VALUE(jo, "Value", value); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, prop_id, "prop_id") - GET_DOUBLE_VALUE(2, value, "value") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, prop_id = %d, value = %f", __FUNCTION__, chart_id, prop_id, value); -#endif - bool result = ChartSetDouble(chart_id, (ENUM_CHART_PROPERTY_DOUBLE)prop_id, value); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartSetInteger() +string Execute_ChartSetInteger() { - long chart_id; - int prop_id; - long value; - - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, prop_id, "prop_id") - GET_LONG_VALUE(2, value, "value") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, prop_id = %d, value = %d", __FUNCTION__, chart_id, prop_id, value); -#endif + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); + GET_LONG_JSON_VALUE(jo, "Value", value); bool result = ChartSetInteger(chart_id, (ENUM_CHART_PROPERTY_INTEGER)prop_id, value); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartSetString() +string Execute_ChartSetString() { - long chart_id; - int prop_id; - string value; - StringInit(value, 1000); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); + GET_STRING_JSON_VALUE(jo, "Value", value); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, prop_id, "prop_id") - GET_STRING_VALUE(2, value, "value") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, prop_id = %d, value = %s", __FUNCTION__, chart_id, prop_id, value); -#endif - bool result = ChartSetString(chart_id, (ENUM_CHART_PROPERTY_STRING)prop_id, value); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartGetDouble() +string Execute_ChartGetDouble() { - long chart_id; - int prop_id; - int sub_window; - - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, prop_id, "prop_id") - GET_INT_VALUE(2, sub_window, "sub_window") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, prop_id = %d, sub_window = %d", __FUNCTION__, chart_id, prop_id, sub_window); -#endif + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); + GET_INT_JSON_VALUE(jo, "SubWindow", sub_window); double result = ChartGetDouble(chart_id, (ENUM_CHART_PROPERTY_DOUBLE)prop_id, sub_window); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %f", __FUNCTION__, result); -#endif - - SEND_DOUBLE_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartGetInteger() +string Execute_ChartGetInteger() { - long chart_id; - int prop_id; - int sub_window; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); + GET_INT_JSON_VALUE(jo, "SubWindow", sub_window); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, prop_id, "prop_id") - GET_INT_VALUE(2, sub_window, "sub_window") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, prop_id = %d, sub_window = %d", __FUNCTION__, chart_id, prop_id, sub_window); -#endif - long result = ChartGetInteger(chart_id, (ENUM_CHART_PROPERTY_INTEGER)prop_id, sub_window); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, result); -#endif - - SEND_LONG_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartGetString() +string Execute_ChartGetString() { - long chart_id; - int prop_id; - - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, prop_id, "prop_id") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, prop_id = %d", __FUNCTION__, chart_id, prop_id); -#endif + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "PropId", prop_id); string result = ChartGetString(chart_id, (ENUM_CHART_PROPERTY_STRING)prop_id); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, result); -#endif - - SEND_STRING_RESPONSE(result) - - ChartRedraw(chart_id); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_ChartNavigate() +string Execute_ChartNavigate() { - long chart_id; - int position; - int shift; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "Position", position); + GET_INT_JSON_VALUE(jo, "Shift", shift); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, position, "position") - GET_INT_VALUE(2, shift, "shift") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, position = %d, shift = %d", __FUNCTION__, chart_id, position, shift); -#endif - bool result = ChartNavigate(chart_id, (ENUM_CHART_POSITION)position, shift); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } string Execute_ChartIndicatorDelete() @@ -6176,15 +3200,12 @@ string Execute_ChartIndicatorDelete() return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartIndicatorName() +string Execute_ChartIndicatorName() { - long chart_id; - int sub_window; - int index; - - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, sub_window, "sub_window") - GET_INT_VALUE(2, index, "index") + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "SubWindow", sub_window); + GET_INT_JSON_VALUE(jo, "index", index); #ifdef __DEBUG_LOG__ PrintFormat("%s: chart_id = %I64d, sub_window = %d, index = %d", __FUNCTION__, chart_id, sub_window, index); @@ -6196,462 +3217,245 @@ void Execute_ChartIndicatorName() PrintFormat("%s: result = %s", __FUNCTION__, result); #endif - SEND_STRING_RESPONSE(result) + return CreateSuccessResponse(new JSONString(result)); } -void Execute_ChartIndicatorsTotal() +string Execute_ChartIndicatorsTotal() { - long chart_id; - int sub_window; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "SubWindow", sub_window); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, sub_window, "sub_window") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, sub_window = %d", __FUNCTION__, chart_id, sub_window); -#endif - int result = ChartIndicatorsTotal(chart_id, sub_window); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, result); -#endif - - SEND_INT_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartWindowOnDropped() +string Execute_ChartWindowOnDropped() { int result = ChartWindowOnDropped(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, result); -#endif - - SEND_INT_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartPriceOnDropped() +string Execute_ChartPriceOnDropped() { double result = ChartPriceOnDropped(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %f", __FUNCTION__, result); -#endif - - SEND_DOUBLE_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartTimeOnDropped() +string Execute_ChartTimeOnDropped() { datetime result = ChartTimeOnDropped(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, TimeToString(result)); -#endif - - SEND_INT_RESPONSE((int)result) + return CreateSuccessResponse(new JSONNumber((int)result)); } -void Execute_ChartXOnDropped() +string Execute_ChartXOnDropped() { int result = ChartXOnDropped(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, result); -#endif - - SEND_INT_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartYOnDropped() +string Execute_ChartYOnDropped() { int result = ChartYOnDropped(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, result); -#endif - - SEND_INT_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartSetSymbolPeriod() +string Execute_ChartSetSymbolPeriod() { - long chart_id; - string symbol; - int period; - StringInit(symbol, 100); - - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_STRING_VALUE(1, symbol, "symbol") - GET_INT_VALUE(2, period, "period") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, symbol = %s, period = %d", __FUNCTION__, chart_id, symbol, period); -#endif + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_STRING_JSON_VALUE(jo, "Symbol", symbol); + GET_INT_JSON_VALUE(jo, "Period", period); bool result = ChartSetSymbolPeriod(chart_id, symbol, (ENUM_TIMEFRAMES)period); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartScreenShot() +string Execute_ChartScreenShot() { - long chart_id; - string filename; - int width; - int height; - int align_mode; - StringInit(filename, 100); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_STRING_JSON_VALUE(jo, "Filename", filename); + GET_INT_JSON_VALUE(jo, "Width", width); + GET_INT_JSON_VALUE(jo, "Height", height); + GET_INT_JSON_VALUE(jo, "AlignMode", align_mode); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_STRING_VALUE(1, filename, "filename") - GET_INT_VALUE(2, width, "width") - GET_INT_VALUE(3, height, "height") - GET_INT_VALUE(4, align_mode, "align_mode") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, filename = %s, width = %d, height = %d, align_mode = %d", __FUNCTION__, chart_id, filename, width, height, align_mode); -#endif - bool result = ChartScreenShot(chart_id, filename, width, height, (ENUM_ALIGN_MODE)align_mode); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_WindowBarsPerChart() +string Execute_WindowBarsPerChart() { - + return CreateErrorResponse(-1, "Unsupported function"); } -void Execute_ChartIndicatorAdd() +string Execute_ChartIndicatorAdd() { - long chart_id; - int sub_window; - int indicator_handle; + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "SubWindow", sub_window); + GET_INT_JSON_VALUE(jo, "IndicatorHandle", indicator_handle); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, sub_window, "sub_window") - GET_INT_VALUE(2, indicator_handle, "indicator_handle") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, sub_window = %d, indicator_handle = %d", __FUNCTION__, chart_id, sub_window, indicator_handle); -#endif - bool result = ChartIndicatorAdd(chart_id, sub_window, indicator_handle); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(result)); -#endif - - SEND_BOOL_RESPONSE(result) + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartIndicatorGet() +string Execute_ChartIndicatorGet() { - long chart_id; - int sub_window; - string indicator_shortname; - StringInit(indicator_shortname, 1000); - - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_INT_VALUE(1, sub_window, "sub_window") - GET_STRING_VALUE(2, indicator_shortname, "indicator_shortname") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, sub_window = %d, indicator_shortname = %s", __FUNCTION__, chart_id, sub_window, indicator_shortname); -#endif + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_INT_JSON_VALUE(jo, "SubWindow", sub_window); + GET_STRING_JSON_VALUE(jo, "IndicatorShortname", indicator_shortname); int result = ChartIndicatorGet( chart_id, sub_window, indicator_shortname); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, result); -#endif - - SEND_INT_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartApplyTemplate() +string Execute_ChartApplyTemplate() { - long ChartId; - string TemplateFileName; - StringInit(TemplateFileName, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_STRING_JSON_VALUE(jo, "TemplateFileName", TemplateFileName); - - if (!getLongValue(ExpertHandle, 0, ChartId, _error)) - { - PrintParamError("ChartApplyTemplate", "ChartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, TemplateFileName, _error)) - { - PrintParamError("ChartApplyTemplate", "TemplateFileName", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } StringReplace(TemplateFileName, "\\", "\\\\"); + bool result = ChartApplyTemplate(chart_id, TemplateFileName); + ChartRedraw(chart_id); - if (!sendBooleanResponse(ExpertHandle, ChartApplyTemplate(ChartId, TemplateFileName), _response_error)) - { - PrintResponseError("ChartApplyTemplate", _response_error); - } - ChartRedraw(ChartId); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartSaveTemplate() +string Execute_ChartSaveTemplate() { - long ChartId; - string TemplateFileName; - StringInit(TemplateFileName, 100, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_STRING_JSON_VALUE(jo, "TemplateFileName", TemplateFileName); - - if (!getLongValue(ExpertHandle, 0, ChartId, _error)) - { - PrintParamError("ChartSaveTemplate", "ChartId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - if (!getStringValue(ExpertHandle, 1, TemplateFileName, _error)) - { - PrintParamError("ChartSaveTemplate", "TemplateFileName", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } StringReplace(TemplateFileName, "\\", "\\\\"); + bool result = ChartSaveTemplate(chart_id, TemplateFileName); + ChartRedraw(chart_id); - if (!sendBooleanResponse(ExpertHandle, ChartSaveTemplate(ChartId, TemplateFileName), _response_error)) - { - PrintResponseError("ChartSaveTemplate", _response_error); - } - ChartRedraw(ChartId); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_ChartWindowFind() +string Execute_ChartWindowFind() { - long chart_id; - string indicator_shortname; - StringInit(indicator_shortname, 200, 0); + GET_JSON_PAYLOAD(jo); + GET_LONG_JSON_VALUE(jo, "ChartId", chart_id); + GET_STRING_JSON_VALUE(jo, "IndicatorShortname", indicator_shortname); - GET_LONG_VALUE(0, chart_id, "chart_id") - GET_STRING_VALUE(1, indicator_shortname, "indicator_shortname") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d, indicator_shortname = %s", __FUNCTION__, chart_id, indicator_shortname); -#endif - int result = ChartWindowFind(chart_id, indicator_shortname); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, result); -#endif - - SEND_INT_RESPONSE(result) + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_TerminalInfoString() +string Execute_TerminalInfoString() { - int propertyId; + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "PropertyId", propertyId); - if (!getIntValue(ExpertHandle, 0, propertyId, _error)) - { - PrintParamError("TerminalInfoString", "propertyId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendStringResponse(ExpertHandle, TerminalInfoString((ENUM_TERMINAL_INFO_STRING)propertyId), _response_error)) - { - PrintResponseError("TerminalInfoString", _response_error); - } + string result = TerminalInfoString((ENUM_TERMINAL_INFO_STRING)propertyId); + return CreateSuccessResponse(new JSONString(result)); } -void Execute_GlobalVariableTemp() +string Execute_GlobalVariableTemp() { - string name; - StringInit(name, 500); - - GET_STRING_VALUE(0, name, "name") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: name = %s", __FUNCTION__, name); -#endif + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Name", name); - bool res = GlobalVariableTemp(name); - - SEND_BOOL_RESPONSE(res) + bool result = GlobalVariableTemp(name); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_GlobalVariableSetOnCondition() +string Execute_GlobalVariableSetOnCondition() { - string name; - double value; - double check_value; - StringInit(name, 500); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "Name", name); + GET_DOUBLE_JSON_VALUE(jo, "Value", value); + GET_DOUBLE_JSON_VALUE(jo, "CheckValue", check_value); - GET_STRING_VALUE(0, name, "name") - GET_DOUBLE_VALUE(1, value, "value") - GET_DOUBLE_VALUE(2, check_value, "check_value") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: name = %s, value = %f, check_value = %f", __FUNCTION__, name, value, check_value); -#endif - - bool res = GlobalVariableSetOnCondition(name, value, check_value); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(res)); -#endif - - SEND_BOOL_RESPONSE(res) + bool result = GlobalVariableSetOnCondition(name, value, check_value); + return CreateSuccessResponse(new JSONBool(result)); } -void Execute_GlobalVariablesDeleteAll() +string Execute_GlobalVariablesDeleteAll() { - string prefix_name; - int limit_data; - StringInit(prefix_name, 500); + GET_JSON_PAYLOAD(jo); + GET_STRING_JSON_VALUE(jo, "PrefixName", prefix_name); + GET_INT_JSON_VALUE(jo, "LimitData", limit_data); - GET_STRING_VALUE(0, prefix_name, "prefix_name") - GET_INT_VALUE(1, limit_data, "limit_data") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: prefix_name = %s, limit_data = %d", __FUNCTION__, prefix_name, limit_data); -#endif - - int res = GlobalVariablesDeleteAll(prefix_name, (datetime)limit_data); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, res); -#endif - - SEND_INT_RESPONSE(res) + int result = GlobalVariablesDeleteAll(prefix_name, (datetime)limit_data); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_GlobalVariablesTotal() +string Execute_GlobalVariablesTotal() { - int res = GlobalVariablesTotal(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, res); -#endif - - SEND_INT_RESPONSE(res) + int result = GlobalVariablesTotal(); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_UnlockTicks() +string Execute_UnlockTicks() { if (!IsTesting()) { Print("WARNING: function UnlockTicks can be used only for backtesting"); - return; + return CreateErrorResponse(-1, "UnlockTicks can be used only for backtesting"); } - _is_ticks_locked = false; - - if (!sendVoidResponse(ExpertHandle, _response_error)) - { - PrintResponseError("UnlockTicks", _response_error); - } + return CreateSuccessResponse(); } -void Execute_PositionCloseAll() +string Execute_PositionCloseAll() { - int res = PositionCloseAll(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: result = %d", __FUNCTION__, res); -#endif - - SEND_INT_RESPONSE(res) + int result = PositionCloseAll(); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_TesterStop() +string Execute_TesterStop() { if (!IsTesting()) { Print("WARNING: function TesterStop can be used only for backtesting"); - } - else - { - Print("TesterStop called."); - TesterStop(); + return CreateErrorResponse(-1, "TesterStop can be used only for backtesting"); } - if (!sendVoidResponse(ExpertHandle, _response_error)) - { - PrintResponseError("TesterStop", _response_error); - } + TesterStop(); + return CreateSuccessResponse(); } -void Execute_TerminalInfoInteger() +string Execute_TerminalInfoInteger() { - int propertyId; + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "PropertyId", propertyId); - if (!getIntValue(ExpertHandle, 0, propertyId, _error)) - { - PrintParamError("TerminalInfoInteger", "propertyId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendIntResponse(ExpertHandle, TerminalInfoInteger((ENUM_TERMINAL_INFO_INTEGER)propertyId), _response_error)) - { - PrintResponseError("TerminalInfoInteger", _response_error); - } + int result = TerminalInfoInteger((ENUM_TERMINAL_INFO_INTEGER)propertyId); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_TerminalInfoDouble() +string Execute_TerminalInfoDouble() { - int propertyId; + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "PropertyId", propertyId); - if (!getIntValue(ExpertHandle, 0, propertyId, _error)) - { - PrintParamError("TerminalInfoDouble", "propertyId", _error); - sendErrorResponse(ExpertHandle, -1, _error, _response_error); - return; - } - - if (!sendDoubleResponse(ExpertHandle, TerminalInfoDouble((ENUM_TERMINAL_INFO_DOUBLE)propertyId), _response_error)) - { - PrintResponseError("TerminalInfoDouble", _response_error); - } + double result = TerminalInfoDouble((ENUM_TERMINAL_INFO_DOUBLE)propertyId); + return CreateSuccessResponse(new JSONNumber(result)); } -void Execute_ChartId() +string Execute_ChartId() { long id = ChartID(); - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: id = %I64d", __FUNCTION__, id); -#endif - - SEND_LONG_RESPONSE(id) + return CreateSuccessResponse(new JSONNumber(id)); } -void Execute_ChartRedraw() +string Execute_ChartRedraw() { - long chart_id; - GET_LONG_VALUE(0, chart_id, "chart_id") - -#ifdef __DEBUG_LOG__ - PrintFormat("%s: chart_id = %I64d", __FUNCTION__, chart_id); -#endif + GET_JSON_PAYLOAD(jo); + GET_INT_JSON_VALUE(jo, "ChartId", chart_id); ChartRedraw(chart_id); - - SEND_VOID_RESPONSE + return CreateSuccessResponse(); } -void PrintParamError(string paramName) +// TODO !!!!!!!! +/*void PrintParamError(string paramName) { Print("[ERROR] parameter: ", paramName); } @@ -6665,108 +3469,7 @@ void PrintResponseError(string commandName, string error = "") { PrintFormat("[ERROR] response: %s. %s", commandName, error); } - -void ReadMqlTradeRequestFromCommand(MqlTradeRequest& request) -{ - string symbol; - string comment; - int tmpEnumValue; - ulong magic = 0; - StringInit(symbol, 100, 0); - StringInit(comment, 1000, 0); - - getIntValue(ExpertHandle, 0, tmpEnumValue, _error); - request.action = (ENUM_TRADE_REQUEST_ACTIONS)tmpEnumValue; - - getULongValue(ExpertHandle, 1, magic, _error); - request.magic = magic; - getULongValue(ExpertHandle, 2, request.order, _error); - getStringValue(ExpertHandle, 3, symbol, _error); - request.symbol = symbol; - getDoubleValue(ExpertHandle, 4, request.volume, _error); - getDoubleValue(ExpertHandle, 5, request.price, _error); - getDoubleValue(ExpertHandle, 6, request.stoplimit, _error); - getDoubleValue(ExpertHandle, 7, request.sl, _error); - getDoubleValue(ExpertHandle, 8, request.tp, _error); - getULongValue(ExpertHandle, 9, request.deviation, _error); - getIntValue(ExpertHandle, 10, tmpEnumValue, _error); - request.type = (ENUM_ORDER_TYPE)tmpEnumValue; - getIntValue(ExpertHandle, 11, tmpEnumValue, _error); - request.type_filling = (ENUM_ORDER_TYPE_FILLING)tmpEnumValue; - getIntValue(ExpertHandle, 12, tmpEnumValue, _error); - request.type_time = (ENUM_ORDER_TYPE_TIME)tmpEnumValue; - getIntValue(ExpertHandle, 13, tmpEnumValue, _error); - request.expiration = (datetime)tmpEnumValue; - getStringValue(ExpertHandle, 14, comment, _error); - request.comment = comment; - getULongValue(ExpertHandle, 15, request.position, _error); - getULongValue(ExpertHandle, 16, request.position_by, _error); -} - -string BoolToString(bool value) -{ - return value ? "1" : "0"; -} - -string ResultToString(bool retVal, MqlTradeResult& result) -{ - string strResult; - - StringConcatenate(strResult - , BoolToString(retVal), PARAM_SEPARATOR - , result.retcode, PARAM_SEPARATOR - , result.deal, PARAM_SEPARATOR - , result.order, PARAM_SEPARATOR - , result.volume, PARAM_SEPARATOR - , result.price, PARAM_SEPARATOR - , result.bid, PARAM_SEPARATOR - , result.ask, PARAM_SEPARATOR - , result.comment, PARAM_SEPARATOR - , result.request_id); - - return strResult; -} - -string ResultToString(bool retVal, MqlTradeCheckResult& result) -{ - string strResult; - - StringConcatenate(strResult - , BoolToString(retVal), PARAM_SEPARATOR - , result.retcode, PARAM_SEPARATOR - , result.balance, PARAM_SEPARATOR - , result.equity, PARAM_SEPARATOR - , result.profit, PARAM_SEPARATOR - , result.margin, PARAM_SEPARATOR - , result.margin_free, PARAM_SEPARATOR - , result.margin_level, PARAM_SEPARATOR - , result.comment, PARAM_SEPARATOR); - - return strResult; -} - -string ResultToString(bool retVal, double result) -{ - string strResult; - - StringConcatenate(strResult - , BoolToString(retVal), PARAM_SEPARATOR - , result); - - return strResult; -} - -string ResultToString(bool retVal, datetime from, datetime to) -{ - string strResult; - - StringConcatenate(strResult - , BoolToString(retVal), PARAM_SEPARATOR - , (int)from, PARAM_SEPARATOR - , (int)to); - - return strResult; -} +*/ bool OrderCloseAll() {