您現在的位置:程序化交易>> 外匯現貨>> MT4>> MT4知識>>正文內容

MT編程入門教程(0)----指標文件構成 [MT4]

  • //例1
    //+------------------------------------------------------------------+
    //雙些線后是單行注釋,用于注解,自用說明。/*和*/包起來實現多行注釋,記錄自己的說明介紹,編程使用記錄等
    //MQL4語言基本服從C語言的規則-----------注意目前MetaEditor處理不好多字節代碼,所以不要在代碼中使用中文和中文空格-------------+
    //每個指標文件只是至少包括三個部分(1)property 和參數,數組聲明,(2)初始化函數nit(), (3)主函數start()
    //property 是各種說明信息
    //最重要必須的是這三種,(1)說明指標將畫在價格窗口還是獨立的窗口
    //(2)有多少個(1~7)儲存指標數據的數組,(3)說明對應將畫指標的繪畫顏色,編號1~7
    #property indicator_chart_window
    #property indicator_buffers 1
    #property indicator_color1 Red

    //---- 可設置的參數,可根據需要,由使用者設置
    extern int MA_Period=13;
    extern int MA_Shift=0;
    extern int MA_Method=2;
    extern int MA_Price = 6;
    /* MA_Method =
    MODE_SMA 0 Simple moving average,
    MODE_EMA 1 Exponential moving average,
    MODE_SMMA 2 Smoothed moving average,
    MODE_LWMA 3 Linear weighted moving average.
    */
    /* MA_Price =
    PRICE_CLOSE 0 Close price.
    PRICE_OPEN 1 Open price.
    PRICE_HIGH 2 High price.
    PRICE_LOW 3 Low price.
    PRICE_MEDIAN 4 Median price, (high+low)/2.
    PRICE_TYPICAL 5 Typical price, (high+low+close)/3.
    PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4.

    */

    //數組,儲存指標數據
    double Buffer0[];
    //----
    //+------------------------------------------------------------------+
    //| 初始化準備函數,裝入時調用一次 |
    //+------------------------------------------------------------------+
    int init()
    {
    //-設置編號為0的線的線形等參數, 0~6,對應indicator_color1~7
    SetIndexStyle(0,DRAW_LINE);
    //---- 設置編號為0的線 與數組的對應關系, 0~6
    SetIndexBuffer(0,Buffer0);
    return(0);
    }
    //+------------------------------------------------------------------+
    //| |
    int start() //指標計算主函數,每次計算調用
    {
    ma();
    return(0);
    }
    //+------------------------------------------------------------------+
    //|自定義函數,這里只是直接使用庫函數實現MA, 若你自己計算,可設計任何指標 |
    //+------------------------------------------------------------------+
    void ma()
    {
    int pos=Bars; //Bars = Number of bars in the current chart.當前窗口中的蠟燭數
    while(pos>=0)
    {
    Buffer0[pos]=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,MA_Price,pos);
    pos--;
    }
    }
    //
    ///----------------------------------------------------------------------


    [Copy to clipboard]


    例2

    CODE:

    //+------------------------------------------------------------------+
    //雙些線后是單行注釋,用于注解,自用說明。/*和*/包起來實現多行注釋,記錄自己的說明介紹,編程使用記錄等
    //MQL4語言基本服從C語言的規則-----------注意目前MetaEditor處理不好多字節代碼,所以不要在代碼中使用中文和中文空格-------------+
    //每個指標文件只是至少包括三個部分(1)property 和參數,數組聲明,(2)初始化函數nit(), (3)主函數start()
    //property 是各種說明信息
    //最重要必須的是這三種,(1)說明指標將畫在價格窗口還是獨立的窗口
    //(2)有多少個(1~7)儲存指標數據的數組,(3)說明對應將畫指標的繪畫顏色,編號1~7
    #property indicator_separate_window
    #property indicator_buffers 7
    #property indicator_color1 Red
    #property indicator_color2 Yellow
    #property indicator_color3 Blue
    #property indicator_color4 Green
    #property indicator_color5 Gray
    #property indicator_color6 SkyBlue
    #property indicator_color7 Tan
    //---- 可設置的參數,可根據需要,由使用者設置
    extern int MA_Period=13;
    extern int MA_Shift=0;
    extern int MA_Method=2;
    extern int MA_Price = 6;

    //數組,儲存指標數據
    double Buffer0[];
    double Buffer1[];
    double Buffer2[];
    double Buffer3[];
    double Buffer4[];
    double Buffer5[];
    double Buffer6[];
    //----
    //+------------------------------------------------------------------+
    //| 初始化準備函數,裝入時調用一次 |
    //+------------------------------------------------------------------+
    int init()
    {
    //-設置編號為0的線的線形等參數, 0~6,對應indicator_color1~7
    SetIndexStyle(0,DRAW_LINE);
    SetIndexStyle(1,DRAW_LINE);
    SetIndexStyle(3,DRAW_LINE);
    SetIndexStyle(4,DRAW_LINE);
    SetIndexStyle(5,DRAW_LINE);
    SetIndexStyle(6,DRAW_LINE);
    //---- 設置編號為0的線 與數組的對應關系, 0~6
    SetIndexBuffer(0,Buffer0);
    SetIndexBuffer(1,Buffer1);
    SetIndexBuffer(2,Buffer2);
    SetIndexBuffer(3,Buffer3);
    SetIndexBuffer(4,Buffer4);
    SetIndexBuffer(5,Buffer5);
    SetIndexBuffer(6,Buffer6);
    return(0);
    }
    //+------------------------------------------------------------------+
    //| |
    int start() //指標計算主函數,每次計算調用
    {
    ma();
    ma1();
    return(0);
    }
    //+------------------------------------------------------------------+
    //|自定義函數,這里只是直接使用庫函數實現MA, 若你自己計算,可設計任何指標 |
    //+------------------------------------------------------------------+
    void ma()
    {
    int pos=Bars; //Bars = Number of bars in the current chart.當前窗口中的蠟燭數
    while(pos>=0)
    {
    Buffer0[pos]=iMA(NULL,0,MA_Period,MA_Shift,MA_Method,MA_Price,pos);
    Buffer1[pos]=iMA(NULL,0,MA_Period*2,MA_Shift,MA_Method,MA_Price,pos);
    Buffer2[pos]=iMA(NULL,0,MA_Period*3,MA_Shift,MA_Method,MA_Price,pos);
    pos--;
    }
    }
    void ma1()
    {
    int pos=Bars; //Bars = Number of bars in the current chart.當前窗口中的蠟燭數
    while(pos>=0)
    {
    Buffer3[pos]=iMA(NULL,0,MA_Period*4,MA_Shift,MA_Method,MA_Price,pos);
    Buffer4[pos]=iMA(NULL,0,MA_Period*5,MA_Shift,MA_Method,MA_Price,pos);
    Buffer5[pos]=iMA(NULL,0,MA_Period*6,MA_Shift,MA_Method,MA_Price,pos);
    Buffer6[pos]=iMA(NULL,0,MA_Period*7,MA_Shift,MA_Method,MA_Price,pos);
    pos--;
    }
    }

