MT4程序在MT5上运行:MT4指标函数在MT5上成功编译和运行

发布时间:2024年01月19日

MT4指标函数移植到MT5上的意义

  • 了解MQL4与MQL5语言的差别,加深学习理解,利于开发通用MT4与MT5的程序。
  • 很多优秀的指标使用MQL4语言开发,无法直接运行mt5上,移值后可节省二次开发MT5指标的时间。
  • MT5优于MT4,当运行复杂的程序时MT5比MT4更稳定,并且MT5具有底层改进和新功能,例如网络通讯和数据库。
  • MT5的回测功能更强大,可实现更精细的多品种回测,MT4一次只能处理一个交易品种且准确性低。

为什么MT4指标无法在MT5上运行

  • MT4中大量系统定义的变量在MT5中被取消,例如Ask,Bid等。
  • MT5绘制指标线的函数与MT4完全不同,例如MT5中指标绘图均是以Plot开头的函数。
  • MT4和MT5指标默认缓冲区的数组序列方向不一样,MT4是从最新到最旧,0号是最新数据,而MT5恰恰相反,0号是最旧数据。
  • 旧版MT4的事件函数start()已无法在MT5中运行,需要重新替换。

MT4指标函数在MT5上的重定义与代码实现

//+------------------------------------------------------------------+
//|                                                indicator4to5.mqh |
//|                                      Copyright 2024, VX: mtquant |
//|                                                   公号: 迈达量化 |
//+------------------------------------------------------------------+
// MT4指标函数在MT5中重新定义
//void                 InitMql4(void);
//void                 GetMQL4Tick();
//void                 GetMQL4(void);
//int                  MQL4Run(int rates_total, int prev_calculated);
//int                  CountedMQL4(void);
//void                 SetIndexStyleMQL4(int index, int type, int style=EMPTY, int width=EMPTY, color clr=CLR_NONE);
//void                 SetLevelStyleMQL4(int draw_style, int line_width, color clr=CLR_NONE);
//bool                 SetIndexBufferMQL4(int index, double &buffer[], int type);
//bool                 SetIndexBufferMQL4(int index, double &buffer[], ENUM_INDEXBUFFER_TYPE data_type=INDICATOR_DATA) export
//void                 SetIndexDrawBeginMQL4(int index, int begin);
//void                 SetIndexLabelMQL4(int index, string text);
//void                 SetIndexShiftMQL4(int buffer, int shift);
//int                  ArrayCopyRatesMQL4(void &dest_array[][], string symbol=NULL, int timeframe=0);
//int                  ArrayCopyRatesMQL4(void &dest_array[][], string symbol=NULL, int timeframe=0);
//int                  ArrayCopySeriesMQL4(double &array[], int series_index, string symbol=NULL, int tf=0);
//int                  ArrayDimensionMQL4(double &array[]);
//int                  ArrayMaximumMQL4(double &array[], int count=WHOLE_ARRAY, int start=0);
//int                  ArrayMinimumMQL4(double &array[], int count=WHOLE_ARRAY, int start=0);
//bool                 ArraySortMQL4(double &array[], int count=WHOLE_ARRAY, int start=0, int direction=MODE_ASCEND);
//ENUM_TIMEFRAMES      TFMigrate(int tf);
//ENUM_MA_METHOD       MethodMigrate(int method);
//ENUM_APPLIED_PRICE   PriceMigrate(int price);
//ENUM_STO_PRICE       StoFieldMigrate(int field);
//double               CopyBufferMQL4(int handle,int index,int shift);
//int                  BarsMQL4(void);
//double               MarketInfoMQL4(string symbol, int type);
//double               iADMQL4(string symbol, int tf, int shift);
//double               iADXMQL4(string symbol, int tf, int period, int price, int mode, int shift);
//double               iAlligatorMQL4(string symbol, int tf, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int method, int price, int mode, int shift);
//double               iAOMQL4(string symbol, int timeframe, int shift);
//double               iATRMQL4(string symbol, int tf, int period, int shift);
//double               iBandsMQL4(string symbol, int tf, int period, double deviation, int bands_shift, int method, int mode, int shift);
//int                  iBarsMQL4(string symbol, int tf);
//int                  iBarShiftMQL4(string symbol, int tf, datetime time, bool exact=false);
//double               iBearsPowerMQL4(string symbol, int tf, int period, int price, int shift);
//double               iBullsPowerMQL4(string symbol, int tf, int period, int price, int shift);
//double               iBWMFIMQL4(string symbol, int tf, int shift);
//double               iCCIMQL4(string symbol, int tf, int period, int price, int shift);
//double               iCloseMQL4(string symbol, int tf, int shift);
//double               iDeMarkerMQL4(string symbol, int tf, int period, int shift);
//double               iEnvelopesMQL4(string symbol, int tf, int ma_period, int method, int ma_shift, int price, double deviation, int mode, int shift);
//double               iFractalsMQL4(string symbol, int tf, int mode, int shift);
//double               iForceMQL4(string symbol, int tf, int period, int method, int price, int shift);
//double               iGatorMQL4(string symbol, int tf, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int method, int price, int mode, int shift);
//double               iHighMQL4(string symbol, int tf, int shift);
//int                  iHighestMQL4(string symbol,int tf,int mode,int Much,int shift);
//double               iLowMQL4(string symbol, int tf, int shift);
//double               iOpenMQL4(string symbol, int tf, int shift);
//double               iRSIMQL4(string symbol, int tf, int period, int price, int shift);
//double               iRVIMQL4(string symbol, int tf, int period, int mode, int shift);
//double               iSARMQL4(string symbol, int tf, double step, double maximum, int shift);
//double               iStdDevMQL4(string symbol, int tf, int ma_period, int ma_shift, int method, int price, int shift);
//datetime             iTimeMQL4(string symbol, int tf, int shift);
//int                  iLowest(string symbol, int tf, int mode, int Much, int shift);
//double               iMACDMQL4(string symbol, int tf, int fast_ema_period, int slow_ema_period, int signal_period, int price, int mode, int shift);
//double               iIchimokuMQL4(string symbol, int tf, int tenkan_sen, int kijun_sen, int senkou_span_b, int mode, int shift);
//double               iMFIMQL4(string symbol, int tf, int period, int shift);
//double               iMomentumMQL4(string symbol, int tf, int period, int price, int shift);
//double               iOBVMQL4(string symbol, int tf, int price, int shift);
//double               iOsMAMQL4(string symbol, int tf, int fast_ema_period, int slow_ema_period, int signal_period, int price, int shift);
//long                 iVolumeMQL4(string symbol, int tf, int shift);
//double               iWPRMQL4(string symbol, int tf, int period, int shift);
//double               iBandsOnArrayMQL4(double &array[], int total, int period, int deviation, int bands_shift, int mode, int shift);
//double               iCCIOnArrayMQL4(double &array[], int total, int period, int shift);
//double               iEnvelopesOnArrayMQL4(double &array[], int total, int ma_period, int ma_method, int ma_shift, double deviation, int mode, int shift);
//double               iMAOnArrayMQL4(double &array[], int total, int period, int ma_shift, int ma_method, int shift);
//double               iMomentumOnArrayMQL4(double &array[], int total, int period, int shift);
//double               iRSIOnArrayMQL4(double &array[], int total, int period, int shift);
//double               iStdDevOnArrayMQL4(double array[], int total, int ma_period, int ma_shift, int ma_method, int shift);
//void                 EMA(double &array[], int InpMAPeriod);
//void                 SimpleMA(double &price[], double &ExtLineBuffer[], int InpMAPeriod);
//void                 SmoothedMA(double &price[], double &ExtLineBuffer[], int InpMAPeriod);
//void                 LWMA(double &price[], double &ExtLineBuffer[], int InpMAPeriod);
//void                 HideTestIndicatorsMQL4(bool hide);
//void                 IndicatorBuffersMQL4(int count);
//int                  IndicatorCountedMQL4(void);
//---                          
#define MODE_ASCEND            0
#define MODE_DESCEND           1
//---                          
#define MODE_OPEN              0
#define MODE_LOW               1
#define MODE_HIGH              2
#define MODE_CLOSE             3
#define MODE_VOLUME            4 
#define MODE_TIME              5
#define MODE_REAL_VOLUME       6
#define MODE_TICKVOLUME        7
#define MODE_REALVOLUME        8
#define MODE_BID               9
#define MODE_ASK               10
#define MODE_POINT             11
#define MODE_DIGITS            12
#define MODE_SPREAD            13
#define MODE_STOPLEVEL         14
#define MODE_LOTSIZE           15
#define MODE_TICKVALUE         16
#define MODE_TICKSIZE          17
#define MODE_SWAPLONG          18
#define MODE_SWAPSHORT         19
#define MODE_STARTING          20
#define MODE_EXPIRATION        21
#define MODE_TRADEALLOWED      22
#define MODE_MINLOT            23
#define MODE_LOTSTEP           24
#define MODE_MAXLOT            25
#define MODE_SWAPTYPE          26
#define MODE_PROFITCALCMODE    27
#define MODE_MARGINCALCMODE    28
#define MODE_MARGININIT        29
#define MODE_MARGINMAINTENANCE 30
#define MODE_MARGINHEDGED      31
#define MODE_MARGINREQUIRED    32
#define MODE_FREEZELEVEL       33
#define MODE_CLOSEBY_ALLOWED   34
// Indicator Lines
#define MODE_MAIN              (0)   // Base indicator line
#define MODE_SIGNAL            (1)   // Sinal line
#define MODE_PLUSDI            (1)   // +DI indicator line
#define MODE_MINUSDI           (2)   // -DI indicator line
#define MODE_UPPER             (1)   // Upper line
#define MODE_LOWER             (2)   // Lower line
#define MODE_GATORJAW          (1)   // Jaw line
#define MODE_GATORTEETH        (2)   // Teeth line
#define MODE_GATORLIPS         (3)   // Lips line
#define MODE_TENKANSEN         (1)   // Tenkan-sen
#define MODE_KIJUNSEN          (2)   // Kijun-sen
#define MODE_SENKOUSPANA       (3)   // Senkou Span A
#define MODE_SENKOUSPANB       (4)   // Senkou Span B
#define MODE_CHIKOUSPAN        (5)   // Chikou Span
// 交易相关函数
double       _Open[];
double       _Close[];
double       _High[];
double       _Low[];
double       _Ask,_Bid;
int          _CountedMQL4;
//+------------------------------------------------------------------
//| 为MQL4环境初始化标准数组                                        |
//+------------------------------------------------------------------
void InitMql4(void) export
{
    ArraySetAsSeries(_Open, true);
    ArraySetAsSeries(_Close, true);
    ArraySetAsSeries(_High, true);
    ArraySetAsSeries(_Low, true);
}
//+------------------------------------------------------------------
//|转换MQL4环境中的报价数据                                         |
//+------------------------------------------------------------------
void GetMQL4Tick() export
{
    MqlRates rates[1];
    CopyRates(Symbol(), 0, 0, 1, rates);
    _Open[0]=rates[0].open;
    _Close[0]=rates[0].close;
    _High[0]=rates[0].high;
    _Low[0]=rates[0].low;
    MqlTick tick;
    SymbolInfoTick(Symbol(), tick);
    _Ask = tick.ask;
    _Bid = tick.bid;
    _CountedMQL4 = ArraySize(_Close);
}
//+------------------------------------------------------------------
//| 填充MQL4环境                                                    |
//+------------------------------------------------------------------
void GetMQL4(void) export
{
    datetime end_tm = 0;
    datetime start_tm = TimeTradeServer();
    CopyOpen(Symbol(), Period(), start_tm, end_tm, _Open);
    CopyHigh(Symbol(), Period(), start_tm, end_tm, _High);
    CopyLow(Symbol(), Period(), start_tm, end_tm, _Low);
    CopyClose(Symbol(), Period(), start_tm, end_tm, _Close);
    MqlTick tick;
    SymbolInfoTick(Symbol(), tick);
    _Ask = tick.ask;
    _Bid = tick.bid;
    _CountedMQL4=0;
}
//+------------------------------------------------------------------
//| 启动MQL4环境                                                   |
//+------------------------------------------------------------------
// bars - 用于计算的柱形数量
int MQL4Run(int rates_total, int prev_calculated) export
{
    int uncount = rates_total - prev_calculated;
    if (uncount == 0)
        GetMQL4Tick();
    else 
        GetMQL4();
    return ( ArraySize(_Close) );
}
//+------------------------------------------------------------------
//|  返回指标计算K线个数,替代prev_calculated                       |
//+------------------------------------------------------------------
int CountedMQL4(void) export
{
    return (_CountedMQL4);
}
//+------------------------------------------------------------------
//| Sets the new type, style,                                       |
//| width and color for a given indicator line                      |
//+------------------------------------------------------------------
void SetIndexStyleMQL4(int index, int type, int style=EMPTY, int width=EMPTY, color clr=CLR_NONE) export
{
    if (width > -1)      PlotIndexSetInteger(index, PLOT_LINE_WIDTH, width);
    if (clr != CLR_NONE) PlotIndexSetInteger(index, PLOT_LINE_COLOR, clr);
    //
    switch (type)
    {
        case 0:  PlotIndexSetInteger(index, PLOT_DRAW_TYPE, DRAW_LINE);
        case 1:  PlotIndexSetInteger(index, PLOT_DRAW_TYPE, DRAW_SECTION);
        case 2:  PlotIndexSetInteger(index, PLOT_DRAW_TYPE, DRAW_HISTOGRAM);
        case 3:  PlotIndexSetInteger(index, PLOT_DRAW_TYPE, DRAW_ARROW);
        case 4:  PlotIndexSetInteger(index, PLOT_DRAW_TYPE, DRAW_ZIGZAG);
        case 12: PlotIndexSetInteger(index, PLOT_DRAW_TYPE, DRAW_NONE);
        default: PlotIndexSetInteger(index, PLOT_DRAW_TYPE, DRAW_LINE);
    }
    switch (style)
    {
        case 0: PlotIndexSetInteger(index, PLOT_LINE_STYLE, STYLE_SOLID);
        case 1: PlotIndexSetInteger(index, PLOT_LINE_STYLE, STYLE_DASH);
        case 2: PlotIndexSetInteger(index, PLOT_LINE_STYLE, STYLE_DOT);
        case 3: PlotIndexSetInteger(index, PLOT_LINE_STYLE, STYLE_DASHDOT);
        case 4: PlotIndexSetInteger(index, PLOT_LINE_STYLE, STYLE_DASHDOTDOT);
        default: return;
    }
}
//+------------------------------------------------------------------
//|函数设置要在单独的窗口中输出的指标的水平线的新样式、宽度和颜色   |
//+------------------------------------------------------------------
void SetLevelStyleMQL4(int draw_style, int line_width, color clr=CLR_NONE) export
{
    IndicatorSetInteger(INDICATOR_LEVELWIDTH, line_width);
    if (clr != CLR_NONE) IndicatorSetInteger(INDICATOR_LEVELCOLOR, clr);
    switch (draw_style)
    {
        case 0: IndicatorSetInteger(INDICATOR_LEVELSTYLE, STYLE_SOLID);
        case 1: IndicatorSetInteger(INDICATOR_LEVELSTYLE, STYLE_DASH);
        case 2: IndicatorSetInteger(INDICATOR_LEVELSTYLE, STYLE_DOT);
        case 3: IndicatorSetInteger(INDICATOR_LEVELSTYLE, STYLE_DASHDOT);
        case 4: IndicatorSetInteger(INDICATOR_LEVELSTYLE, STYLE_DASHDOTDOT);
        default: return;
    }
}
// 指定指标的缓冲区的绑定预定义缓冲区编好与类型
bool SetIndexBufferMQL4(int index, double &buffer[], ENUM_INDEXBUFFER_TYPE data_type=INDICATOR_DATA) export
{
    //bool b = ::SetIndexBuffer(index, buffer, data_type);
    //ArraySetAsSeries(buffer, true);
    //ArrayInitialize(buffer, EMPTY_VALUE); // default filling
    //return (b);
    return ::SetIndexBuffer(index, buffer, data_type);
}
// 设置指标线的绘制开始时间
void SetIndexDrawBeginMQL4(int index, int begin) export
{
    PlotIndexSetInteger(index, PLOT_DRAW_BEGIN, begin);
}
// 设置要显示在数据窗口和工具提示中的绘制线说明
void SetIndexLabelMQL4(int index, string text) export
{
    PlotIndexSetString(index, PLOT_LABEL, text);
}
// 设置指定缓冲区指标线的绘图偏移量
void SetIndexShiftMQL4(int buffer, int shift) export
{
    PlotIndexSetInteger(buffer, PLOT_SHIFT, shift);
}
//
int ArrayCopyRatesMQL4(MqlRates &rates_array[], string symbol=NULL, int timeframe=0) export
{
    // Unimplemented stub
    Print("Error: ArrayCopyRates() - Not implemented stub.");
    return (-1);
}
//
int ArrayCopyRatesMQL4(double &dest_array[][], string symbol=NULL, int timeframe=0) export
{
    // Unimplemented stub
    Print("Error: ArrayCopyRates() - Not implemented stub.");
    return (-1);
}
// 将一个时间序列数组复制到一个自定义数组,并返回复制元素的数量
int ArrayCopySeriesMQL4(double &array[], int series_index, string symbol=NULL, int tf=0) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int count = Bars(symbol, timeframe);
    switch (series_index)
    {
        case MODE_OPEN:
            return (CopyOpen(symbol, timeframe, 0, count, array));
        case MODE_LOW:
            return (CopyLow(symbol, timeframe, 0, count, array));
        case MODE_HIGH:
            return (CopyHigh(symbol, timeframe, 0, count, array));
        case MODE_CLOSE:
            return (CopyClose(symbol, timeframe, 0, count, array));

        default: return (0);
    }
    //
    return (0);
}
// 返回多维数组秩
int ArrayDimensionMQL4(double &array[]) export
{
    // Unimplemented stub
    Print("Error: ArrayDimension() - Not implemented stub.");
    return (-1);
}
// 搜索具有最大值的元素。函数返回此最大值元素在数组中的位置
int ArrayMaximumMQL4(double &array[], int count=WHOLE_ARRAY, int start=0) export
{
    return ( ArrayMaximum(array, start, count) );
}
// 搜索具有最小值的元素。函数返回此最小值元素在数组中的位置
int ArrayMinimumMQL4(double &array[], int count=WHOLE_ARRAY, int start=0) export
{
    return ( ArrayMinimum(array, start, count) );
}
//+------------------------------------------------------------------
//| Sorts numeric arrays by first dimension                         |
//+------------------------------------------------------------------
bool ArraySortMQL4(double &array[], int count=WHOLE_ARRAY, int start=0, int direction=MODE_ASCEND) export
{
    switch (direction)
    {
        case MODE_ASCEND:  ArraySetAsSeries(array, true);
        case MODE_DESCEND: ArraySetAsSeries(array, false);
        default: ArraySetAsSeries(array, true);
    }
    //
    ArraySort(array);
    return (false);
}
// mt4和mt5周期框架的值不一样,数据类型也不一样
// PERIOD_M30之前一样,但是PERIOD_H1之后不同
// 例如mt5中PERIOD_H1是16385,而mt4是60
// 将时间框架从MQL4转换为MQL5
ENUM_TIMEFRAMES TFMigrate(int tf) export
{
    switch (tf)
    {
        case 0: return (PERIOD_CURRENT);
        case 1: return (PERIOD_M1);
        case 5: return (PERIOD_M5);
        case 15: return (PERIOD_M15);
        case 30: return (PERIOD_M30);
        case 60: return (PERIOD_H1);
        case 240: return (PERIOD_H4);
        case 1440: return (PERIOD_D1);
        case 10080: return (PERIOD_W1);
        case 43200: return (PERIOD_MN1);

        case 2: return (PERIOD_M2);
        case 3: return (PERIOD_M3);
        case 4: return (PERIOD_M4);      
        case 6: return (PERIOD_M6);
        case 10: return (PERIOD_M10);
        case 12: return (PERIOD_M12);
        case 16385: return (PERIOD_H1);
        case 16386: return (PERIOD_H2);
        case 16387: return (PERIOD_H3);
        case 16388: return (PERIOD_H4);
        case 16390: return (PERIOD_H6);
        case 16392: return (PERIOD_H8);
        case 16396: return (PERIOD_H12);
        case 16408: return (PERIOD_D1);
        case 32769: return (PERIOD_W1);
        case 49153: return (PERIOD_MN1);      
        default: return (PERIOD_CURRENT);
    }
}
// 技术指标基于价格序列平滑方法的移植
ENUM_MA_METHOD MethodMigrate(int method) export
{
    switch (method)
    {
        case 0: return (MODE_SMA);
        case 1: return (MODE_EMA);
        case 2: return (MODE_SMMA);
        case 3: return (MODE_LWMA);
        default: return (MODE_SMA);
    }
}
// 技术指标计算价格类型的移植
ENUM_APPLIED_PRICE PriceMigrate(int price) export
{
    switch (price)
    {
        case 1: return (PRICE_CLOSE);
        case 2: return (PRICE_OPEN);
        case 3: return (PRICE_HIGH);
        case 4: return (PRICE_LOW);
        case 5: return (PRICE_MEDIAN);
        case 6: return (PRICE_TYPICAL);
        case 7: return (PRICE_WEIGHTED);
        default: return (PRICE_CLOSE);
    }
}
// 以收盘价或以高低价计算类型的移植
ENUM_STO_PRICE StoFieldMigrate(int field) export
{
    switch (field)
    {
        case 0:  return (STO_LOWHIGH);
        case 1:  return (STO_CLOSECLOSE);
        default: return (STO_LOWHIGH);
    }
}
// 拷贝缓冲区
double CopyBufferMQL4(int handle, int index, int shift) export
{
    double buf[];
    //
    switch (index)
    {
        case 0: if (CopyBuffer(handle,0,shift,1,buf)>0)
                    return (buf[0]); break;
        case 1: if (CopyBuffer(handle,1,shift,1,buf)>0)
                    return (buf[0]); break;
        case 2: if (CopyBuffer(handle,2,shift,1,buf)>0)
                    return (buf[0]); break;
        case 3: if (CopyBuffer(handle,3,shift,1,buf)>0)
                    return (buf[0]); break;
        case 4: if (CopyBuffer(handle,4,shift,1,buf)>0)
                    return (buf[0]); break;
        default: break;
    }
    //
    return (EMPTY_VALUE);
}
// 指定产品与周期的总K线个数
int BarsMQL4(void) export
{
    return (Bars(_Symbol, _Period));
}
// 返回按类型选择的各种数据
double MarketInfoMQL4(string symbol, int type) export
{
    switch(type)
    {
        case MODE_LOW:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_LASTLOW));
        case MODE_HIGH:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_LASTHIGH));
        case MODE_TIME:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_TIME));
        case MODE_BID:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_BID));
        case MODE_ASK:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_ASK));
        case MODE_POINT:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_POINT));
        case MODE_DIGITS:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_DIGITS));
        case MODE_SPREAD:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_SPREAD));
        case MODE_STOPLEVEL:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL));
        case MODE_LOTSIZE:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_TRADE_CONTRACT_SIZE));
        case MODE_TICKVALUE:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE));
        case MODE_TICKSIZE:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE));
        case MODE_SWAPLONG:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_SWAP_LONG));
        case MODE_SWAPSHORT:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_SWAP_SHORT));
        case MODE_STARTING:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_START_TIME));
        case MODE_EXPIRATION:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_EXPIRATION_TIME));
        case MODE_TRADEALLOWED:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_TRADE_MODE) != SYMBOL_TRADE_MODE_DISABLED);
        case MODE_MINLOT:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_VOLUME_MIN));
        case MODE_LOTSTEP:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_VOLUME_STEP));
        case MODE_MAXLOT:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_VOLUME_MAX));
        case MODE_SWAPTYPE:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_SWAP_MODE));
        case MODE_PROFITCALCMODE:
        case MODE_MARGINCALCMODE:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_TRADE_CALC_MODE));
        case MODE_MARGINREQUIRED:
        case MODE_MARGININIT: 
            return (double)(SymbolInfoDouble(symbol, SYMBOL_MARGIN_INITIAL));
        case MODE_MARGINMAINTENANCE:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_MARGIN_MAINTENANCE));
        case MODE_MARGINHEDGED:
            return (double)(SymbolInfoDouble(symbol, SYMBOL_MARGIN_HEDGED));
        case MODE_FREEZELEVEL:
            return (double)(SymbolInfoInteger(symbol, SYMBOL_TRADE_FREEZE_LEVEL));

        default: return(0);
    }
    return(0);
}
// iAD 计算累积分布指标并返回其值
double iADMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = (int)iAD(symbol, timeframe, VOLUME_TICK);
    if (handle < 0)
    {
        Print( "此 iAD 对象不能创建: 错误", GetLastError() );
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle, 0, shift));
}
// iADX 计算趋向指标并返回其值
double iADXMQL4(string symbol, int tf, int period, int price, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iADX(symbol, timeframe, period);
    if (handle < 0)
    {
        Print("The iADX object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, mode, shift) );
}
// iAlligator 计算 Bill Williams 的鳄鱼指标并返回其值
double iAlligatorMQL4(string symbol, int tf, int jaw_period, int jaw_shift,
        int teeth_period, int teeth_shift, int lips_period, int lips_shift,
        int method, int price, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_MA_METHOD ma_method = MethodMigrate(method);
    ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
    int handle = iAlligator(symbol, timeframe, jaw_period, jaw_shift,
            teeth_period, teeth_shift, lips_period, lips_shift,
            ma_method, applied_price);
    if (handle < 0)
    {
        Print("The iAlligator object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, mode-1, shift) );
}
//
double iAOMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iAO(symbol, timeframe);
    if (handle < 0)
    {
        Print("The iAO object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
// iBearsPower 计算熊市力量动量指标并返回其值
double iBearsPowerMQL4(string symbol, int tf, int period, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iBearsPower(symbol, timeframe, period);
    if (handle < 0)
    {
        Print("The iBearsPower object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, 0, shift) );
}
// iBullsPower 计算牛市力量动量指标并返回其值
double iBullsPowerMQL4(string symbol, int tf, int period, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iBullsPower(symbol, timeframe, period);
    if (handle < 0)
    {
        Print("The iBullsPower object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, 0, shift) );
}
// iBWMFI 计算 Bill Williams 市场促进指数并返回其值
double iBWMFIMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle=(int)iBWMFI(symbol,timeframe,VOLUME_TICK);
    if (handle < 0)
    {
        Print("The iBWMFI object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
// iATR 计算平均真实波动范围指标并返回其值
double iATRMQL4(string symbol, int tf, int period, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iATR(symbol, timeframe, period);
    if (handle < 0)
    {
        Print("The iATR object is not created: Error",GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
// iBands 计算布林带指标并返回其值
double iBandsMQL4(string symbol, int tf, int period, double deviation, int bands_shift, int method, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_MA_METHOD ma_method = MethodMigrate(method);
    int handle = iBands(symbol,timeframe,period,
            bands_shift,deviation,ma_method);
    if (handle < 0)
    {
        Print("The iBands object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,mode,shift));
}
//+------------------------------------------------------------------
//| iBars 返回指定图表中柱的数量                                    |
//+------------------------------------------------------------------
int iBarsMQL4(string symbol, int tf) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    return (Bars(symbol, timeframe));
}
//+------------------------------------------------------------------
//| iBarShift 按建立时间搜索柱                                      |
//+------------------------------------------------------------------
int iBarShiftMQL4(string symbol, int tf, datetime time, bool exact=false) export
{
    if (time < 0) return (-1);
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    datetime arr[], time1;
    CopyTime(symbol, timeframe, 0, 1,arr);
    time1 = arr[0];
    if (CopyTime(symbol,timeframe,time,time1,arr) > 0)
    {
        if (ArraySize(arr) > 2) return (ArraySize(arr)-1);
        if (time < time1) 
            return (1);
        else
            return(0);
    }
    else 
        return(-1);
}
//+------------------------------------------------------------------
//| iCCI 计算顺市指标并返回其值                                     |
//+------------------------------------------------------------------
double iCCIMQL4(string symbol, int tf, int period, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_APPLIED_PRICE applied_price = PriceMigrate(price);
    int handle = iCCI(symbol, timeframe, period, price);
    if (handle < 0)
    {
        Print("The iCCI object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, 0, shift) );
}
//+------------------------------------------------------------------
//|返回相应图表(交易对象、时间周期)由偏移参数确定的                |                  
//|柱形的成交量时间。                                                |
//|如果出错返回0。                                                   |
//+------------------------------------------------------------------
//Close 返回具有指定时间框架和偏移的指定交易品种的柱的收盘价。如果本地历史记录是空的(未加载),则函数返回 0。
// High 返回具有指定时间框架和偏移的指定交易品种的柱的最高价。如果本地历史记录是空的(未加载),则函数返回 0。
//iLow 返回具有指定时间框架和偏移的指定交易品种的柱的最低价。如果本地历史记录是空的(未加载),则函数返回 0。
double iCloseMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    double array[1];
    int copied = CopyClose(symbol, timeframe, shift, 1, array);
    if (copied != 1) return (0);
    return (array[0]);
}
//+------------------------------------------------------------------
//| 计算 DeMarker 指标并返回其值                                    |
//+------------------------------------------------------------------
double iDeMarkerMQL4(string symbol, int tf, int period, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iDeMarker(symbol,timeframe,period);
    if (handle < 0)
    {
        Print("The iDeMarker object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle,0,shift) );
}
//+------------------------------------------------------------------
//| iEnvelopes 计算包络线指标并返回其值                            |
//+------------------------------------------------------------------
double iEnvelopesMQL4(string symbol, int tf, int ma_period, int method, int ma_shift, int price, double deviation, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_MA_METHOD ma_method = MethodMigrate(method);
    ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
    int handle = iEnvelopes(symbol,timeframe,
            ma_period,ma_shift,ma_method,
            applied_price,deviation);
    if (handle < 0)
    {
        Print("The iEnvelopes object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,mode-1,shift));
}
//+------------------------------------------------------------------
//| iForce 计算强力指数并返回其值                                   |
//+------------------------------------------------------------------
double iForceMQL4(string symbol, int tf, int period, int method, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_MA_METHOD ma_method = MethodMigrate(method);
    int handle = iForce(symbol,timeframe,period,ma_method,VOLUME_TICK);
    if (handle < 0)
    {
        Print("The iForce object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
//+------------------------------------------------------------------
//| iFractals 计算分形指标并返回其值                                |
//+------------------------------------------------------------------
double iFractalsMQL4(string symbol, int tf, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iFractals(symbol,timeframe);
    if (handle < 0)
    {
        Print("The iFractals object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,mode-1,shift));
}
//+------------------------------------------------------------------
//| iGator 计算鳄鱼振荡指标                                         |
//+------------------------------------------------------------------
double iGatorMQL4(string symbol, int tf, int jaw_period, int jaw_shift, int teeth_period, int teeth_shift, int lips_period, int lips_shift, int method, int price, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_MA_METHOD ma_method = MethodMigrate(method);
    ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
    int handle = iGator(symbol,timeframe,jaw_period,jaw_shift,
            teeth_period,teeth_shift,
            lips_period,lips_shift,
            ma_method,applied_price);
    if (handle < 0)
    {
        Print("The iGator object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,mode-1,shift));
}
//+------------------------------------------------------------------
//|返回相应图表(交易对象、时间周期)由偏移参数确定的                | 
//|柱形的成交量时间。                                                |
//|如果出错返回0。                                                   | 
//+------------------------------------------------------------------
double iHighMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    double array[1];
    int copied = CopyHigh(symbol, timeframe, shift, 1, array);
    if (copied != 1) return (0);
    return (array[0]);
}
//+-------------------------------------------------------+
//|iHighest 视类型而定,返回指定的若干周期内最高价的偏移  |    
//+-------------------------------------------------------+
int iHighestMQL4(string symbol, int tf, int type, int count=WHOLE_ARRAY, int start=0) export
{
    if (start < 0) return (-1);
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    if (count<=0) count = Bars(symbol,timeframe);
    if (type<=MODE_OPEN)
    {
        double open[];
        ArraySetAsSeries(open, true);
        CopyOpen(symbol, timeframe, start, count, open);
        return (ArrayMaximum(open,0,count) + start);
    }
    if (type==MODE_LOW)
    {
        double low[];
        ArraySetAsSeries(low, true);
        CopyLow(symbol, timeframe, start, count, low);
        return (ArrayMaximum(low,0,count) + start);
    }
    if (type==MODE_HIGH)
    {
        double high[];
        ArraySetAsSeries(high, true);
        CopyHigh(symbol, timeframe, start, count, high);
        return (ArrayMaximum(high,0,count) + start);
    }
    if (type==MODE_CLOSE)
    {
        double close[];
        ArraySetAsSeries(close, true);
        CopyClose(symbol, timeframe, start, count, close);
        return (ArrayMaximum(close,0,count) + start);
    }
    if (type==MODE_VOLUME)
    {
        long volume[];
        ArraySetAsSeries(volume, true);
        CopyTickVolume(symbol, timeframe, start, count, volume);
        return (ArrayMaximum(volume,0,count) + start);
    }
    if (type>=MODE_TIME)
    {
        datetime time[];
        ArraySetAsSeries(time, true);
        CopyTime(symbol, timeframe, start, count, time);
        return (ArrayMaximum(time,0,count) + start);
    }
    //
    return (-1);
}
//+------------------------------------------------------------------
//|返回相应图表(交易对象、时间周期)由偏移参数确定的               |
//|柱形的成交量时间。                                               |
//|如果出错返回0。                                                  |
//+------------------------------------------------------------------
double iLowMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    double array[1];
    int copied = CopyLow(symbol,timeframe,shift,1,array);
    if (copied!=1) return (0);
    return (array[0]);
}
//+------------------------------------------------------------------
//| 返回相应图表(交易对象、时间周期)由偏移参数确定的               |
//|柱形的成交量时间。                                                | 
//|如果出错返回0。                                                   |
//+------------------------------------------------------------------
double iOpenMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    double array[1];
    int copied = CopyOpen(symbol, timeframe, shift, 1, array);
    if (copied != 1) return (0);
    return (array[0]);
}
//+------------------------------------------------------------------
//| iRSI 计算相对强弱指数并返回其值                                 |
//+------------------------------------------------------------------
double iRSIMQL4(string symbol, int tf, int period, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_APPLIED_PRICE applied_price = PriceMigrate(price);
    static int handle = INVALID_HANDLE;
    if (handle == INVALID_HANDLE)
    {
        handle = iRSI(symbol, timeframe, period, applied_price);
    }
    //
    if (handle < 0)
    {
        Print("The iRSI object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle,0,shift) );
}
//+------------------------------------------------------------------
//| iRVI 计算相对能量指数并返回其值                                 |
//+------------------------------------------------------------------
double iRVIMQL4(string symbol, int tf, int period, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iRVI(symbol, timeframe, period);
    if (handle < 0)
    {
        Print("The iRVI object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, mode, shift) );
}
//+------------------------------------------------------------------
//| iSAR 计算抛物线停止和反向系统指标并返回其值                     |
//+------------------------------------------------------------------
double iSARMQL4(string symbol, int tf, double step, double maximum, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iSAR(symbol, timeframe, step, maximum);
    if (handle < 0)
    {
        Print("The iSAR object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, 0, shift) );
}
//+------------------------------------------------------------------------+
//| iStdDev 计算标准方差指标并返回其值                                     |
//+------------------------------------------------------------------------+
double iStdDevMQL4(string symbol, int tf, int ma_period, int ma_shift, int method, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_MA_METHOD ma_method = MethodMigrate(method);
    ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
    int handle = iStdDev(symbol,timeframe,ma_period,ma_shift,
            ma_method,applied_price);
    if (handle < 0)
    {
        Print("The iStdDev object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
//+------------------------------------------------------------------
//|返回相应图表(交易对象、时间周期)由偏移参数确定的                |
//|柱形的成交量时间。                                                |
//|如果出错返回0。                                                   |                       
//+------------------------------------------------------------------
datetime iTimeMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    datetime array[1];
    int copied = CopyTime(symbol, timeframe, shift, 1, array);
    if (copied != 1) return (0);
    return (array[0]);
}
//+------------------------------------------------------------------
//|返回发现最小值的数组的索引                                       |
//|(相对于当前柱形的偏移)。                                       |
//+------------------------------------------------------------------
int iLowestMQL4(string symbol, int tf, int type, int count=WHOLE_ARRAY, int start=0) export
{
    if(start<0) return(-1);
    ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
    if(count<=0) count=Bars(symbol,timeframe);
    if(type<=MODE_OPEN)
    {
        double open[];
        ArraySetAsSeries(open,true);
        CopyOpen(symbol,timeframe,start,count,open);
        return(ArrayMinimum(open,0,count)+start);
    }
    if(type==MODE_LOW)
    {
        double low[];
        ArraySetAsSeries(low,true);
        CopyLow(symbol,timeframe,start,count,low);
        return(ArrayMinimum(low,0,count)+start);
    }
    if(type==MODE_HIGH)
    {
        double high[];
        ArraySetAsSeries(high,true);
        CopyHigh(symbol,timeframe,start,count,high);
        return(ArrayMinimum(high,0,count)+start);
    }
    if(type==MODE_CLOSE)
    {
        double close[];
        ArraySetAsSeries(close,true);
        CopyClose(symbol,timeframe,start,count,close);
        return(ArrayMinimum(close,0,count)+start);
    }
    if(type==MODE_VOLUME)
    {
        long volume[];
        ArraySetAsSeries(volume,true);
        CopyTickVolume(symbol,timeframe,start,count,volume);
        return(ArrayMinimum(volume,0,count)+start);
    }
    if(type>=MODE_TIME)
    {
        datetime time[];
        ArraySetAsSeries(time,true);
        CopyTime(symbol,timeframe,start,count,time);
        return(ArrayMinimum(time,0,count)+start);
    }
    //---
    return(0);
}
//+------------------------------------------------------------------
//| 指数平均                                                        |
//+------------------------------------------------------------------
void EMA(double &array[], int InpMAPeriod) export
{
    int count=ArraySize(array)-1;
    double pr=2.0/(InpMAPeriod+1);
    count--;
    while (count >= 0)
    {
        array[count]=array[count]*pr+array[count+1]*(1-pr);
        count--;
    }
}
//+------------------------------------------------------------------
//|  简单平均                                                       |
//+------------------------------------------------------------------
void SimpleMA(double &price[], double &ExtLineBuffer[], int InpMAPeriod) export
{
    int rates_total=ArraySize(price);
    int i,ii;
    double Value;
    for (ii=0;ii<(rates_total-InpMAPeriod);ii++)
    {
        Value=0;
        for (i=0;i<InpMAPeriod;i++) Value+=price[ii+i];
        Value/=InpMAPeriod;
        ExtLineBuffer[ii]=Value;
    }
}
//+------------------------------------------------------------------
//| 平滑平均                                                        |
//+------------------------------------------------------------------
void SmoothedMA(double &price[], double &ExtLineBuffer[], int InpMAPeriod) export
{
    int rates_total=ArraySize(price)-1;
    int i,limit;
    limit=rates_total-InpMAPeriod;
    double firstValue=0;
    for (i=rates_total;i>limit;i--) firstValue+=price[i];
    firstValue/=InpMAPeriod;
    ExtLineBuffer[limit+1]=firstValue;
    for (i=limit;i>=0;i--) ExtLineBuffer[i]=(ExtLineBuffer[i+1]*(InpMAPeriod-1)+price[i])/InpMAPeriod;
}
//+------------------------------------------------------------------
//| 线形加权平均                                                    |
//+------------------------------------------------------------------
void LWMA(double &price[], double &ExtLineBuffer[], int InpMAPeriod) export
{
    int rates_total=ArraySize(price)-1;
    int  limit=rates_total-InpMAPeriod;
    int i,weightsum;
    weightsum=0;
    double sum;
    double firstValue=0;
    //
    for (i=limit;i<=rates_total;i++)
    {
        int k=i-limit;
        weightsum+=k;
        firstValue+=k*price[i];
    }
    firstValue/=weightsum;
    ExtLineBuffer[limit+1]=firstValue;
    //--- 主循环
    for (i=limit; i>=0; i--)
    {
        sum=0;
        for (int j=0;j<InpMAPeriod;j++)
            sum+=(InpMAPeriod-j)*price[i+j];
        ExtLineBuffer[i]=sum/weightsum;
    }
    //---
}
//+------------------------------------------------------------------------+
//| Ichimoku Kinko Hyo 指标并返回其值                                      |
//+------------------------------------------------------------------------+
double iIchimokuMQL4(string symbol, int tf, int tenkan_sen, int kijun_sen, int senkou_span_b, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iIchimoku(symbol,timeframe, tenkan_sen,kijun_sen,senkou_span_b);
    if (handle < 0)
    {
        Print("The iIchimoku object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,mode-1,shift));
}
//+------------------------------------------------------------------------+
//| 计算平滑异动移动平均线动量指标并返回其值。                             |
//+------------------------------------------------------------------------+
double iMACDMQL4(string symbol, int tf, int fast_ema_period, int slow_ema_period, int signal_period, int price, int mode, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
    int handle = iMACD(symbol,timeframe, fast_ema_period,slow_ema_period, signal_period,applied_price);
    if (handle < 0)
    {
        Print("The iMACD object is not created: Error ", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle, mode, shift));
}
//+------------------------------------------------------------------------+
//| iMFI 计算资金流向指标并返回其值                                        |
//+------------------------------------------------------------------------+
double iMFIMQL4(string symbol, int tf, int period, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle=(int)iMFI(symbol,timeframe,period,VOLUME_TICK);
    if (handle < 0)
    {
        Print("The iMFI object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
//+------------------------------------------------------------------------+
//| iMomentum 计算动量指标并返回其值                                       |
//+------------------------------------------------------------------------+
double iMomentumMQL4(string symbol, int tf, int period, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
    int handle = iMomentum(symbol,timeframe,period,applied_price);
    if (handle < 0)
    {
        Print("The iMomentum object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
//+------------------------------------------------------------------------+
//| iOBV 计算平衡交易量指标并返回其值                                      |
//+------------------------------------------------------------------------+
double iOBVMQL4(string symbol, int tf, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iOBV(symbol,timeframe,VOLUME_TICK);
    if (handle < 0)
    {
        Print("The iOBV object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
//+------------------------------------------------------------------------+
//| iOsMA 计算移动平均线动量指标并返回其值                                 |
//+------------------------------------------------------------------------+
double iOsMAMQL4(string symbol, int tf, int fast_ema_period, int slow_ema_period, int signal_period, int price, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    ENUM_APPLIED_PRICE applied_price=PriceMigrate(price);
    int handle = iOsMA(symbol,timeframe,
            fast_ema_period,slow_ema_period,
            signal_period,applied_price);
    if (handle < 0)
    {
        Print("The iOsMA object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return (CopyBufferMQL4(handle,0,shift));
}
//+------------------------------------------------------------------
//|返回相应图表(交易对象、时间周期)由偏移参数确定的               |
//|柱形的成交量时间。                                               |
//|如果出错返回0。                                                  |
//+------------------------------------------------------------------
long iVolumeMQL4(string symbol, int tf, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    long array[1];
    int copied = CopyTickVolume(symbol, timeframe, shift, 1, array);
    if (copied != 1) return (0);
    return (array[0]);
}
//+------------------------------------------------------------------------+
//| iWPR 计算 Larry William 百分比范围指标并返回其值                       |
//+------------------------------------------------------------------------+
double iWPRMQL4(string symbol, int tf, int period, int shift) export
{
    ENUM_TIMEFRAMES timeframe = TFMigrate(tf);
    int handle = iWPR(symbol, timeframe, period);
    if (handle < 0)
    {
        Print("The iWPR object is not created: Error", GetLastError());
        return (-1);
    }
    else
        return ( CopyBufferMQL4(handle, 0, shift) );
}
//+------------------------------------------------------------------------+
//|                                                          |
//+------------------------------------------------------------------------+
double iBandsOnArrayMQL4(double &array[], int total, int period, int deviation, int bands_shift, int mode, int shift) export
{
    // Unimplemented stub
    Print("Error: iBandsOnArray() - Not implemented stub.");
    return (0);
}
//+------------------------------------------------------------------------+
//| 用存储在数字数组中的数据计算顺市指标                                   |
//+------------------------------------------------------------------------+
double iCCIOnArrayMQL4(double &array[], int total, int period, int shift) export
{
    // Unimplemented stub
    Print("Error: iCCIOnArray() - Not implemented stub.");
    return (0);
}
//+------------------------------------------------------------------------+
//|                                                          |
//+------------------------------------------------------------------------+
double iEnvelopesOnArrayMQL4(double &array[], int total, int ma_period, int ma_method, int ma_shift, double deviation, int mode, int shift) export
{
    // Unimplemented stub
    Print("Error: iEnvelopesOnArray() - Not implemented stub.");
    return (-1);
}
//+------------------------------------------------------------------+
//| Calculates the Relative Strength Index indicator on data
//| stored in array, and returns its value                                                      |
//+------------------------------------------------------------------+
double iRSIOnArrayMQL4(double &array[], int total, int period, int shift) export
{
    if (total == 0) total = ArraySize(array);
    int stop = total-shift;
    if (period<=1 || shift<0 || stop<=period) return (0);
    bool is_series = ArrayGetAsSeries(array);
    if(is_series)
        ArraySetAsSeries(array,false);
    int i;
    double SumP=0;
    double SumN=0;
    for (i=1; i<=period; i++)
    {
        double diff = array[i]-array[i-1];
        if (diff > 0)
            SumP += diff;
        else
            SumN += -diff;
    }
    if (!MathIsValidNumber(SumP) || !MathIsValidNumber(SumN))
    {
        return MathSqrt(-1);
    }
    double AvgP = SumP/period;
    double AvgN = SumN/period;
    for (; i<stop; i++)
    {
        double diff = array[i]-array[i-1];
        AvgP = (AvgP*(period-1)+(diff>0?diff:0))/period;
        AvgN = (AvgN*(period-1)+(diff<0?-diff:0))/period;
    }
    double rsi;
    if(AvgN==0.0)
    {
        rsi = (AvgP==0.0 ? 50.0 : 100.0);
    }
    else
    {
        rsi = 100.0-(100.0/(1.0+AvgP/AvgN));
    }
    if (is_series) ArraySetAsSeries(array, true);
    return (rsi);
}
//+------------------------------------------------------------------------+
//|  计算用于MQL4程序的一个数组的移动平均。                                |               
//+------------------------------------------------------------------------+
double iMAOnArrayMQL4(double &array[], int total, int period, int ma_shift, int ma_method, int shift) export
{
    double buf[],arr[];
    if(total==0) total=ArraySize(array);
    if(total>0 && total<=period) return(0);
    if(shift>total-period-ma_shift) return(0);
    switch(ma_method)
    {
        case MODE_SMA :
            {
                total=ArrayCopy(arr,array,0,shift+ma_shift,period);
                if(ArrayResize(buf,total)<0) return(0);
                double sum=0;
                int    i,pos=total-1;
                for(i=1;i<period;i++,pos--)
                    sum+=arr[pos];
                while(pos>=0)
                {
                    sum+=arr[pos];
                    buf[pos]=sum/period;
                    sum-=arr[pos+period-1];
                    pos--;
                }
                return(buf[0]);
            }
        case MODE_EMA :
            {
                if(ArrayResize(buf,total)<0) return(0);
                double pr=2.0/(period+1);
                int    pos=total-2;
                while(pos>=0)
                {
                    if(pos==total-2) buf[pos+1]=array[pos+1];
                    buf[pos]=array[pos]*pr+buf[pos+1]*(1-pr);
                    pos--;
                }
                return(buf[shift+ma_shift]);
            }
        case MODE_SMMA :
            {
                if(ArrayResize(buf,total)<0) return(0);
                double sum=0;
                int    i,k,pos;
                pos=total-period;
                while(pos>=0)
                {
                    if(pos==total-period)
                    {
                        for(i=0,k=pos;i<period;i++,k++)
                        {
                            sum+=array[k];
                            buf[k]=0;
                        }
                    }
                    else sum=buf[pos+1]*(period-1)+array[pos];
                    buf[pos]=sum/period;
                    pos--;
                }
                return(buf[shift+ma_shift]);
            }
        case MODE_LWMA :
            {
                if(ArrayResize(buf,total)<0) return(0);
                double sum=0.0,lsum=0.0;
                double price;
                int    i,weight=0,pos=total-1;
                for(i=1;i<=period;i++,pos--)
                {
                    price=array[pos];
                    sum+=price*i;
                    lsum+=price;
                    weight+=i;
                }
                pos++;
                i=pos+period;
                while(pos>=0)
                {
                    buf[pos]=sum/weight;
                    if(pos==0) break;
                    pos--;
                    i--;
                    price=array[pos];
                    sum=sum-lsum+price*period;
                    lsum-=array[i];
                    lsum+=price;
                }
                return(buf[shift+ma_shift]);
            }
        default: return(0);
    }
    return(0);
}
//+------------------------------------------------------------------------+
//|  计算用于MQL4程序的一个数组的移动平均。                                |               
//+------------------------------------------------------------------------+
double iMomentumOnArrayMQL4(double &array[], int total, int period, int shift) export
{
    // Unimplemented stub
    Print("Error: iMomentumOnArray() - Not implemented stub.");
    return -1;
}
//+------------------------------------------------------------------------+
//| iStdDevOnArray 用存储在数字数组中的数据计算标准方差指标                |               
//+------------------------------------------------------------------------+
double iStdDevOnArrayMQL4(double &array[], int total, int ma_period, int ma_shift, int ma_method, int shift) export
{
    // Unimplemented stub
    Print("Error: iStdDevOnArray() - Not implemented stub.");
    return (-1);
}
//+------------------------------------------------------------------------+
//| The function sets a flag hiding indicators called by the Expert Advisor|               
//+------------------------------------------------------------------------+
void HideTestIndicatorsMQL4(bool hide) export
{
    // Unimplemented stub
    Print("Error: HideTestIndicators() - Not implemented stub.");
}
// 指标缓冲区设置,在MT5中已取消
void IndicatorBuffersMQL4(int count) export
{
    Print("Error: IndicatorBuffers() - Not implemented stub.");
}
// 指标缓冲区统计,在MT5中已取消
int IndicatorCountedMQL4(void) export
{
    Print("Error: IndicatorCounted() - Not implemented stub.");
    return (0);
}
文章来源:https://blog.csdn.net/FXSuperLee/article/details/135682366
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。