📅 财经日历 📊 实时波动 📈 大盘云图 📶 行情走势 🆚 投机情绪 🚀 今日热点

    求:MT5均线交叉箭头指标源码,哪位大神有?

    2026-06-11 · 91 阅读
    求MT5均线交叉箭头指标源码,哪位大神有?

    我找到的不是源码,用DeepSeek编辑的不显示,所以想问问朋友们


    ""
    还没有人打赏,支持一下
    回复

    举报

     

    回答|共 2 个

    m1800 LV9

    发表于 2026-6-11 04:07:53 | 显示全部楼层

    1. #property link          "https://www.earnforex.com/metatrader-indicators/moving-average-crossover-alert/"
    2. #property version       "1.05"
    3. #property strict
    4. #property copyright     "EarnForex.com - 2020-2023"
    5. #property description   "Moving average crossover alert. Supports simple, exponential, smoothed, linear weighted, and TEMA."
    6. #property description   " "
    7. #property description   " "
    8. #property description   "Find More on www.EarnForex.com"
    9. //#property icon          "\\Files\\EF-Icon-64x64px.ico"

    10. #property indicator_chart_window
    11. #property indicator_buffers 2
    12. #property indicator_plots 2
    13. #property indicator_color1 clrDarkOrchid
    14. #property indicator_color2 clrLime
    15. #property indicator_type1 DRAW_LINE
    16. #property indicator_type2 DRAW_LINE
    17. //#property indicator_label1 "Fast MA"
    18. //#property indicator_label2 "Slow MA"

    19. //#include <MQLTA ErrorHandling.mqh>
    20. //#include <MQLTA Utils.mqh>

    21. enum ENUM_TRADE_SIGNAL
    22.   {
    23.    SIGNAL_BUY = 1,    // Buy
    24.    SIGNAL_SELL = -1,  // Sell
    25.    SIGNAL_NEUTRAL = 0 // Neutral
    26.   };

    27. enum ENUM_CANDLE_TO_CHECK
    28.   {
    29.    CURRENT_CANDLE = 0,  // Current candle
    30.    CLOSED_CANDLE = 1    // Previous candle
    31.   };

    32. enum ENUM_MA_METHOD_EXTENDED // Same as ENUM_MA_METHOD but with TEMA.
    33.   {
    34.    MODE_SMA_,   // Simple
    35.    MODE_EMA_,   // Exponential
    36.    MODE_SMMA_,  // Smoothed
    37.    MODE_LWMA_,  // Linear weighted
    38.    MODE_TEMA    // TEMA (Triple exponential moving average)
    39.   };

    40. input group "MQLTA Moving Average Crossover Alert"
    41. input string IndicatorName = "EMA";                 // Indicator short name

    42. input group "Indicator parameters"
    43. input int MAFastPeriod = 30;                               // Fast moving average period
    44. input int MAFastShift = 0;                                 // Fast moving average shift
    45. input ENUM_MA_METHOD_EXTENDED MAFastMethod = MODE_EMA_;    // Fast moving average method
    46. input ENUM_APPLIED_PRICE MAFastAppliedPrice = PRICE_CLOSE; // Fast moving average applied price
    47. input int MASlowPeriod = 50;                               // Slow moving average period
    48. input int MASlowShift = 0;                                 // Slow moving average shift
    49. input ENUM_MA_METHOD_EXTENDED MASlowMethod = MODE_EMA_;    // Slow moving average method
    50. input ENUM_APPLIED_PRICE MASlowAppliedPrice = PRICE_CLOSE; // Slow moving average applied price
    51. input ENUM_CANDLE_TO_CHECK CandleToCheck = CURRENT_CANDLE; // Candle to use for analysis
    52. input int BarsToScan = 5000;                                // Number of candles to analyze

    53. input group "Notification options"
    54. input bool EnableNotify = false;                           // Enable notifications feature
    55. input bool SendAlert = false;                              // Send alert notification
    56. input bool SendApp = false;                                // Send notification to mobile
    57. input bool SendEmail = false;                              // Send notification via email

    58. input group "Drawing options"
    59. input bool EnableDrawArrows = true;                        // Draw signal arrows
    60. input uchar ArrowBuy = 233;                                // Buy arrow code
    61. input uchar ArrowSell = 234;                               // Sell arrow code
    62. //input uchar ArrowBuy = 241;                                // Buy arrow code
    63. //input uchar ArrowSell = 242;                               // Sell arrow code
    64. input int ArrowSize = 1;                                   // Arrow size (1-5)
    65. input color ArrowBuyColor = clrGreen;                      // Buy arrow color
    66. input color ArrowSellColor = clrRed;                       // Sell arrow color

    67. #property indicator_label1 "Fast MA"
    68. #property indicator_label2 "Slow MA"//+ IntegerToString(MASlowPeriod,0)
    69. double BufferMASlow[];
    70. double BufferMAFast[];

    71. int BufferMASlowHandle, BufferMAFastHandle;

    72. double Open[], Close[], High[], Low[];
    73. datetime Time[];

    74. datetime LastNotificationTime;
    75. ENUM_TRADE_SIGNAL LastNotificationDirection;
    76. int Shift = 0;

    77. //+------------------------------------------------------------------+
    78. //|                                                                  |
    79. //+------------------------------------------------------------------+
    80. int OnInit(void)
    81.   {
    82.    IndicatorSetString(INDICATOR_SHORTNAME, IndicatorName);

    83.    OnInitInitialization();
    84.    if(!OnInitPreChecksPass())
    85.      {
    86.       return INIT_FAILED;
    87.      }

    88.    InitialiseHandles();
    89.    InitialiseBuffers();
    90. //SetIndexLabel(2,IndicatorName + IntegerToString(MASlowPeriod));
    91.    PlotIndexSetString(1,PLOT_LABEL,IndicatorName + " " + IntegerToString(MASlowPeriod));
    92.    PlotIndexSetString(0,PLOT_LABEL,IndicatorName + " " + IntegerToString(MAFastPeriod));
    93.    return INIT_SUCCEEDED;
    94.   }

    95. //+------------------------------------------------------------------+
    96. //|                                                                  |
    97. //+------------------------------------------------------------------+
    98. int OnCalculate(const int rates_total,
    99.                 const int prev_calculated,
    100.                 const datetime &time[],
    101.                 const double &open[],
    102.                 const double &high[],
    103.                 const double &low[],
    104.                 const double &close[],
    105.                 const long &tick_volume[],
    106.                 const long &volume[],
    107.                 const int &spread[])
    108.   {
    109.    if(rates_total < MASlowPeriod + MASlowShift)
    110.      {
    111.       Print("Not enough candles on the chart.");
    112.       return 0;
    113.      }

    114.    bool IsNewCandle = CheckIfNewCandle();

    115.    int counted_bars = 0;
    116.    if(prev_calculated > 0)
    117.       counted_bars = prev_calculated - 1;

    118.    if(counted_bars < 0)
    119.       return -1;
    120.    if(counted_bars > 0)
    121.       counted_bars--;
    122.    int limit = rates_total - counted_bars;
    123.    if(limit > BarsToScan)
    124.      {
    125.       limit = BarsToScan;
    126.       if(rates_total < BarsToScan + MASlowPeriod + MASlowShift)
    127.          limit = rates_total - (MASlowPeriod + MASlowShift);
    128.      }
    129.    if(limit > rates_total - (MASlowPeriod + MASlowShift))
    130.       limit = rates_total - (MASlowPeriod + MASlowShift);

    131.    if((CopyBuffer(BufferMAFastHandle,0, -MAFastShift, limit, BufferMAFast) <= 0) ||
    132.       (CopyBuffer(BufferMASlowHandle, 0, -MASlowShift, limit, BufferMASlow) <= 0))
    133.      {
    134.      // Print("Failed to create the indicator! Error: ", GetLastErrorText(GetLastError()), " - ", GetLastError());
    135.       return 0;
    136.      }

    137.    if(IsStopped())
    138.       return 0;


    139.    for(int i = limit - 1; (i >= 0) && (!IsStopped()); i--)
    140.      {
    141.       Open[i] = iOpen(Symbol(), PERIOD_CURRENT, i);
    142.       Low[i] = iLow(Symbol(), PERIOD_CURRENT, i);
    143.       High[i] = iHigh(Symbol(), PERIOD_CURRENT, i);
    144.       Close[i] = iClose(Symbol(), PERIOD_CURRENT, i);
    145.       Time[i] = iTime(Symbol(), PERIOD_CURRENT, i);
    146.      }

    147.    if((IsNewCandle) || (prev_calculated == 0))
    148.      {
    149.       if(EnableDrawArrows)
    150.          DrawArrows(limit);
    151.      }

    152.    if(EnableDrawArrows)
    153.       DrawArrow(0);

    154.    if(EnableNotify)
    155.       NotifyHit();

    156.    return rates_total;
    157.   }

    158. //+------------------------------------------------------------------+
    159. //|                                                                  |
    160. //+------------------------------------------------------------------+
    161. void OnDeinit(const int reason)
    162.   {
    163.    CleanChart();
    164.   }

    165. //+------------------------------------------------------------------+
    166. //|                                                                  |
    167. //+------------------------------------------------------------------+
    168. void OnInitInitialization()
    169.   {
    170.    LastNotificationTime = TimeCurrent();
    171.    LastNotificationDirection = SIGNAL_NEUTRAL;
    172.    Shift = CandleToCheck;
    173.   }

    174. //+------------------------------------------------------------------+
    175. //|                                                                  |
    176. //+------------------------------------------------------------------+
    177. bool OnInitPreChecksPass()
    178.   {
    179.    if((MASlowPeriod <= 0) || (MAFastPeriod <= 0) || (MAFastPeriod > MASlowPeriod))
    180.      {
    181.       Print("Wrong input parameter");
    182.       return false;
    183.      }
    184.    return true;
    185.   }

    186. //+------------------------------------------------------------------+
    187. //|                                                                  |
    188. //+------------------------------------------------------------------+
    189. void CleanChart()
    190.   {
    191.    ObjectsDeleteAll(ChartID(), IndicatorName);
    192.   }

    193. //+------------------------------------------------------------------+
    194. //|                                                                  |
    195. //+------------------------------------------------------------------+
    196. void InitialiseHandles()
    197.   {
    198.    if(MAFastMethod == MODE_TEMA)
    199.      {
    200.       BufferMAFastHandle = iTEMA(Symbol(), PERIOD_CURRENT, MAFastPeriod, MAFastShift, MAFastAppliedPrice);
    201.      }
    202.    else
    203.      {
    204.       BufferMAFastHandle = iMA(Symbol(), PERIOD_CURRENT, MAFastPeriod, MAFastShift, ENUM_MA_METHOD(MAFastMethod), MAFastAppliedPrice);
    205.      }
    206.    if(MASlowMethod == MODE_TEMA)
    207.      {
    208.       BufferMASlowHandle = iTEMA(Symbol(), PERIOD_CURRENT, MASlowPeriod, MASlowShift, MASlowAppliedPrice);
    209.      }
    210.    else
    211.      {
    212.       BufferMASlowHandle = iMA(Symbol(), PERIOD_CURRENT, MASlowPeriod, MASlowShift, ENUM_MA_METHOD(MASlowMethod), MASlowAppliedPrice);
    213.      }
    214.    ArrayResize(Open, BarsToScan);
    215.    ArrayResize(High, BarsToScan);
    216.    ArrayResize(Low, BarsToScan);
    217.    ArrayResize(Close, BarsToScan);
    218.    ArrayResize(Time, BarsToScan);
    219.   }

    220. //+------------------------------------------------------------------+
    221. //|                                                                  |
    222. //+------------------------------------------------------------------+
    223. void InitialiseBuffers()
    224.   {
    225.    ArraySetAsSeries(BufferMAFast, true);
    226.    ArraySetAsSeries(BufferMASlow, true);
    227.    SetIndexBuffer(0, BufferMAFast, INDICATOR_DATA);
    228.    SetIndexBuffer(1, BufferMASlow, INDICATOR_DATA);
    229.    PlotIndexSetInteger(0, PLOT_SHIFT, MAFastShift);
    230.    PlotIndexSetInteger(1, PLOT_SHIFT, MASlowShift);
    231.   }

    232. //+------------------------------------------------------------------+
    233. //|                                                                  |
    234. //+------------------------------------------------------------------+
    235. datetime NewCandleTime = TimeCurrent();
    236. bool CheckIfNewCandle()
    237.   {
    238.    if(NewCandleTime == iTime(Symbol(), 0, 0))
    239.       return false;
    240.    else
    241.      {
    242.       NewCandleTime = iTime(Symbol(), 0, 0);
    243.       return true;
    244.      }
    245.   }

    246. // Check if it is a trade Signla 0 - Neutral, 1 - Buy, -1 - Sell
    247. ENUM_TRADE_SIGNAL IsSignal(int i)
    248.   {
    249.    int j = i + Shift;

    250. // Prevent array out of range error (negative index) for when the MA shift is negative.
    251.    if((j + MAFastShift < 0) || (j + MASlowShift < 0))
    252.       return SIGNAL_NEUTRAL;
    253. // Prevent array out of range error when not enough bars.
    254.    if(j + 1 + MASlowShift >= iBars(Symbol(), Period()))
    255.       return SIGNAL_NEUTRAL;

    256.    if((BufferMAFast[j + 1 + MAFastShift] < BufferMASlow[j + 1 + MASlowShift]) && (BufferMAFast[j + MAFastShift] > BufferMASlow[j + MASlowShift]))
    257.       return SIGNAL_BUY;
    258.    if((BufferMAFast[j + 1 + MAFastShift] > BufferMASlow[j + 1 + MASlowShift]) && (BufferMAFast[j + MAFastShift] < BufferMASlow[j + MASlowShift]))
    259.       return SIGNAL_SELL;

    260.    return SIGNAL_NEUTRAL;
    261.   }

    262. //+------------------------------------------------------------------+
    263. //|                                                                  |
    264. //+------------------------------------------------------------------+
    265. void NotifyHit()
    266.   {
    267.   /*
    268.    if(!EnableNotify)
    269.       return;
    270.    if((!SendAlert) && (!SendApp) && (!SendEmail))
    271.       return;
    272.    if((CandleToCheck == CLOSED_CANDLE) && (Time[0] <= LastNotificationTime))
    273.       return;
    274.    ENUM_TRADE_SIGNAL Signal = IsSignal(0);
    275.    if(Signal == SIGNAL_NEUTRAL)
    276.      {
    277.       LastNotificationDirection = Signal;
    278.       return;
    279.      }
    280.    if(Signal == LastNotificationDirection)
    281.       return;
    282.    string EmailSubject = IndicatorName + " " + Symbol() + " Notification ";
    283.    //string EmailBody =      AccountCompany() + " - " + AccountName() + " - " + IntegerToString(AccountNumber()) + "\r\n\r\n" + IndicatorName + " Notification for " + Symbol() + " [url=home.php?mod=space&uid=73392]@[/url] " + EnumToString(Period()) + "\r\n\r\n";
    284.    string AlertText = "";
    285.    //string AppText = AccountCompany() + " - " + AccountName() + " - " + IntegerToString(AccountNumber()) + " - " + IndicatorName + " - " + Symbol() + " @ " + EnumToString(Period()) + " - ";
    286.    string Text = "";

    287.    Text += "Slow and Fast Moving Average Crossed - " + ((Signal == SIGNAL_SELL) ? "Sell" : "Buy");

    288.    EmailBody += Text;
    289.    AlertText += Text;
    290.    AppText += Text;
    291.    if(SendAlert)
    292.       Alert(AlertText);
    293.    if(SendEmail)
    294.      {
    295.       if(!SendMail(EmailSubject, EmailBody))
    296.          Print("Error sending email " + IntegerToString(GetLastError()));
    297.      }
    298.    if(SendApp)
    299.      {
    300.       if(!SendNotification(AppText))
    301.          Print("Error sending notification " + IntegerToString(GetLastError()));
    302.      }
    303.    LastNotificationTime = Time[0];
    304.    LastNotificationDirection = Signal;
    305.    */
    306.   }

    307. //+------------------------------------------------------------------+
    308. //|                                                                  |
    309. //+------------------------------------------------------------------+
    310. void DrawArrows(int limit)
    311.   {
    312.    for(int i = limit - 1; i >= 1; i--)
    313.      {
    314.       DrawArrow(i);
    315.      }
    316.   }

    317. //+------------------------------------------------------------------+
    318. //|                                                                  |
    319. //+------------------------------------------------------------------+
    320. void RemoveArrows()
    321.   {
    322.    ObjectsDeleteAll(ChartID(), IndicatorName + "-ARWS-");
    323.   }

    324. //+------------------------------------------------------------------+
    325. //|                                                                  |
    326. //+------------------------------------------------------------------+
    327. void DrawArrow(int i)
    328.   {
    329.    RemoveArrowCurr();
    330.    ENUM_TRADE_SIGNAL Signal = IsSignal(i);
    331.    if(Signal == SIGNAL_NEUTRAL)
    332.       return;
    333.    datetime ArrowDate = iTime(Symbol(), 0, i);
    334.    string ArrowName = IndicatorName + "-ARWS-" + IntegerToString(ArrowDate);
    335.    double ArrowPrice = 0;
    336.    uchar ArrowType = 0;
    337.    color ArrowColor = 0;
    338.    int ArrowAnchor = 0;
    339.    string ArrowDesc = "";
    340.    if(Signal == SIGNAL_BUY)
    341.      {
    342.       //  ArrowPrice = Low[i];
    343.       ArrowPrice = BufferMASlow[i];
    344.       ArrowType = ArrowBuy;
    345.       ArrowColor = ArrowBuyColor;
    346.       ArrowAnchor = ANCHOR_TOP;
    347.       ArrowDesc = "BUY";
    348.      }
    349.    if(Signal == SIGNAL_SELL)
    350.      {
    351.       // ArrowPrice = High[i];
    352.       ArrowPrice = BufferMAFast[i];
    353.       ArrowType = ArrowSell;
    354.       ArrowColor = ArrowSellColor;
    355.       ArrowAnchor = ANCHOR_BOTTOM;
    356.       ArrowDesc = "SELL";
    357.      }
    358.    ObjectCreate(0, ArrowName, OBJ_ARROW, 0, ArrowDate, ArrowPrice);
    359.    ObjectSetInteger(0, ArrowName, OBJPROP_COLOR, ArrowColor);
    360.    ObjectSetInteger(0, ArrowName, OBJPROP_SELECTABLE, false);
    361.    ObjectSetInteger(0, ArrowName, OBJPROP_HIDDEN, true);
    362.    ObjectSetInteger(0, ArrowName, OBJPROP_ANCHOR, ArrowAnchor);
    363.    ObjectSetInteger(0, ArrowName, OBJPROP_ARROWCODE, ArrowType);
    364.    ObjectSetInteger(0, ArrowName, OBJPROP_WIDTH, ArrowSize);
    365.    ObjectSetInteger(0, ArrowName, OBJPROP_STYLE, STYLE_SOLID);
    366.    ObjectSetInteger(0, ArrowName, OBJPROP_BGCOLOR, ArrowColor);
    367.    ObjectSetString(0, ArrowName, OBJPROP_TEXT, ArrowDesc);
    368.   }

    369. //+------------------------------------------------------------------+
    370. //|                                                                  |
    371. //+------------------------------------------------------------------+
    372. void RemoveArrowCurr()
    373.   {
    374.    datetime ArrowDate = iTime(Symbol(), 0, 0);
    375.    string ArrowName = IndicatorName + "-ARWS-" + IntegerToString(ArrowDate);
    376.    ObjectDelete(0, ArrowName);
    377.   }
    378. //+------------------------------------------------------------------+
    379. //+------------------------------------------------------------------+
    复制代码


    日出东方888 LV3

    发表于 2026-6-11 08:39:36 | 显示全部楼层


    非常感谢!
    祝你交易大赚,共发大财!
    您需要登录后才可以回帖 登录 | 注册

    提醒: 禁止引战、谩骂、灌水内容

    微信二维码

    有问题联系客服