01_MT4 实现一个双均线指标

//+------------------------------------------------------------------+
//|                                                       双均线.mq4 |
//|                                          Copyright 2023, 100w123 |
//|                                              https://100w123.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, 100w123"
#property link      "https://100w123.com"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_color1 clrWhite
#property indicator_color2 clrYellow

input int fastMA_Period = 5;
input int slowMA_Period = 10;

double fastMA[];
double slowMA[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit() {    

    SetIndexBuffer(0, fastMA);
    SetIndexBuffer(1, slowMA);
    //---
    SetIndexStyle(0, DRAW_LINE);
    SetIndexStyle(1, DRAW_LINE);
    //--
    SetIndexLabel(0, "Fast MA");
    SetIndexLabel(1, "Slow MA");
    //--
    SetIndexDrawBegin(0, fastMA_Period);
    SetIndexDrawBegin(1, slowMA_Period);

    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {

    int limit;

    // 第一次回调计算所有 K 线
    if (prev_calculated == 0)
        limit = rates_total - 1;
    else
        limit = rates_total - prev_calculated;      // 后续回调,limit = 0 计算最后一根不断更新的 K 线,当新 K 线形成时, limit = 1,需要计算上一根的最终收盘后的价格和最新形成的一根    

    // 最后最新一根索引是 0,从前往后算
    for (int i = limit; i >= 0; i--) {
        fastMA[i] = iMA(NULL, 0, fastMA_Period, 0, MODE_SMA, PRICE_CLOSE, i);
        slowMA[i] = iMA(NULL, 0, slowMA_Period, 0, MODE_SMA, PRICE_CLOSE, i);
    }

    return(rates_total);
}
//+------------------------------------------------------------------+
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