公告板

MT4編程參考三

    
        

            函數[Function]

        

            函數定義

        

            一個函數是由返回值、輸入參數、內嵌動作所群組成的。

        

            示例: 

        

            double // 返回值類型

        

            linfunc (double x, double a, double b) // 函數名和輸入參數

        

            {

        

            // 內嵌的動作

        

            return (a*x + b); // 返回值

        

            }

        

            若果沒有返回值那麼返回值的類型可以寫為void

        

            示例: 

        

            void errmesg(string s)

        

            {

        

            Print("error: "+s);

        

            }

        

            函數呼叫

        

            function_name (x1,x2,...,xn)

        

            示例:

        

            int somefunc()

        

            {

        

            double a=linfunc(0.3, 10.5, 8);

        

            }

        

            double linfunc(double x, double a, double b)

        

            {

        

            return (a*x + b);

        

            }

        

            特殊函數init()、deinit()和start()

        

            init()在載入時呼叫,可以用此函數在開始訂做指標或是自動交易之前做起始化動作。

        

            deinit()在卸載時呼叫,可以用此函數在去處訂做指標或是自動交易之前做起始化動作。 

        

            start()當資料變動時觸發,對於訂做指標或是自動交易的寫程式主要依靠此函數進行。

        

            變量[Variables]

        

            定義變量

        

            定義基本類型

        

            基本類型內含

        

            string - 字元串型;

        

            int - 整數型;

        

            double - 雙精度浮點數型;

        

            bool - 布爾型

        

            示例:

        

            string MessageBox;

        

            int Orders;

        

            double SymbolPrice;

        

            bool bLog;

        

            定義附加類型 

        

            附加類型內含

        

            datetime - 時間型,使用無符號整型數字存儲,是1970.1.1 0:0:0開始的秒數

        

            color - 彩色,使用三色的整型數字編碼而成

        

            示例:

        

            extern datetime tBegin_Data = D'2004.01.01 00:00';

        

            extern color cModify_Color = C'0x44,0xB9,0xE6';

        

            定義陣列類型

        

            示例:

        

            int a[50]; //一個一維由五十個int群組成的陣列

        

            double m[7][50]; //一個兩維由7x50個double群組成的陣列

        

            內定變量定義

        

            內定變量顧名思義是在內定使用的,可以理解為在目前嵌套內所使用的變量。

        

            函數參數定義

        

            示例:

        

            void func(int x, double y, bool z)

        

            {

        

            ...

        

            }

        

            函數的參數內的變量隻能在函數內才生效,在函數外無法使用,而且在函數內對變量進行的修改在函數外無法生效。

        

            呼叫函數示例:

        

            func(123, 0.5);

        

            若果有需要在變量傳入由參數傳入函數內動作後保留修改在函數外生效的情況的話,可以在參數定義的類型名稱後加上修飾符(&)。

        

            示例:

        

            void func(int& x, double& y, double& z[])

        

            {

        

            ...

        

            }

        

            靜態變量定義

        

            在資料類型前加上static就可以將變量定義成靜態變量

        

            示例:

        

            {

        

            static int flag

        

            }全局變量定義

        

            全局變量是指在整個程式中都能夠呼叫的變量,隻需將變量定義卸載所有嵌套之外即可。

        

            示例:

        

            int Global_flag;

        

            int start()

        

            {

        

            ...

        

            }

        

            附加變量定義

        

            附加變量可以容許由使用者自己輸入。

        

            示例:

        

            extern double InputParameter1 = 1.0;

        

            int init()

        

            {

        

             

        

            ...

        

             

        

            }

        

             起始化變量

        

            變量必須經由起始化才可以使用。

        

            基本類型

        

            示例:

        

            int mt = 1; // integer 起始化

        

            // double 起始化

        

            double p = MarketInfo(Symbol(),MODE_POINT);

        

            // string 起始化

        

            string s = "hello";

        

            陣列類型

        

            示例:

        

            int mta[6] = {1,4,9,16,25,36};

        

            外部函數引用

        

            示例:

        

            #import "user32.dll" 

        

            int MessageBoxA(int hWnd ,string szText,

        

            string szCaption,int nType);

        

            int SendMessageA(int hWnd,int Msg,int wParam,int lParam);

        

            #import "lib.ex4"

        

            double round(double value);

        

            #import

        

            預處理程式[Preprocessor]

        

            定義常量

        

            #define identifier_value

        

            常量可以是任何類型的,常量在程式中不可變更。

        

            示例:

        

            #define ABC 100

        

            #define PI 0.314

        

            #define COMPANY_NAME "MetaQuotes Software Corp."

        

            編譯參數定義

        

            #property identifier_value

        

            示例:

        

            #property link http://www.metaquotes.net

        

            #property copyright "MetaQuotes Software Corp."

        

            #property stacksize 1024

        

            以下是所有的參數名稱:

        

            參數名稱 

        

             類型

        

             說明

        

            link

        

             string

        

             設定一個連結到公司網站

        

            copyright

        

             string

        

              公司名稱

        

            stacksize

        

             int

        

             堆堆疊大小

        

            indicator_chart_window

        

             void

        

              顯示在走勢圖視窗

        

            indicator_separate_window

        

             void

        

             顯示在新區塊

        

            indicator_buffers

        

             int

        

            顯示快取最高8

        

            indicator_minimum

        

             int

        

            圖形區間最低點 

        

            indicator_maximum

        

             int

        

             圖形區間最高點

        

            indicator_colorN

        

             color

        

             第N根線的彩色,最高8根線

        

            indicator_levelN

        

             double

        

             predefined level N for separate window custom indicator

        

            show_confirm

        

             void

        

             當程式執行之前是否經由確認

        

            show_inputs

        

             void

        

              before script run its property sheet appears; disables show_confirm property

        

            內嵌檔案

        

            #include <file_name>

        

            示例:

        

            #include <win32.h>

        

            #include "file_name"

        

            示例:

        

            #include "mylib.h"

        

            引入函數或其他模組

        

            #import "file_name"

        

            func1();

        

            func2();

        

            #import

        

            示例:

        

            #import "user32.dll"

        

            int MessageBoxA(int hWnd,string lpText,string lpCaption,

        

            int uType);

        

            int MessageBoxExA(int hWnd,string lpText,string lpCaption,

        

            int uType,int wLanguageId); 

        

            #import "melib.ex4"

        

            #import "gdi32.dll"

        

            int GetDC(int hWnd);

        

            int ReleaseDC(int hWnd,int hDC);

        

            #import

        

            賬戶訊息[Account Information]

        

            double AccountBalance()

        

            返回賬戶餘額

        

            示例:

        

            Print("Account balance = ",AccountBalance());

        

            double AccountCredit()

        

            返回賬戶信用點數

        

            示例:

        

            Print("Account number ", AccountCredit());

        

            string AccountCompany() 

        

            返回賬戶公司名

        

             示例:

        

            Print("Account company name ", AccountCompany());

        

            string AccountCurrency()

        

            返回賬戶所用的通貨名稱

        

            示例:

        

            Print("account currency is ", AccountCurrency());

        

            double AccountEquity()

        

            返回資產淨值

        

            示例:

        

            Print("Account equity = ",AccountEquity());

        

            double AccountFreeMargin()

        

            Returns free margin value of the current account.

        

            示例:

        

            Print("Account free margin = ",AccountFreeMargin());

    學習外匯交易賺錢
引用通告位址: http://mforex.org/trackback.php?tbID=744&extra=77c1d2
標籤: 外匯交易學習站 外匯技術面
評論: 0 | 引用: 0 | 閱讀: 4269
 加入網摘

對於【翻倉系統】有興趣的人,填寫【翻倉系統預購表單】加入

【翻倉系統LucyDoubleBooster登記表】https://forexatm999.com/go/lucydoublebooster/
外匯交易輔助軟體【翻倉系統】付一年的費用,賺三年的錢!檔也擋不住的划算!要賺要快!