【字體: 】【打印文章】【查看評論

相關文章

    沒有相關內容
主站蜘蛛池模板: 久久成人国产精品免费软件| 又爽又刺激的视频| 97人妻人人揉人人躁人人| 性放荡日记高h| 久久久久亚洲精品中文字幕| 最近免费韩国电影hd免费观看| 亚洲日韩久久综合中文字幕| 狠狠躁夜夜躁av网站中文字幕 | 国产免费爽爽视频在线观看| 亚洲国产成a人v在线观看| 国产超碰人人模人人爽人人添 | 情人伊人久久综合亚洲| 久久人妻av无码中文专区| 最近2019中文字幕mv免费看| 亚洲午夜小视频| 欧美日韩国产高清| 亚洲精品资源在线| 狍和女人一级毛片免费的| 免费a级黄毛片| 真实男女动态无遮挡图| 免费观看女人与狥交视频在线| 精品香蕉久久久午夜福利| 国产69精品久久久久9999apgf| 被公侵犯肉体中文字幕电影| 国产免费色视频| 高清国产性色视频在线| 国产成人精品无码一区二区 | 日本无遮挡漫画| 久久躁狠狠躁夜夜AV| 桃子视频在线官网观看免费| 亚洲另类视频在线观看| 欧美成人免费一级人片| 亚洲女初尝黑人巨高清| 欧美成人片在线观看| 亚洲成A人片在线观看无码| 欧美日韩精品久久久久| 亚洲欧洲无卡二区视頻| 欧美日韩一区视频| 亚洲国产精品一区二区九九 | 182tv成人午夜在线观看| 国产精品白丝av嫩草影院|