From f7e06c157086ff5a24c575400e3688af8ec0bb32 Mon Sep 17 00:00:00 2001 From: vdemydiuk Date: Mon, 26 Feb 2018 18:21:44 +0200 Subject: [PATCH] Issue #92: Added functions IndicatorCreate and IndicatorRelease --- MtApi5/MqlParam.cs | 10 ++ MtApi5/Mt5CommandType.cs | 4 +- MtApi5/Mt5Enums.cs | 64 ++++++++++++ MtApi5/MtApi5.csproj | 2 + MtApi5/MtApi5Client.cs | 26 +++++ MtApi5/Requests/IndicatorCreateRequest.cs | 14 +++ MtApi5/Requests/RequestType.cs | 3 +- TestClients/MtApi5TestClient/MainWindow.xaml | 4 + TestClients/MtApi5TestClient/ViewModel.cs | 49 +++++++++ mq5/MtApi5.ex5 | Bin 502640 -> 520352 bytes mq5/MtApi5.mq5 | 101 ++++++++++++++++++- 11 files changed, 273 insertions(+), 4 deletions(-) create mode 100644 MtApi5/MqlParam.cs create mode 100644 MtApi5/Requests/IndicatorCreateRequest.cs diff --git a/MtApi5/MqlParam.cs b/MtApi5/MqlParam.cs new file mode 100644 index 00000000..ac7d4aa4 --- /dev/null +++ b/MtApi5/MqlParam.cs @@ -0,0 +1,10 @@ +namespace MtApi5 +{ + public class MqlParam + { + public ENUM_DATATYPE DataType { get; set; } + public long? IntegerValue { get; set; } + public double? DoubleValue { get; set; } + public string StringValue { get; set; } + } +} diff --git a/MtApi5/Mt5CommandType.cs b/MtApi5/Mt5CommandType.cs index 3adc3e9c..535c00f8 100755 --- a/MtApi5/Mt5CommandType.cs +++ b/MtApi5/Mt5CommandType.cs @@ -177,6 +177,8 @@ namespace MtApi5 TimeCurrent = 127, TimeTradeServer = 128, TimeLocal = 129, - TimeGMT = 130 + TimeGMT = 130, + + IndicatorRelease = 131 } } diff --git a/MtApi5/Mt5Enums.cs b/MtApi5/Mt5Enums.cs index 1cd3cb7b..3389ff45 100755 --- a/MtApi5/Mt5Enums.cs +++ b/MtApi5/Mt5Enums.cs @@ -784,4 +784,68 @@ namespace MtApi5 } #endregion //Smoothing Methods + + #region Indicator constants + + public enum ENUM_INDICATOR + { + IND_AC = 5, // Accelerator Oscillator + IND_AD = 6, // Accumulation/Distribution + IND_ADX = 8, // Average Directional Index + IND_ADXW = 9, // ADX by Welles Wilder + IND_ALLIGATOR = 7, // Alligator + IND_AMA = 40, // Adaptive Moving Average + IND_AO = 11, // Awesome Oscillator + IND_ATR = 10, // Average True Range + IND_BANDS = 13, // Bollinger Bands® + IND_BEARS = 12, // Bears Power + IND_BULLS = 14, // Bulls Power + IND_BWMFI = 22, // Market Facilitation Index + IND_CCI = 15, // Commodity Channel Index + IND_CHAIKIN = 41, // Chaikin Oscillator + IND_CUSTOM = 43, // Custom indicator + IND_DEMA = 36, // Double Exponential Moving Average + IND_DEMARKER = 16, // DeMarker + IND_ENVELOPES = 17, // Envelopes + IND_FORCE = 18, // Force Index + IND_FRACTALS = 19, // Fractals + IND_FRAMA = 39, // Fractal Adaptive Moving Average + IND_GATOR = 20, // Gator Oscillator + IND_ICHIMOKU = 21, // Ichimoku Kinko Hyo + IND_MA = 26, // Moving Average + IND_MACD = 23, // MACD + IND_MFI = 25, // Money Flow Index + IND_MOMENTUM = 24, // Momentum + IND_OBV = 28, // On Balance Volume + IND_OSMA = 27, // OsMA + IND_RSI = 30, // Relative Strength Index + IND_RVI = 31, // Relative Vigor Index + IND_SAR = 29, // Parabolic SAR + IND_STDDEV = 32, // Standard Deviation + IND_STOCHASTIC = 33, // Stochastic Oscillator + IND_TEMA = 37, // Triple Exponential Moving Average + IND_TRIX = 38, // Triple Exponential Moving Averages Oscillator + IND_VIDYA = 42, // Variable Index Dynamic Average + IND_VOLUMES = 34, // Volumes + IND_WPR = 35 // Williams' Percent Ranges } + + public enum ENUM_DATATYPE + { + TYPE_BOOL = 1, + TYPE_CHAR = 2, + TYPE_UCHAR = 3, + TYPE_SHORT = 4, + TYPE_USHORT = 5, + TYPE_COLOR = 6, + TYPE_INT = 7, + TYPE_UINT = 8, + TYPE_DATETIME = 9, + TYPE_LONG = 10, + TYPE_ULONG = 11, + TYPE_FLOAT = 12, + TYPE_DOUBLE = 13, + TYPE_STRING = 14 + } + #endregion +} diff --git a/MtApi5/MtApi5.csproj b/MtApi5/MtApi5.csproj index d012aecc..e72aa0fd 100755 --- a/MtApi5/MtApi5.csproj +++ b/MtApi5/MtApi5.csproj @@ -49,6 +49,7 @@ + @@ -68,6 +69,7 @@ + diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs index 4c55b6e5..2e775f91 100755 --- a/MtApi5/MtApi5Client.cs +++ b/MtApi5/MtApi5Client.cs @@ -1262,6 +1262,32 @@ namespace MtApi5 }); return response; } + + /// + ///The function returns the handle of a specified technical indicator created based on the array of parameters of MqlParam type. + /// + ///Name of a symbol, on data of which the indicator is calculated. NULL means the current symbol. + ///The value of the timeframe can be one of values of the ENUM_TIMEFRAMES enumeration, 0 means the current timeframe. + ///Indicator type, can be one of values of the ENUM_INDICATOR enumeration. + ///An array of MqlParam type, whose elements contain the type and value of each input parameter of a technical indicator. + public int IndicatorCreate(string symbol, ENUM_TIMEFRAMES period, ENUM_INDICATOR indicatorType, List parameters = null) + { + var response = SendRequest(new IndicatorCreateRequest + { + Symbol = symbol, + Period = period, + IndicatorType = indicatorType, + Parameters = parameters + }); + return response; + } + + public bool IndicatorRelease(int indicatorHandle) + { + var commandParameters = new ArrayList { indicatorHandle }; + + return SendCommand(Mt5CommandType.IndicatorRelease, commandParameters); + } #endregion #region Market Info diff --git a/MtApi5/Requests/IndicatorCreateRequest.cs b/MtApi5/Requests/IndicatorCreateRequest.cs new file mode 100644 index 00000000..e7af6543 --- /dev/null +++ b/MtApi5/Requests/IndicatorCreateRequest.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace MtApi5.Requests +{ + internal class IndicatorCreateRequest: RequestBase + { + public override RequestType RequestType => RequestType.IndicatorCreate; + + public string Symbol { get; set; } + public ENUM_TIMEFRAMES Period { get; set; } + public ENUM_INDICATOR IndicatorType { get; set; } + public List Parameters { get; set; } + } +} \ No newline at end of file diff --git a/MtApi5/Requests/RequestType.cs b/MtApi5/Requests/RequestType.cs index 52bdd181..735ce6f3 100755 --- a/MtApi5/Requests/RequestType.cs +++ b/MtApi5/Requests/RequestType.cs @@ -10,6 +10,7 @@ namespace MtApi5.Requests OrderSend = 3, PositionOpen = 4, OrderCheck = 5, - MarketBookGet = 6 + MarketBookGet = 6, + IndicatorCreate = 7 } } \ No newline at end of file diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml index 13c800ac..113f6afd 100755 --- a/TestClients/MtApi5TestClient/MainWindow.xaml +++ b/TestClients/MtApi5TestClient/MainWindow.xaml @@ -352,6 +352,10 @@