【正文】
可以內(nèi)嵌多個用逗號(,)分割的表達式。iN。函數(shù) [Function]函數(shù)定義一個函數(shù)是由返回值、輸入?yún)?shù)、內(nèi)嵌操作所組成的。 // 返回值}如果沒有返回值那么返回值的類型可以寫為void示例:void errmesg(string s){Print(error: +s)。}double linfunc(double x, double a, double b){return (a*x + b)。deinit()在卸載時調用,可以用此函數(shù)在去處自定義指標或者自動交易之前做初始化操作。變量 [Variables]定義變量定義基本類型基本類型包括 int Orders。bool bLog。 datetime 時間型,使用無符號整型數(shù)字存儲, 0:0:0開始的秒數(shù) 00:0039。0x44,0xB9,0xE639。 //一個一維由五十個int組成的數(shù)組double m[7][50]。函數(shù)參數(shù)定義示例:void func(int x, double y, bool z){...}函數(shù)的參數(shù)內(nèi)的變量只能在函數(shù)內(nèi)才生效,在函數(shù)外無法使用,而且在函數(shù)內(nèi)對變量進行的修改在函數(shù)外無法生效。如果有需要在變量傳入由參數(shù)傳入函數(shù)內(nèi)操作后保留修改在函數(shù)外生效的情況的話,可以在參數(shù)定義的類型名稱后加上修飾符(amp。示例:void func(intamp。 y, doubleamp。示例:int Global_flag。示例:extern double InputParameter1 = ?;绢愋褪纠?int mt = 1。// string 初始化string s = hello。外部函數(shù)引用示例:import int MessageBoxA(int hWnd ,string szText,string szCaption,int nType)。import double round(double value)。示例:define ABC 100define PI define COMPANY_NAME MetaQuotes Software Corp.編譯參數(shù)定義property identifier_value示例:property link property copyright MetaQuotes Software Corp.property stacksize 1024以下是所有的參數(shù)名稱: 參數(shù)名稱類型說明link string 設置一個鏈接到公司網(wǎng)站copyright string 公司名稱stacksize int 堆棧大小indicator_chart_window void 顯示在走勢圖窗口indicator_separate_window void 顯示在新區(qū)塊indicator_buffers int 顯示緩存最高8indicator_minimum int 圖形區(qū)間最低點indicator_maximum int 圖形區(qū)間最高點indicator_colorN color 第N根線的顏色,最高8根線indicator_levelN double predefined level N for separate window custom indicatorshow_confirm void 當程序執(zhí)行之前是否經(jīng)過確認show_inputs void before script run its property sheet appears。func2()。int MessageBoxExA(int hWnd,string lpText,string lpCaption,int uType,int wLanguageId)。int ReleaseDC(int hWnd,int hDC)。double AccountCredit()返回賬戶信用點數(shù)示例:Print(Account number , AccountCredit())。string AccountCurrency()返回賬戶所用的通貨名稱示例:Print(account currency is , AccountCurrency())。double AccountFreeMargin()Returns free margin value of the current account.示例:Print(Account free margin = ,AccountFreeMargin())。double AccountMargin()Returns margin value of the current account.示例:Print(Account margin , AccountMargin())。int AccountNumber()返回賬戶數(shù)字示例:Print(account number , AccountNumber())。數(shù)組函數(shù) [Array Functions]int ArrayBsearch( double array[], double value, int count=WHOLE_ARRAY, int start=0, int direction=MODE_ASCEND)搜索一個值在數(shù)組中的位置此函數(shù)不能用在字符型或連續(xù)數(shù)字的數(shù)組上.:: 輸入?yún)?shù)array[] 需要搜索的數(shù)組value 將要搜索的值 count 搜索的數(shù)量,默認搜索所有的數(shù)組start 搜索的開始點,默認從頭開始direction 搜索的方向,MODE_ASCEND 順序搜索 MODE_DESCEND 倒序搜索 示例:datetime daytimes[]。// All the Time[] timeseries are sorted in descendant modeArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1)。else{dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND)。}Print(TimeToStr(Time[shift]), corresponds to ,dayshift, day bar opened at ,TimeToStr(daytimes[dayshift]))。 dest[], object source[], int start_dest=0, int start_source=0, int count=WHOLE_ARRAY) 復制一個數(shù)組到另外一個數(shù)組。 :: 輸入?yún)?shù)dest[] 目標數(shù)組 source[] 源數(shù)組 start_dest 從目標數(shù)組的第幾位開始寫入,默認為0 start_source 從源數(shù)組的第幾位開始讀取,默認為0 count 讀取多少位的數(shù)組 示例:double array1[][6]。// fill array with some dataArrayCopyRates(array1)。// now array2 has first 10 bars in the historyint ArrayCopyRates( doubleamp。ArrayCopyRates(array1,EURUSD, PERIOD_H1)。int ArrayCopySeries( doubleamp。int shift=10,dayshift。if(Time[shift]=daytimes[0]) dayshift=0。if(Period()}Print(TimeToStr(Time[shift]), corresponds to ,dayshift, day bar opened at , TimeToStr(daytimes[dayshift]))。int dim_size。// dim_size is 2bool ArrayGetAsSeries(object array[])檢查數(shù)組是否是有組織序列的數(shù)組(是否從最后到最開始排序過的),如果不是返回否 :: 輸入?yún)?shù)array[] 需要檢查的數(shù)組 示例:if(ArrayGetAsSeries(array1)==true)Print(array1 is indexed as a series array)。int ArrayInitialize( doubleamp。ArrayInitialize(myarray,)。else{Print(Series array cannot be initialized!)。}int ArrayMaximum( double array[], int count=WHOLE_ARRAY, int start=0) 找出數(shù)組中最大值的定位 :: 輸入?yún)?shù)array[] 需要檢查的數(shù)組count 搜索數(shù)組中項目的個數(shù)start 搜索的開始點 示例:double num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9}。Print(Max value = , num_array[maxValueIdx])。double minValueidx=ArrayMinimum(num_array)。int ArrayRange( object array[], int range_index) 取數(shù)組中指定維數(shù)中項目的數(shù)量。double num_array[10,10,10]。int ArrayResize( objectamp。int element_count=ArrayResize(array, 20)。 array[], bool set) 設置指數(shù)數(shù)組為系列數(shù)組,數(shù)組0位的值是最后的值。double signal_buffer[300]。ArraySetAsSeries(macd_buffer,true)。 imacd_buffer=iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,i)iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE,i)。 isignal_buffer=iMAOnArray(macd_buffer,limit,9,0,MODE_SMA,i)。for(int i=0。 array[], int count=WHOLE_ARRAY, int start=0, int sort_dir=MODE_ASCEND) 對數(shù)組進行排序,系列數(shù)組不可進行排序 :: 輸入?yún)?shù)array[] 需要處理的數(shù)組count 對多少個數(shù)組項進行排序start 排序的開始點sort_dir 排序方式,MODE_ASCEND順序排列 MODE_DESCEND倒序排列 示例:double num_array[5]={4,1,6,3,9}。// now array is sorted 1,3,4,6,9ArraySort(num_array,MODE_DESCEND)。 // 44 is code for 39。// resulting string will be WORLDstring DoubleToStr( double value, int digits)將雙精度浮點型轉換成字符串型結果返回 :: 輸入?yún)?shù)value 浮點型數(shù)字digits 小數(shù)點后多少位,08 示例:string value=DoubleToStr(, 5)。Print(NormalizeDouble(var1,5))。int StrToInteger( string value)將字符串型轉換成整型結果返回 :: 輸入?yún)?shù)value 數(shù)字的字符串 示例:int var1=StrToInteger(1024)。var1=StrToTime( 17:35)。 // returns with current datevar1=StrToTime()。公用函數(shù) [Common Functions]void Alert( ... ) 彈出一個顯示信息的警告窗口:: 輸入?yún)?shù)... 任意值,如有多個可用逗號分割 示例:if(Close[0]SignalLevel)Alert(Close price ing , Close[0],!!!)。string CompanyName()返回公司名稱示例:Print(Company name is ,CompanyName())。Comment(Account free margin is ,DoubleToStr(free,2),\n,Current time is ,TimeToStr(CurTime()))。int handle=FileOpen(, FILE_