MT4语法学习
語法?[Syntax]
代碼格式
空格建、Tab鍵、換行鍵和換頁符都可以成為代碼排版的分隔符,你能使用各種符號來增加代碼的可讀性。
注釋?
多行注釋使用?/*?作為開始到?*/?結束,在這之間不能夠嵌套。單行注釋使用?//?作為開始到新的一行結束,可以被嵌套到多行注釋之中。
示例:
//?單行注釋?
/*?多行
?????注釋?//?嵌套的單行注釋?
注釋結束?*/
標識符?
標識符用來給變量、函數和數據類型進行命名,長度不能超過31個字節
你可以使用數字0-9、拉丁字母大寫A-Z和小寫a-z(大小寫有區分的)還有下劃線(_)。此外首字母不可以是數字,標識符不能和保留字沖突.
示例:
//?NAME1?namel?Total_5?Paper
保留字?
下面列出的是固定的保留字。不能使用以下任何保留字進行命名。?
數據類型 存儲類型 操作符 其它
bool? extern? break? false?
color? static? case? true?
datetime? continue?
double? default?
int? else?
string? for?
void? if?
return?
switch?
while?
數據類型?[Data?types]
數據類型概述
主要數據類型有:
? Integer?(int)?
? Boolean?(bool)?
? ?èò?eà???(char)?
? String?(string)?
? Floating-point?number?(double)?
? Color?(color)?
? Datetime?(datetime)?
我們用Integer類型數據來作為DateTime和Color數據的存儲。
使用以下方式可以進行類型站換:
int?(bool,color,datetime);
double;
string;
Integer?類型
十進制:?數字0-9;0不能作為第一個字母
示例:
12,?111,?-956?1007
十六進制:?數字0-9;拉丁字母a-f或A-F用來表示10-15;使用0x或者0X作為開始。
示例:
0x0A,?0x12,?0X12,?0x2f,?0xA3,?0Xa3,?0X7C7
Integer?變量的取值范圍為-2147483648到2147483647。
Literal?類型
任意在單引號中的字符或十六進制的任意ASCII碼例如'\x10'都是被看作為一個字符,
一些字符例如單引號('),雙引號("),問號(?),反斜杠(\)和一些控制符都需要在之前加一個反斜杠(\)進行轉意后表示出來:
line?feed?NL?(LF)?\n
horizontal?tab?HT?\t
carriage?return?CR?\r
reverse?slash?\?\\
single?quote?'?\'
double?quote?"?\"
hexadecimal?ASCII-code?hh?\xhh
以上字符如果不經過反斜杠進行轉意將不能被使用
示例:
int?a?=?'A';
int?b?=?'$';
int?c?=?'?';?//?code?0xA9
int?d?=?'\xAE';?//?symbol?code??
Boolean?類型
Boolean?用來表示?是?和?否,?還可以用數字?1?和?0?進行表示。True和Flase可以忽略大小寫。
示例:
bool?a?=?true;
bool?b?=?false;
bool?c?=?1;
Floating-point?number?類型
浮點型變量在整數型后面加一個點(.)用來更精確的表示十進制數字。
示例:
double?a?=?12.111;
double?b?=?-956.1007;
double?c?=?0.0001;
double?d?=?16;
浮點型的取值范圍從?2.2e-308?到?1.8e308.
String?類型
字符串型是用來表示連續的ASCII碼字符的使用連續的兩個雙引號來包括需要表示的內容如:"Character?constant".
示例:
"This?is?a?character?string"
"Copyright?symbol?\t\xA9"
"this?line?with?LF?symbol?\n"
"A"?"1234567890"?"0"?"$"
Color?類型
顏色類型可以使用以下示例里的幾種方式進行定義。?
示例:
//?symbol?constants
C'128,128,128'?//?gray
C'0x00,0x00,0xFF'?//?blue
//?named?color
Red
Yellow
Black
//?integer-valued?representation
0xFFFFFF?//?white
16777215?//?white
0x008000?//?green
32768?//?green
Datetime?類型
時間類型使用年、月、日、時、分、秒來進行定義,你可以使用以下示例中的方式來定義變量。
示例:
D'2004.01.01?00:00'?//?New?Year
D'1980.07.19?12:30:27'
D'19.07.1980?12:30:27'
D'19.07.1980?12'?//equal?to?D'1980.07.19?12:00:00'
D'01.01.2004'?//equal?to?D'01.01.2004?00:00:00'
D'12:30:27'?//equal?to?D'[compilation?date]?12:30:27'
D''?//equal?to?D'[compilation?date]?00:00:00'
運算符和表達式?[Operations?&?Expressions]
表達式
一個表達式可以擁有多個字符和操作符,一個表達式可以寫在幾行里面。
示例:
a++;?b?=?10;?x?=?(y*z)/w;
注:分號(;)是表達式的結束符。
算術運算符
Sum?of?values?i?=?j?+?2;
Difference?of?values?i?=?j?-?3;
Changing?the?operation?sign?x?=?-?x;
Product?of?values?z?=?3?*?x;
Division?quotient?i?=?j?/?5;
Division?remainder?minutes?=?time?%?60;
Adding?1?to?the?variable?value?i++;
Subtracting?1?from?the?variable?value?k--;
加減1的運算符不能被嵌套在表達式中
int?a=3;
a++;?//?可行的表達式
int?b=(a++)*3;?//?不可行的表達式
賦值運算符
注:將右側的結果賦值給左側的變量
將x的值賦值給y?y?=?x;
將x的值加到y上面?y?+=?x;
在y上面減去x的值?y?-=?x;
得到y的x倍的值?y?*=?x;
得到y除以x的值?y?/=?x;
取y除以x后的余數?y?%=?x;
y向右位移x位?y?>>=?x;
y向左位移x位?y?<<=?x;
得到邏輯AND的值?y?&=?x;
得到邏輯OR的值?y?|=?x;
得到邏輯非OR的值?y?^=?x;
注:一個表達式只能有一個賦值運算符.
關系運算符
用返回0(False)或1(True)來表示兩個量之間的關系。
a是否等于b?a?==?b;
a是否不等于b?a?!=?b;
a是否小于b?a?<?b;
a是否大于b?a?>?b;
a是否小于等于b?a?<=?b;
a是否大于等于b?a?>=?b;
真假運算符
否定運算符(!),用來表示真假的反面的結果。
//?如果a不是真的
if(!a)
Print("not?'a'");
邏輯運算符或(||)用來表示兩個表達式只要有一個成立即可。
示例:
if(xl)
Print("out?of?range");
邏輯運算符和(&&)用來表示兩個表達式要同時成立才行。
示例:
if(p!=x?&&?p>y)
Print("true");
n++;
位邏輯運算符
~?運算符對操作數執行按位求補操作。
b?=?~n;
>>?運算符對操作數執行向右位移操作。
x?=?x?>>?y;
<<?運算符對操作數執行向左位移操作。
x?=?x?<<?y;
一元?&?運算符返回操作數的地址
為整型和?bool?類型預定義了二進制?&?運算符。對于整型,&?計算操作數的按位“與”。對于?bool?操作數,&?計算操作數的邏輯“與”;也就是說,當且僅當兩個操作數均為?true?時,其結果才為?true。
b?=?((x?&?y)?!=?0);
二進制?|?運算符是為整型和?bool?類型預定義的。對于整型,|?對操作數進行按位“或”運算。對于?bool?操作數,|?對操作數進行邏輯“或”計算,也就是說,當且僅當兩個操作數均為?false?時,其結果才為?false。
b?=?x?|?y;
為整型和?bool?類型預定義了?^?二進制操作數。對于整型,^?計算操作數的按位“異或”。對于?bool?操作數,^?計算操作數的邏輯“異或”;也就是說,當且僅當只有一個操作數為?true?時,其結果才為?true。
b?=?x?^?y;
注:位邏輯運算符只作用于Integers類型
其它運算符
索引。定位在數組中i位置的值。
array[i]?=?3;
//將3負值到array數組第i位置上
使用?x1,x2,...,xn?這樣的方法將各種值傳送到function中進行運算。
示例:
double?SL=Ask-25*Point;
double?TP=Ask+25*Point;
int?ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,SL,TP,
"My?comment",123,0,Red);
優先級規則
下面是從上到下的運算優先規則,優先級高的將先被運算。
()?Function?call?From?left?to?right
[]?Array?element?selection
!?Negation?From?left?to?right
~?Bitwise?negation
-?Sign?changing?operation
*?Multiplication?From?left?to?right
/?Division
%?Module?division
+?Addition?From?left?to?right
-?Subtraction
<<?Left?shift?From?left?to?right
>>?Right?shift
<?Less?than?From?left?to?right
<=?Less?than?or?equals
>?Greater?than
>=?Greater?than?or?equals
==?Equals?From?left?to?right
!=?Not?equal
&?Bitwise?AND?operation?From?left?to?right
^?Bitwise?exclusive?OR?From?left?to?right
|?Bitwise?OR?operation?From?left?to?right
&&?Logical?AND?From?left?to?right
||?Logical?OR?From?left?to?right
=?Assignment?From?right?to?left
+=?Assignment?addition
-=?Assignment?subtraction
*=?Assignment?multiplication
/=?Assignment?division
%=?Assignment?module
>>=?Assignment?right?shift
<<=?Assignment?left?shift
&=?Assignment?bitwise?AND
|=?Assignment?bitwise?OR
^=?Assignment?exclusive?OR
,?Comma?From?left?to?right
操作符?[Operators]?
格式和嵌套
格式.一個操作符可以占用一行或者多行,兩個或多個操作符可以占用更多的行。
嵌套.執行控制符(if,?if-else,?switch,?while?and?for)可以進行任意嵌套.
復合操作符
一個復合操作符有一個(一個區段)和由一個或多個任何類型的操作符組成的的附件{}.?每個表達式使用分號作為結束(;)
示例:
if(x==0)
{
x=1;?y=2;?z=3;
}
表達式操作符
任何以分號(;)結束的表達式都被視為是一個操作符。
Assignment?operator.
Identifier=expression;
標識符=表達式;
示例:
x=3;
y=x=3;?//?這是錯誤的
一個操作符中只能有一個表達式。
調用函數操作符
Function_name(argument1,...,?argumentN);
函數名稱(參數1,...,參數N);
示例:
fclose(file);
空操作符
只有一個分號組成(;).我們用它來表示沒有任何表達式的空操作符.
停止操作符
一個break;?,?我們將其放在嵌套內的指定位置,用來在指定情況下跳出循環操作.
示例:
//?從0開始搜索數組
for(i=0;i<ARRAY_SIZE;I++)
if((array[i]==0)
break;
繼續操作符
一個continue;我們將其放在嵌套內的指定位置,用來在指定情況下跳過接下來的運算,直接跳入下一次的循環。
示例:
//?summary?of?nonzero?elements?of?array
int?func(int?array[])
{
int?array_size=ArraySize(array);
int?sum=0;
for(int?i=0;i
{
if(a[i]==0)?continue;
sum+=a[i];
}
return(sum);
}
返回操作符
一個return;將需要返回的結果放在return后面的()中。
示例:
return(x+y);
條件操作符?if
if?(expression)
operator;
如果表達式為真那么執行操作。
示例:
if(a==x)
temp*=3;
temp=MathAbs(temp);
條件操作符?if-else
if?(expression)
operator1
else
operator2
如果表達式為真那么執行operator1,如果為假執行operator2,else后還可以跟進多個if執行多項選擇。詳見示例。
示例:
if(x>1)
if(y==2)
z=5;
else
z=6;?
if(x>l)
{
if(y==2)?z=5;
}
else
{
z=6;
}
//?多項選擇
if(x=='a')
{
y=1;
}
else?if(x=='b')
{
y=2;
z=3;
}
else?if(x=='c')
{
y?=?4;
}
else
{
Print("ERROR");
}
選擇操作符?switch
switch?(expression)
{
case?constant1:?operators;?break;
case?constant2:?operators;?break;
...
default:?operators;?break;
}
當表達式expression的值等于結果之一時,執行其結果下的操作。不管結果如何都將執行default中的操作。
示例:
case?3+4:?//正確的
case?X+Y:?//錯誤的
被選擇的結果只可以是常數,不可為變量或表達式。
示例:
switch(x)
{
case?'A':
Print("CASE?A\n");
break;
case?'B':
case?'C':
Print("CASE?B?or?C\n");
break;
default:
Print("NOT?A,?B?or?C\n");
break;
}
循環操作符?while
while?(expression)
operator;
只要表達式expression為真就執行操作operator
示例:
while(k<N)
{
y=y*x;
k++;
}
循環操作符?for
for?(expression1;?expression2;?expression3)
operator;
用表達式1(expression1)來定義初始變量,當表達式2(expression2)為真的時候執行操作operator,在每次循環結束后執行表達式3(expression3)
用while可以表示為這樣:
expression1;
while?(expression2)
{
operator;
expression3;
};
示例:
for(x=1;x<=7;x++)
Print(MathPower(x,2));
使用for(;;)可以造成一個死循環如同while(true)一樣.
表達式1和表達式3都可以內嵌多個用逗號(,)分割的表達式。
示例:
for(i=0,j=n-l;i<N;I++,J--)
a[i]=a[j];
函數?[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());
int?AccountLeverage()
返回杠桿比率
示例:
Print("Account?#",AccountNumber(),?"?leverage?is?",?AccountLeverage());
double?AccountMargin()
Returns?margin?value?of?the?current?account.
示例:
Print("Account?margin?",?AccountMargin());
string?AccountName()
返回賬戶名稱
示例:
Print("Account?name?",?AccountName());
int?AccountNumber()
返回賬戶數字
示例:
Print("account?number?",?AccountNumber());
double?AccountProfit()
返回賬戶利潤
示例:
Print("Account?profit?",?AccountProfit());
數組函數?[Array?Functions]
int?ArrayBsearch(?double?array[],?double?value,?int?count=WHOLE_ARRAY,?int?start=0,?int?direction=MODE_ASCEND)
搜索一個值在數組中的位置
此函數不能用在字符型或連續數字的數組上.
::?輸入參數
array[]?-?需要搜索的數組
value?-?將要搜索的值?
count?-?搜索的數量,默認搜索所有的數組
start?-?搜索的開始點,默認從頭開始
direction?-?搜索的方向,MODE_ASCEND?順序搜索?MODE_DESCEND?倒序搜索?
示例:
datetime?daytimes[];
int?shift=10,dayshift;
//?All?the?Time[]?timeseries?are?sorted?in?descendant?mode
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
if(Time[shift]>>=daytimes[0])?dayshift=0;
else
{
dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<PERIOD_D1)
dayshift++;
}
Print(TimeToStr(Time[shift]),"?corresponds?to?",dayshift,"?day?bar?opened?at?",
TimeToStr(daytimes[dayshift]));
int?ArrayCopy(?object&?dest[],?object?source[],?int?start_dest=0,?int?start_source=0,?int?count=WHOLE_ARRAY)?
復制一個數組到另外一個數組。
只有double[],?int[],?datetime[],?color[],?和?bool[]?這些類型的數組可以被復制。?
::?輸入參數
dest[]?-?目標數組?
source[]?-?源數組?
start_dest?-?從目標數組的第幾位開始寫入,默認為0?
start_source?-?從源數組的第幾位開始讀取,默認為0?
count?-?讀取多少位的數組?
示例:
double?array1[][6];
double?array2[10][6];
//?fill?array?with?some?data
ArrayCopyRates(array1);
ArrayCopy(array2,?array1,0,Bars-9,10);
//?now?array2?has?first?10?bars?in?the?history
int?ArrayCopyRates(?double&?dest_array[],?string?symbol=NULL,?int?timeframe=0)?
復制一段走勢圖上的數據到一個二維數組,數組的第二維只有6個項目分別是:
0?-?時間,
1?-?開盤價,
2?-?最低價,
3?-?最高價,
4?-?收盤價,
5?-?成交量.?
::?輸入參數
dest_array[]?-?目標數組
symbol?-?標示,當前所需要的通貨的標示
timeframe?-?圖表的時間線?
示例:
double?array1[][6];
ArrayCopyRates(array1,"EURUSD",?PERIOD_H1);
Print("Current?bar?",TimeToStr(array1[0][0]),"Open",?array1[0][1]);
int?ArrayCopySeries(?double&?array[],?int?series_index,?string?symbol=NULL,?int?timeframe=0)?
復制一個系列的走勢圖數據到數組上
注:?如果series_index是MODE_TIME,?那么第一個參數必須是日期型的數組?
::?輸入參數
dest_array[]?-?目標數組
series_index?-?想要取的系列的名稱或編號,0-5
symbol?-?標示,當前所需要的通貨的標示
timeframe?-?圖表的時間線?
示例:
datetime?daytimes[];
int?shift=10,dayshift;
//?All?the?Time[]?timeseries?are?sorted?in?descendant?mode
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
if(Time[shift]>=daytimes[0])?dayshift=0;
else
{
dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()
}
Print(TimeToStr(Time[shift]),"?corresponds?to?",dayshift,"?day?bar?opened?at?",?TimeToStr(daytimes[dayshift]));
int?ArrayDimension(?int?array[])?
返回數組的維數?
::?輸入參數
array[]?-?需要檢查的數組?
示例:
int?num_array[10][5];
int?dim_size;
dim_size=ArrayDimension(num_array);
//?dim_size?is?2
bool?ArrayGetAsSeries(object?array[])
檢查數組是否是有組織序列的數組(是否從最后到最開始排序過的),如果不是返回否?
::?輸入參數
array[]?-?需要檢查的數組?
示例:
if(ArrayGetAsSeries(array1)==true)
Print("array1?is?indexed?as?a?series?array");
else
Print("array1?is?indexed?normally?(from?left?to?right)");
int?ArrayInitialize(?double&?array[],?double?value)
對數組進行初始化,返回經過初始化的數組項的個數?
::?輸入參數
array[]?-?需要初始化的數組
value?-?新的數組項的值?
示例:
//----?把所有數組項的值設置為2.1
double?myarray[10];
ArrayInitialize(myarray,2.1);
bool?ArrayIsSeries(?object?array[])?
檢查數組是否連續的(time,open,close,high,low,?or?volume).?
::?輸入參數
array[]?-?需要檢查的數組?
示例:
if(ArrayIsSeries(array1)==false)
ArrayInitialize(array1,0);
else
{
Print("Series?array?cannot?be?initialized!");
return(-1);
}
int?ArrayMaximum(?double?array[],?int?count=WHOLE_ARRAY,?int?start=0)?
找出數組中最大值的定位?
::?輸入參數
array[]?-?需要檢查的數組
count?-?搜索數組中項目的個數
start?-?搜索的開始點?
示例:
double?num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
int?maxValueIdx=ArrayMaximum(num_array);
Print("Max?value?=?",?num_array[maxValueIdx]);
int?ArrayMinimum(?double?array[],?int?count=WHOLE_ARRAY,?int?start=0)?
找出數組中最小值的定位?
::?輸入參數
array[]?-?需要檢查的數組
count?-?搜索數組中項目的個數
start?-?搜索的開始點?
示例:
double?num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
double?minValueidx=ArrayMinimum(num_array);
Print("Min?value?=?",?num_array[minValueIdx]);
int?ArrayRange(?object?array[],?int?range_index)?
取數組中指定維數中項目的數量。?
::?輸入參數
array[]?-?需要檢查的數組
range_index?-?指定的維數?
示例:
int?dim_size;
double?num_array[10,10,10];
dim_size=ArrayRange(num_array,?1);
int?ArrayResize(?object&?array[],?int?new_size)?
重定義數組大小?
::?輸入參數
array[]?-?需要檢查的數組
new_size?-?第一維中數組的新大小?
示例:
double?array1[][4];
int?element_count=ArrayResize(array,?20);
//?數組中總項目數為80
bool?ArraySetAsSeries(?double&?array[],?bool?set)?
設置指數數組為系列數組,數組0位的值是最后的值。返回之前的數組狀態?
::?輸入參數
array[]?-?需要處理的數組
set?-?是否是設置為系列數組,true或者false?
示例:
double?macd_buffer[300];
double?signal_buffer[300];
int?i,limit=ArraySize(macd_buffer);
ArraySetAsSeries(macd_buffer,true);
for(i=0;?i
macd_buffer[i]=iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0;?i
signal_buffer[i]=iMAOnArray(macd_buffer,limit,9,0,MODE_SMA,i);
int?ArraySize(?object?array[])?
返回數組的項目數?
::?輸入參數
array[]?-?需要處理的數組?
示例:
int?count=ArraySize(array1);
for(int?i=0;?i
{
//?do?some?calculations.
}
int?ArraySort(?double&?array[],?int?count=WHOLE_ARRAY,?int?start=0,?int?sort_dir=MODE_ASCEND)?
對數組進行排序,系列數組不可進行排序?
::?輸入參數
array[]?-?需要處理的數組
count?-?對多少個數組項進行排序
start?-?排序的開始點
sort_dir?-?排序方式,MODE_ASCEND順序排列?MODE_DESCEND倒序排列?
示例:
double?num_array[5]={4,1,6,3,9};
//?now?array?contains?values?4,1,6,3,9
ArraySort(num_array);
//?now?array?is?sorted?1,3,4,6,9
ArraySort(num_array,MODE_DESCEND);
//?now?array?is?sorted?9,6,4,3,1
類型轉換函數?[Conversion?Functions]
string?CharToStr(?int?char_code)?
將字符型轉換成字符串型結果返回
::?輸入參數
char_code?-?字符的ACSII碼?
示例:
string?str="WORL"?+?CharToStr(44);?//?44?is?code?for?'D'
//?resulting?string?will?be?WORLD
string?DoubleToStr(?double?value,?int?digits)
將雙精度浮點型轉換成字符串型結果返回?
::?輸入參數
value?-?浮點型數字
digits?-?小數點后多少位,0-8?
示例:
string?value=DoubleToStr(1.28473418,?5);
//?value?is?1.28473
double?NormalizeDouble(?double?value,?int?digits)?
將雙精度浮點型格式化后結果返回?
::?輸入參數
value?-?浮點型數字
digits?-?小數點后多少位,0-8?
示例:
double?var1=0.123456789;
Print(NormalizeDouble(var1,5));
//?output:?0.12346
double?StrToDouble(?string?value)
將字符串型轉換成雙精度浮點型結果返回?
::?輸入參數
value?-?數字的字符串?
示例:
double?var=StrToDouble("103.2812");
int?StrToInteger(?string?value)
將字符串型轉換成整型結果返回?
::?輸入參數
value?-?數字的字符串?
示例:
int?var1=StrToInteger("1024");
datetime?StrToTime(?string?value)?
將字符串型轉換成時間型結果返回,輸入格式為?yyyy.mm.dd?hh:mi?
::?輸入參數
value?-?時間的字符串?
示例:
datetime?var1;
var1=StrToTime("2003.8.12?17:35");
var1=StrToTime("17:35");?//?returns?with?current?date
var1=StrToTime("2003.8.12");?//?returns?with?midnight?time?"00:00"
string?TimeToStr(?datetime?value,?int?mode=TIME_DATE|TIME_MINUTES)
將時間型轉換成字符串型返回?
::?輸入參數
value?-?時間的數字,從1970.1.1?0:0:0?到現在的秒數
mode?-?返回字符串的格式?TIME_DATE(yyyy.mm.dd),TIME_MINUTES(hh:mi),TIME_SECONDS(hh:mi:ss)?
示例:
strign?var1=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);
公用函數?[Common?Functions]
void?Alert(?...?)?
彈出一個顯示信息的警告窗口
::?輸入參數
...?-?任意值,如有多個可用逗號分割?
示例:
if(Close[0]>SignalLevel)
Alert("Close?price?coming?",?Close[0],"!!!");
string?ClientTerminalName()
返回客戶終端名稱
示例:
Print("Terminal?name?is?",ClientTerminalName());
string?CompanyName()
返回公司名稱
示例:
Print("Company?name?is?",CompanyName());
void?Comment(?...?)
顯示信息在走勢圖左上角?
::?輸入參數
...?-?任意值,如有多個可用逗號分割?
示例:
double?free=AccountFreeMargin();
Comment("Account?free?margin?is?",DoubleToStr(free,2),"\n","Current?time?is?",TimeToStr(CurTime()));
int?GetLastError()
取最后錯誤在錯誤中的索引位置
示例:
int?err;
int?handle=FileOpen("somefile.dat",?FILE_READ|FILE_BIN);
if(handle<1)
{
err=GetLastError();
Print("error(",err,"):?",ErrorDescription(err));
return(0);
}
int?GetTickCount()
取時間標記,函數取回用毫秒標示的時間標記。
示例:
int?start=GetTickCount();
//?do?some?hard?calculation...
Print("Calculation?time?is?",?GetTickCount()-start,?"?milliseconds.");
void?HideTestIndicators(bool?hide)
使用此函數設置一個在Expert?Advisor的開關,在測試完成之前指標不回顯示在圖表上。?
::?輸入參數
hide?-?是否隱藏?True或者False?
示例:
HideTestIndicators(true);
bool?IsConnected()
返回客戶端是否已連接
示例:
if(!IsConnected())
{
Print("Connection?is?broken!");
return(0);
}
//?Expert?body?that?need?opened?connection
//?...
bool?IsDemo()
返回是否是模擬賬戶
示例:
if(IsDemo())?Print("I?am?working?on?demo?account");
else?Print("I?am?working?on?real?account");
bool?IsDllsAllowed()
返回是否允許載入Dll文件
示例:
#import?"user32.dll"
int?MessageBoxA(int?hWnd?,string?szText,?string?szCaption,int?nType);
...
...
if(IsDllsAllowed()==false)
{
Print("DLL?call?is?not?allowed.?Experts?cannot?run.");
return(0);
}
//?expert?body?that?calls?external?DLL?functions
MessageBoxA(0,"an?message","Message",MB_OK);
bool?IsLibrariesAllowed()
返回是否允許載入庫文件
示例:
#import?"somelibrary.ex4"
int?somefunc();
...
...
if(IsLibrariesAllowed()==false)
{
Print("Library?call?is?not?allowed.?Experts?cannot?run.");
return(0);
}
//?expert?body?that?calls?external?DLL?functions
somefunc();
bool?IsStopped()
返回是否處于停止狀態
示例:
while(expr!=false)
{
if(IsStopped()==true)?return(0);
//?long?time?procesing?cycle
//?...
}
bool?IsTesting()
返回是否處于測試模式
示例:
if(IsTesting())?Print("I?am?testing?now");
bool?IsTradeAllowed()
返回是否允許交易
示例:
if(IsTradeAllowed())?Print("Trade?allowed");
double?MarketInfo(?string?symbol,?int?type)
返回市場當前情況?
::?輸入參數
symbol?-?通貨代碼
type?-?返回結果的類型?
示例:
double?var;
var=MarketInfo("EURUSD",MODE_BID);
int?MessageBox(?string?text=NULL,?string?caption=NULL,?int?flags=EMPTY)?
彈出消息窗口,返回消息窗口的結果?
::?輸入參數
text?-?窗口顯示的文字
caption?-?窗口上顯示的標題
flags?-?窗口選項開關?
示例:
#include?
if(ObjectCreate("text_object",?OBJ_TEXT,?0,?D'2004.02.20?12:30',?1.0045)==false)
{
int?ret=MessageBox("ObjectCreate()?fails?with?code?"+GetLastError()+"\nContinue?",?"Question",?MB_YESNO|MB_ICONQUESTION);
if(ret==IDNO)?return(false);
}
//?continue
int?Period()
返回圖表時間線的類型
示例:
Print("Period?is?",?Period());
void?PlaySound(?string?filename)
播放音樂文件?
::?輸入參數
filename?-?音頻文件名?
示例:
if(IsDemo())?PlaySound("alert.wav");
void?Print(?...?)
將文本打印在結果窗口內?
::?輸入參數
...?-?任意值,復數用逗號分割?
示例:
Print("Account?free?margin?is?",?AccountFreeMargin());
Print("Current?time?is?",?TimeToStr(CurTime()));
double?pi=3.141592653589793;
Print("PI?number?is?",?DoubleToStr(pi,8));
//?Output:?PI?number?is?3.14159265
//?Array?printing
for(int?i=0;i<10;i++)
Print(Close[i]);
bool?RefreshRates()
返回數據是否已經被刷新過了
示例:
int?ticket;
while(true)
{
ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert?comment",255,0,CLR_NONE);
if(ticket<=0)
{
int?error=GetLastError();
if(error==134)?break;?//?not?enough?money
if(error==135)?RefreshRates();?//?prices?changed
break;
}
else?{?OrderPrint();?break;?}
//----?10?seconds?wait
Sleep(10000);
}
void?SendMail(?string?subject,?string?some_text)
發送郵件到指定信箱,需要到菜單?Tools?->?Options?->?Email?中將郵件打開.?
::?輸入參數
subject?-?郵件標題
some_text?-?郵件內容?
示例:
double?lastclose=Close[0];
if(lastclose<MY_SIGNAL)
SendMail("from?your?expert",?"Price?dropped?down?to?"+DoubleToStr(lastclose));
string?ServerAddress()
返回服務器地址
示例:
Print("Server?address?is?",?ServerAddress());
void?Sleep(?int?milliseconds)
設置線程暫停時間?
::?輸入參數
milliseconds?-?暫停時間?1000?=?1秒?
示例:
Sleep(5);
void?SpeechText(?string?text,?int?lang_mode=SPEECH_ENGLISH)
使用Speech進行語音輸出?
::?輸入參數
text?-?閱讀的文字
lang_mode?-?語音模式?SPEECH_ENGLISH?(默認的)?或?SPEECH_NATIVE?
示例:
double?lastclose=Close[0];
SpeechText("Price?dropped?down?to?"+DoubleToStr(lastclose));
string?Symbol()
返回當前當前通貨的名稱
示例:
int?total=OrdersTotal();
for(int?pos=0;pos<TOTAL;POS++)
{
//?check?selection?result?becouse?order?may?be?closed?or?deleted?at?this?time!
if(OrderSelect(pos,?SELECT_BY_POS)==false)?continue;
if(OrderType()>OP_SELL?||?OrderSymbol()!=Symbol())?continue;
//?do?some?orders?processing...
}
int?UninitializeReason()
取得程序末初始化的理由
示例:
//?this?is?example
int?deinit()
{
switch(UninitializeReason())
{
case?REASON_CHARTCLOSE:
case?REASON_REMOVE:?CleanUp();?break;?//?clean?up?and?free?all?expert's?resources.
case?REASON_RECOMPILE:
case?REASON_CHARTCHANGE:
case?REASON_PARAMETERS:
case?REASON_ACCOUNT:?StoreData();?break;?//?prepare?to?restart
}
//...
}
自定義指標函數?[Custom?Indicator?Functions]
void?IndicatorBuffers(int?count)
設置自定義指標緩存數
::?輸入參數
count?-?緩存數量?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
int?IndicatorCounted()
返回緩存數量
示例:
int?start()
{
int?limit;
int?counted_bars=IndicatorCounted();
//----?check?for?possible?errors
if(counted_bars<0)?return(-1);
//----?last?counted?bar?will?be?recounted
if(counted_bars>0)?counted_bars--;
limit=Bars-counted_bars;
//----?main?loop
for(int?i=0;?i
{
//----?ma_shift?set?to?0?because?SetIndexShift?called?abowe
ExtBlueBuffer[i]=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
ExtRedBuffer[i]=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
ExtLimeBuffer[i]=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
}
//----?done
return(0);
}
void?IndicatorDigits(?int?digits)
設置指標精確度?
::?輸入參數
digits?-?小數點后的小數位數?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
void?IndicatorShortName(?string?name)
設置指標的簡稱?
::?輸入參數
name?-?新的簡稱?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
void?SetIndexArrow(?int?index,?int?code)
在指標上設置一個箭頭符號?
::?輸入參數
index?-?第幾根指標線?0-7
code?-?符號的編碼,參照?Wingdings?字體?
示例:
SetIndexArrow(0,?217);
bool?SetIndexBuffer(?int?index,?double?array[])
設置指標線的緩存數組?
::?輸入參數
index?-?第幾根指標線?0-7
array[]?-?緩存的數組?
示例:
double?ExtBufferSilver[];
int?init()
{
SetIndexBuffer(0,?ExtBufferSilver);?//?set?buffer?for?first?line
//?...
}
void?SetIndexDrawBegin(?int?index,?int?begin)
設置劃線的開始點?
::?輸入參數
index?-?第幾根指標線?0-7
begin?-?劃線的開始點?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
void?SetIndexEmptyValue(?int?index,?double?value)?
設置劃線的空值,空值不劃在和出現在數據窗口?
::?輸入參數
index?-?第幾根指標線?0-7
value?-?新的空值?
示例:
SetIndexEmptyValue(6,0.0001);
void?SetIndexLabel(?int?index,?string?text)?
設置指標線的名稱?
::?輸入參數
index?-?第幾根指標線?0-7
text?-?線的名稱,Null不會顯示在數據窗口中?
示例:
//+------------------------------------------------------------------+
//|?Ichimoku?Kinko?Hyo?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Tenkan_Buffer);
SetIndexDrawBegin(0,Tenkan-1);
SetIndexLabel(0,"Tenkan?Sen");
//----
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Kijun_Buffer);
SetIndexDrawBegin(1,Kijun-1);
SetIndexLabel(1,"Kijun?Sen");
//----
a_begin=Kijun;?if(a_begin?SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT);
SetIndexBuffer(2,SpanA_Buffer);
SetIndexDrawBegin(2,Kijun+a_begin-1);
SetIndexShift(2,Kijun);
//----?Up?Kumo?bounding?line?does?not?show?in?the?DataWindow
SetIndexLabel(2,NULL);
SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(5,SpanA2_Buffer);
SetIndexDrawBegin(5,Kijun+a_begin-1);
SetIndexShift(5,Kijun);
SetIndexLabel(5,"Senkou?Span?A");
//----
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT);
SetIndexBuffer(3,SpanB_Buffer);
SetIndexDrawBegin(3,Kijun+Senkou-1);
SetIndexShift(3,Kijun);
//----?Down?Kumo?bounding?line?does?not?show?in?the?DataWindow
SetIndexLabel(3,NULL);
//----
SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(6,SpanB2_Buffer);
SetIndexDrawBegin(6,Kijun+Senkou-1);
SetIndexShift(6,Kijun);
SetIndexLabel(6,"Senkou?Span?B");
//----
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,Chinkou_Buffer);
SetIndexShift(4,-Kijun);
SetIndexLabel(4,"Chinkou?Span");
//----
return(0);
}
void?SetIndexShift(?int?index,?int?shift)
設置指標線的位移數?
::?輸入參數
index?-?第幾根指標線?0-7
shift?-?位移多少?
示例:
//+------------------------------------------------------------------+
//|?Alligator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?line?shifts?when?drawing
SetIndexShift(0,JawsShift);
SetIndexShift(1,TeethShift);
SetIndexShift(2,LipsShift);
//----?first?positions?skipped?when?drawing
SetIndexDrawBegin(0,JawsShift+JawsPeriod);
SetIndexDrawBegin(1,TeethShift+TeethPeriod);
SetIndexDrawBegin(2,LipsShift+LipsPeriod);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ExtBlueBuffer);
SetIndexBuffer(1,ExtRedBuffer);
SetIndexBuffer(2,ExtLimeBuffer);
//----?drawing?settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
//----?index?labels
SetIndexLabel(0,"Gator?Jaws");
SetIndexLabel(1,"Gator?Teeth");
SetIndexLabel(2,"Gator?Lips");
//----?initialization?done
return(0);
}
void?SetIndexStyle(?int?index,?int?type,?int?style=EMPTY,?int?width=EMPTY,?color?clr=CLR_NONE)?
設置指標線的樣式?
::?輸入參數
index?-?第幾根指標線?0-7
type?-?線形狀的種類,詳見線條種類
style?-?劃線的樣式
width?-?顯得寬度(1,2,3,4,5)
clr?-?線的顏色?
示例:
SetIndexStyle(3,?DRAW_LINE,?EMPTY,?2,?Red);
日期時間函數?[Date?&?Time?Functions]
datetime?CurTime(?)
返回當前時間
示例:
if(CurTime()-OrderOpenTime()<360)?return(0);
int?Day()
返回當前日期
示例:
if(Day()<5)?return(0);
int?DayOfWeek(?)
返回當前日期是星期幾?0-星期天,1,2,3,4,5,6
示例:
//?do?not?work?on?holidays.
if(DayOfWeek()==0?||?DayOfWeek()==6)?return(0);
int?DayOfYear(?)
返回當前日期在年內的第幾天
示例:
if(DayOfYear()==245)
return(true);
int?Hour()
返回當前的小時數?0-23
示例:
bool?is_siesta=false;
if(Hour()>=12?||?Hour()<17)
is_siesta=true;
datetime?LocalTime()
返回當前電腦時間
示例:
if(LocalTime()-OrderOpenTime()<360)?return(0);
int?Minute()
返回當前分鐘
示例:
if(Minute()<=15)
return("first?quarter");
int?Month()
返回當前月份
示例:
if(Month()<=5)
return("first?half?of?year");
int?Seconds()
返回當前秒數
示例:
if(Seconds()<=15)
return(0);
int?TimeDay(?datetime?date)
返回輸入日期中的日期?
::?輸入參數
date?-?輸入日期?
示例:
int?day=TimeDay(D'2003.12.31');
//?day?is?31
int?TimeDayOfWeek(?datetime?date)
返回輸入日期中的日期是星期幾?(0-6)?
::?輸入參數
date?-?輸入日期?
示例:
int?weekday=TimeDayOfWeek(D'2004.11.2');
//?day?is?2?-?tuesday
int?TimeDayOfYear(?datetime?date)
返回輸入日期中的日期在當年中的第幾天?
::?輸入參數
date?-?輸入日期?
示例:
int?day=TimeDayOfYear(CurTime());
int?TimeHour(?datetime?time)
返回輸入日期中的小時?
::?輸入參數
date?-?輸入日期?
示例:
int?h=TimeHour(CurTime());
int?TimeMinute(?datetime?time)
返回輸入日期中的分鐘?
::?輸入參數
date?-?輸入日期?
示例:
int?m=TimeMinute(CurTime());
int?TimeMonth(?datetime?time)
返回輸入日期中的月份?
::?輸入參數
date?-?輸入日期?
示例:
int?m=TimeMonth(CurTime());
int?TimeSeconds(?datetime?time)
返回輸入日期中的秒鐘?
::?輸入參數
date?-?輸入日期?
示例:
int?m=TimeSeconds(CurTime());
int?TimeYear(?datetime?time)
返回輸入日期中的年份?
::?輸入參數
date?-?輸入日期?
示例:
int?y=TimeYear(CurTime());
int?TimeYear(?datetime?time)
返回當前年份
示例:
//?return?if?date?before?1?May?2002
if(Year()==2002?&&?Month()<5)
return(0);
文件處理函數?[File?Functions]
void?FileClose(int?handle)
關閉正在已經打開的文件.
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle=FileOpen("filename",?FILE_CSV|FILE_READ);
if(handle>0)
{
//?working?with?file?...
FileClose(handle);
}
void?FileDelete(string?filename)
刪除文件,如果發生錯誤可以通過GetLastError()來查詢
注:你只能操作terminal_dir\experts\files目錄下的文件?
::?輸入參數
filename?-?目錄和文件名?
示例:
//?file?my_table.csv?will?be?deleted?from?terminal_dir\experts\files?directory
int?lastError;
FileDelete("my_table.csv");
lastError=GetLastError();
if(laseError!=ERR_NOERROR)
{
Print("An?error?ocurred?while?(",lastError,")?deleting?file?my_table.csv");
return(0);
}
void?FileFlush(int?handle)
將緩存中的數據刷新到磁盤上去?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?bars_count=Bars;
int?handle=FileOpen("mydat.csv",FILE_CSV|FILE_WRITE);
if(handle>0)
{
FileWrite(handle,?"#","OPEN","CLOSE","HIGH","LOW");
for(int?i=0;i<BARS_COUNT;I++)
FileWrite(handle,?i+1,Open[i],Close[i],High[i],?Low[i]);
FileFlush(handle);
...
for(int?i=0;i<BARS_COUNT;I++)
FileWrite(handle,?i+1,Open[i],Close[i],High[i],?Low[i]);
FileClose(handle);
}
bool?FileIsEnding(int?handle)
檢查是否到了文件尾.?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
if(FileIsEnding(h1))
{
FileClose(h1);
return(false);
}
bool?FileIsLineEnding(?int?handle)
檢查行是否到了結束?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
if(FileIsLineEnding(h1))
{
FileClose(h1);
return(false);
}
int?FileOpen(?string?filename,?int?mode,?int?delimiter=';')
打開文件,如果失敗返回值小于1,可以通過GetLastError()獲取錯誤
注:只能操作terminal_dir\experts\files目錄的文件?
::?輸入參數
filename?-?目錄文件名
mode?-?打開模式?FILE_BIN,?FILE_CSV,?FILE_READ,?FILE_WRITE.?
delimiter?-?CSV型打開模式用的分割符,默認為分號(;).?
示例:
int?handle;
handle=FileOpen("my_data.csv",FILE_CSV|FILE_READ,';');
if(handle<1)
{
Print("File?my_data.dat?not?found,?the?last?error?is?",?GetLastError());
return(false);
}
int?FileOpenHistory(?string?filename,?int?mode,?int?delimiter=';')
打開歷史數據文件,如果失敗返回值小于1,可以通過GetLastError()獲取錯誤?
::?輸入參數
filename?-?目錄文件名
mode?-?打開模式?FILE_BIN,?FILE_CSV,?FILE_READ,?FILE_WRITE.?
delimiter?-?CSV型打開模式用的分割符,默認為分號(;).?
示例:
int?handle=FileOpenHistory("USDX240.HST",FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("Cannot?create?file?USDX240.HST");
return(false);
}
//?work?with?file
//?...
FileClose(handle);
int?FileReadArray(?int?handle,?object&?array[],?int?start,?int?count)
將二進制文件讀取到數組中,返回讀取的條數,可以通過GetLastError()獲取錯誤
注:在讀取之前要調整好數組大小?
::?輸入參數
handle?-?FileOpen()返回的句柄
array[]?-?寫入的數組
start?-?在數組中存儲的開始點
count?-?讀取多少個對象?
示例:
int?handle;
double?varray[10];
handle=FileOpen("filename.dat",?FILE_BIN|FILE_READ);
if(handle>0)
{
FileReadArray(handle,?varray,?0,?10);
FileClose(handle);
}
double?FileReadDouble(?int?handle,?int?size=DOUBLE_VALUE)
從文件中讀取浮點型數據,數字可以是8byte的double型或者是4byte的float型。?
::?輸入參數
handle?-?FileOpen()返回的句柄
size?-?數字個是大小,DOUBLE_VALUE(8?bytes)?或者?FLOAT_VALUE(4?bytes).?
示例:
int?handle;
double?value;
handle=FileOpen("mydata.dat",FILE_BIN);
if(handle>0)
{
value=FileReadDouble(handle,DOUBLE_VALUE);
FileClose(handle);
}
int?FileReadInteger(?int?handle,?int?size=LONG_VALUE)
從文件中讀取整形型數據,數字可以是1,2,4byte的長度?
::?輸入參數
handle?-?FileOpen()返回的句柄
size?-?數字個是大小,CHAR_VALUE(1?byte),?SHORT_VALUE(2?bytes)?或者?LONG_VALUE(4?bytes).?
示例:
int?handle;
int?value;
handle=FileOpen("mydata.dat",?FILE_BIN|FILE_READ);
if(handle>0)
{
value=FileReadInteger(h1,2);
FileClose(handle);
}
double?FileReadNumber(?int?handle)
從文件中讀取數字,只能在CSV里使用?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle;
int?value;
handle=FileOpen("filename.csv",?FILE_CSV,?';');
if(handle>0)
{
value=FileReadNumber(handle);
FileClose(handle);
}
string?FileReadString(?int?handle,?int?length=0)
從文件中讀取字符串?
::?輸入參數
handle?-?FileOpen()返回的句柄
length?-?讀取字符串長度?
示例:
int?handle;
string?str;
handle=FileOpen("filename.csv",?FILE_CSV|FILE_READ);
if(handle>0)
{
str=FileReadString(handle);
FileClose(handle);
}
bool?FileSeek(?int?handle,?int?offset,?int?origin)
移動指針移動到某一點,如果成功返回true?
::?輸入參數
handle?-?FileOpen()返回的句柄
offset?-?設置的原點
origin?-?SEEK_CUR從當前位置開始?SEEK_SET從文件頭部開始?SEEK_END?從文件尾部開始?
示例:
int?handle=FileOpen("filename.csv",?FILE_CSV|FILE_READ,?';');
if(handle>0)
{
FileSeek(handle,?10,?SEEK_SET);
FileReadInteger(handle);
FileClose(handle);
handle=0;
}
int?FileSize(?int?handle)
返回文件大小?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle;
int?size;
handle=FileOpen("my_table.dat",?FILE_BIN|FILE_READ);
if(handle>0)
{
size=FileSize(handle);
Print("my_table.dat?size?is?",?size,?"?bytes");
FileClose(handle);
}
int?FileTell(?int?handle)
返回文件讀寫指針當前的位置?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle;
int?pos;
handle=FileOpen("my_table.dat",?FILE_BIN|FILE_READ);
//?reading?some?data
pos=FileTell(handle);
Print("current?position?is?",?pos);
int?FileWrite(?int?handle,?...?)
向文件寫入數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
...?-?寫入的數據?
示例:
int?handle;
datetime?orderOpen=OrderOpenTime();
handle=FileOpen("filename",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
FileWrite(handle,?Close[0],?Open[0],?High[0],?Low[0],?TimeToStr(orderOpen));
FileClose(handle);
}
int?FileWriteArray(?int?handle,?object?array[],?int?start,?int?count)
向文件寫入數組?
::?輸入參數
handle?-?FileOpen()返回的句柄
array[]?-?要寫入的數組
start?-?寫入的開始點
count?-?寫入的項目數?
示例:
int?handle;
double?BarOpenValues[10];
//?copy?first?ten?bars?to?the?array
for(int?i=0;i<10;?i++)
BarOpenValues[i]=Open[i];
//?writing?array?to?the?file
handle=FileOpen("mydata.dat",?FILE_BIN|FILE_WRITE);
if(handle>0)
{
FileWriteArray(handle,?BarOpenValues,?3,?7);?//?writing?last?7?elements
FileClose(handle);
}
int?FileWriteDouble(?int?handle,?double?value,?int?size=DOUBLE_VALUE)
向文件寫入浮點型數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
value?-?要寫入的值
size?-?寫入的格式,DOUBLE_VALUE?(8?bytes,?default)或FLOAT_VALUE?(4?bytes).?
示例:
int?handle;
double?var1=0.345;
handle=FileOpen("mydata.dat",?FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("can't?open?file?error-",GetLastError());
return(0);
}
FileWriteDouble(h1,?var1,?DOUBLE_VALUE);
//...
FileClose(handle);
int?FileWriteInteger(?int?handle,?int?value,?int?size=LONG_VALUE)
向文件寫入整型數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
value?-?要寫入的值
size?-?寫入的格式,CHAR_VALUE?(1?byte),SHORT_VALUE?(2?bytes),LONG_VALUE?(4?bytes,?default).?
示例:
int?handle;
int?value=10;
handle=FileOpen("filename.dat",?FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("can't?open?file?error-",GetLastError());
return(0);
}
FileWriteInteger(handle,?value,?SHORT_VALUE);
//...
FileClose(handle);
int?FileWriteString(?int?handle,?string?value,?int?length)
向文件寫入字符串數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
value?-?要寫入的值
length?-?寫入的字符長度?
示例:
int?handle;
string?str="some?string";
handle=FileOpen("filename.bin",?FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("can't?open?file?error-",GetLastError());
return(0);
}
FileWriteString(h1,?str,?8);
FileClose(handle);
全局變量函數?[Global?Variables?Functions]
bool?GlobalVariableCheck(?string?name)
檢查全局變量是否存在
::?輸入參數
name?-?全局變量的名稱?
示例:
//?check?variable?before?use
if(!GlobalVariableCheck("g1"))
GlobalVariableSet("g1",1);
bool?GlobalVariableDel(?string?name)?
刪除全局變量?
::?輸入參數
name?-?全局變量的名稱?
示例:
//?deleting?global?variable?with?name?"gvar_1"
GlobalVariableDel("gvar_1");
double?GlobalVariableGet(?string?name)
獲取全局變量的值?
::?輸入參數
name?-?全局變量的名稱?
示例:
double?v1=GlobalVariableGet("g1");
//----?check?function?call?result
if(GetLastError()!=0)?return(false);
//----?continue?processing
double?GlobalVariableGet(?string?name)
獲取全局變量的值?
::?輸入參數
name?-?全局變量的名稱?
示例:
double?v1=GlobalVariableGet("g1");
//----?check?function?call?result
if(GetLastError()!=0)?return(false);
//----?continue?processing
datetime?GlobalVariableSet(?string?name,?double?value?)
設置全局變量的值?
::?輸入參數
name?-?全局變量的名稱
value?-?全局變量的值?
示例:
//----?try?to?set?new?value
if(GlobalVariableSet("BarsTotal",Bars)==0)
return(false);
//----?continue?processing
bool?GlobalVariableSetOnCondition(?string?name,?double?value,?double?check_value)
有條件的設置全局變量的值?
::?輸入參數
name?-?全局變量的名稱
value?-?全局變量的值
check_value?-?檢查變量的值?
示例:
int?init()
{
//----?create?global?variable
GlobalVariableSet("DATAFILE_SEM",0);
//...
}?
int?start()
{
//----?try?to?lock?common?resource
while(!IsStopped())
{
//----?locking
if(GlobalVariableSetOnCondition("DATAFILE_SEM",1,0)==true)?break;
//----?may?be?variable?deleted?
if(GetLastError()==ERR_GLOBAL_VARIABLE_NOT_FOUND)?return(0);
//----?sleeping
Sleep(500);
}
//----?resource?locked
//?...?do?some?work
//----?unlock?resource
GlobalVariableSet("DATAFILE_SEM",0);
}
void?GlobalVariablesDeleteAll(?)?
刪除所有全局變量
示例:
GlobalVariablesDeleteAll();
數學運算函數?[Math?&?Trig]
double?MathAbs(?double?value)?
返回數字的絕對值
::?輸入參數
value?-?要處理的數字?
示例:
double?dx=-3.141593,?dy;
//?calc?MathAbs
dy=MathAbs(dx);
Print("The?absolute?value?of?",dx,"?is?",dy);
//?Output:?The?absolute?value?of?-3.141593?is?3.141593
double?MathArccos(?double?x)
計算反余弦值?
::?輸入參數
value?-?要處理的數字,范圍-1到1?
示例:
double?x=0.32696,?y;
y=asin(x);
Print("Arcsine?of?",x,"?=?",y);
y=acos(x);
Print("Arccosine?of?",x,"?=?",y);
//Output:?Arcsine?of?0.326960=0.333085
//Output:?Arccosine?of?0.326960=1.237711
double?MathArcsin(?double?x)?
計算反正弦值?
::?輸入參數
x?-?要處理的值?
示例:
double?x=0.32696,?y;
y=MathArcsin(x);
Print("Arcsine?of?",x,"?=?",y);
y=acos(x);
Print("Arccosine?of?",x,"?=?",y);
//Output:?Arcsine?of?0.326960=0.333085
//Output:?Arccosine?of?0.326960=1.237711
double?MathArctan(?double?x)
計算反正切值?
::?輸入參數
x?-?要處理的值?
示例:
double?x=-862.42,?y;
y=MathArctan(x);
Print("Arctangent?of?",x,"?is?",y);
//Output:?Arctangent?of?-862.42?is?-1.5696
double?MathCeil(?double?x)
返回向前進位后的值?
::?輸入參數
x?-?要處理的值?
示例:
double?y;
y=MathCeil(2.8);
Print("The?ceil?of?2.8?is?",y);
y=MathCeil(-2.8);
Print("The?ceil?of?-2.8?is?",y);
/*Output:
The?ceil?of?2.8?is?3
The?ceil?of?-2.8?is?-2*/
double?MathCos(?double?value)
計算余弦值?
::?輸入參數
value?-?要處理的值?
示例:
double?pi=3.1415926535;
double?x,?y;
x=pi/2;
y=MathSin(x);
Print("MathSin(",x,")?=?",y);
y=MathCos(x);
Print("MathCos(",x,")?=?",y);
//Output:?MathSin(1.5708)=1
//?MathCos(1.5708)=0
double?MathExp(?double?d)
Returns?value?the?number?e?raised?to?the?power?d.?On?overflow,?the?function?returns?INF?(infinite)?and?on?underflow,?MathExp?returns?0.?
::?輸入參數
d?-?A?number?specifying?a?power.?
示例:
double?x=2.302585093,y;
y=MathExp(x);
Print("MathExp(",x,")?=?",y);
//Output:?MathExp(2.3026)=10
double?MathFloor(?double?x)
返回向后進位后的值?
::?輸入參數
x?-?要處理的值?
示例:
double?y;
y=MathFloor(2.8);
Print("The?floor?of?2.8?is?",y);
y=MathFloor(-2.8);
Print("The?floor?of?-2.8?is?",y);
/*Output:
The?floor?of?2.8?is?2
The?floor?of?-2.8?is?-3*/
double?MathLog(?double?x)
計算對數?
::?輸入參數
x?-?要處理的值?
示例:
double?x=9000.0,y;
y=MathLog(x);
Print("MathLog(",x,")?=?",?y);
//Output:?MathLog(9000)=9.10498
double?MathMax(?double?value1,?double?value2)?
計算兩個值中的最大值?
::?輸入參數
value1?-?第一個值?
value2?-?第二個值?
示例:
double?result=MathMax(1.08,Bid);
double?MathMin(?double?value1,?double?value2)?
計算兩個值中的最小值?
::?輸入參數
value1?-?第一個值?
value2?-?第二個值?
示例:
double?result=MathMin(1.08,Ask);
double?MathMod(?double?value,?double?value2)?
計算兩個值相除的余數?
::?輸入參數
value?-?被除數?
value2?-?除數?
示例:
double?x=-10.0,y=3.0,z;
z=MathMod(x,y);
Print("The?remainder?of?",x,"?/?",y,"?is?",z);
//Output:?The?remainder?of?-10?/?3?is?-1
double?MathPow(?double?base,?double?exponent)
計算指數?
::?輸入參數
base?-?基數
exponent?-?指數?
示例:
double?x=2.0,y=3.0,z;
z=MathPow(x,y);
Printf(x,"?to?the?power?of?",y,"?is?",?z);
//Output:?2?to?the?power?of?3?is?8
int?MathRand(?)
取隨機數
示例:
MathSrand(LocalTime());
//?Display?10?numbers.
for(int?i=0;i<10;i++?)
Print("random?value?",?MathRand());
double?MathRound(?double?value)?
取四舍五入的值?
::?輸入參數
value?-?要處理的值?
示例:
double?y=MathRound(2.8);
Print("The?round?of?2.8?is?",y);
y=MathRound(2.4);
Print("The?round?of?-2.4?is?",y);
//Output:?The?round?of?2.8?is?3
//?The?round?of?-2.4?is?-2
double?MathSin(?double?value)
計算正弦數?
::?輸入參數
value?-?要處理的值?
示例:
double?pi=3.1415926535;
double?x,?y;
x=pi/2;
y=MathSin(x);
Print("MathSin(",x,")?=?",y);
y=MathCos(x);
Print("MathCos(",x,")?=?",y);
//Output:?MathSin(1.5708)=1
//?MathCos(1.5708)=0
double?MathSqrt(?double?x)
計算平方根?
::?輸入參數
x?-?要處理的值?
示例:
double?question=45.35,?answer;
answer=MathSqrt(question);
if(question<0)
Print("Error:?MathSqrt?returns?",answer,"?answer");
else
Print("The?square?root?of?",question,"?is?",?answer);
//Output:?The?square?root?of?45.35?is?6.73
void?MathSrand(?int?seed)
通過Seed產生隨機數?
::?輸入參數
seed?-?隨機數的種子?
示例:
MathSrand(LocalTime());
//?Display?10?numbers.
for(int?i=0;i<10;i++?)
Print("random?value?",?MathRand());
double?MathTan(?double?x)
計算正切值?
::?輸入參數
x?-?要計算的角度?
示例:
double?pi=3.1415926535;
double?x,y;
x=MathTan(pi/4);
Print("MathTan(",pi/4,"?=?",x);
//Output:?MathTan(0.7856)=1
物體函數?[Object?Functions]
bool?ObjectCreate(?string?name,?int?type,?int?window,?datetime?time1,?double?price1,?datetime?time2=0,?double?price2=0,?datetime?time3=0,?double?price3=0)
創建物件
::?輸入參數
name?-?物件名稱
type?-?物件類型.?
window?-?物件所在窗口的索引值
time1?-?時間點1
price1?-?價格點1
time2?-?時間點2
price2?-?價格點2
time3?-?時間點3
price3?-?價格點3?
示例:
//?new?text?object
if(!ObjectCreate("text_object",?OBJ_TEXT,?0,?D'2004.02.20?12:30',?1.0045))
{
Print("error:?can't?create?text_object!?code?#",GetLastError());
return(0);
}
//?new?label?object
if(!ObjectCreate("label_object",?OBJ_LABEL,?0,?0,?0))
{
Print("error:?can't?create?label_object!?code?#",GetLastError());
return(0);
}
ObjectSet("label_object",?OBJPROP_XDISTANCE,?200);
ObjectSet("label_object",?OBJPROP_YDISTANCE,?100);
bool?ObjectDelete(?string?name)?
刪除物件?
::?輸入參數
name?-?物件名稱?
示例:
ObjectDelete("text_object");
string?ObjectDescription(?string?name)?
返回物件描述?
::?輸入參數
name?-?物件名稱?
示例:
//?writing?chart's?object?list?to?the?file
int?handle,?total;
string?obj_name,fname;
//?file?name
fname="objlist_"+Symbol();
handle=FileOpen(fname,FILE_CSV|FILE_WRITE);
if(handle!=false)
{
total=ObjectsTotal();
for(int?i=-;i<TOTAL;I++)
{
obj_name=ObjectName(i);
FileWrite(handle,"Object?"+obj_name+"?description=?"+ObjectDescription(obj_name));
}
FileClose(handle);
}
int?ObjectFind(?string?name)?
尋找物件,返回物件的索引值?
::?輸入參數
name?-?物件名稱?
示例:
if(ObjectFind("line_object2")!=win_idx)?return(0);
double?ObjectGet(?string?name,?int?index)?
獲取物件的值?
::?輸入參數
name?-?物件名稱
index?-?取值屬性的索引?
示例:
color?oldColor=ObjectGet("hline12",?OBJPROP_COLOR);
string?ObjectGetFiboDescription(?string?name,?int?index)?
取物件的斐波納契數列地描述?
::?輸入參數
name?-?物件名稱
index?-?斐波納契數列的等級索引?
示例:
#include?
...
string?text;
for(int?i=0;i<32;i++)
{
text=ObjectGetFiboDescription(MyObjectName,i);
//----?check.?may?be?objects's?level?count?less?than?32
if(GetLastError()!=ERR_NO_ERROR)?break;
Print(MyObjectName,"level:?",i,"?description:?",text);
}
int?ObjectGetShiftByValue(?string?name,?double?value)?
取物件的位移值?
::?輸入參數
name?-?物件名稱
value?-?價格?
示例:
int?shift=ObjectGetShiftByValue("MyTrendLine#123",?1.34);
double?ObjectGetValueByShift(?string?name,?int?shift)?
取物件位移后的值?
::?輸入參數
name?-?物件名稱
shift?-?位移數?
示例:
double?price=ObjectGetValueByShift("MyTrendLine#123",?11);
bool?ObjectMove(?string?name,?int?point,?datetime?time1,?double?price1)?
移動物件?
::?輸入參數
name?-?物件名稱
point?-?調整的索引?
time1?-?新的時間?
price1?-?新的價格?
示例:
ObjectMove("MyTrend",?1,?D'2005.02.25?12:30',?1.2345);
string?ObjectName(?int?index)?
取物件名稱?
::?輸入參數
index?-?物件的索引?
示例:
int?obj_total=ObjectsTotal();
string?name;
for(int?i=0;i<OBJ_TOTAL;I++)
{
name=ObjectName(i);
Print(i,"Object?name?is?"?+?name);
}
int?ObjectsDeleteAll(?int?window,?int?type=EMPTY)?
刪除所有物件?
::?輸入參數
window?-?物件所在的窗口索引
type?-?刪除物件的類型?
示例:
ObjectsDeleteAll(2,?OBJ_HLINE);?//?removes?all?horizontal?line?objects?from?window?3?(index?2).
bool?ObjectSet(?string?name,?int?index,?double?value)?
設置物件的值?
::?輸入參數
name?-?物件的名稱
index?-?物件屬性的索引值?
value?-?新的屬性值?
示例:
//?moving?first?coord?to?last?bar?time
ObjectSet("MyTrend",?OBJPROP_TIME1,?Time[0]);
//?setting?second?fibo?level
ObjectSet("MyFibo",?OBJPROP_FIRSTLEVEL+1,?1.234);
//?setting?object?visibility.?object?will?be?shown?only?on?15?minute?and?1?hour?charts
ObjectSet("MyObject",?OBJPROP_TIMEFRAMES,?OBJ_PERIOD_M15?|?OBJ_PERIOD_H1);
bool?ObjectSetFiboDescription(?string?name,?int?index,?string?text)?
設置物件斐波納契數列的描述?
::?輸入參數
name?-?物件的名稱
index?-?物件斐波納契數列的索引值?
text?-?新的描述?
示例:
ObjectSetFiboDescription("MyFiboObject,2,"Second?line");
bool?ObjectSetText(?string?name,?string?text,?int?font_size,?string?font=NULL,?color?text_color=CLR_NONE)?
設置物件的描述?
::?輸入參數
name?-?物件的名稱
text?-?文本
font_size?-?字體大小?
font?-?字體名稱?
text_color?-?字體顏色?
示例:
ObjectSetText("text_object",?"Hello?world!",?10,?"Times?New?Roman",?Green);
void?ObjectsRedraw(?)?
重繪所有物件
示例:
ObjectsRedraw();
int?ObjectsTotal(?)?
取物件總數
示例:
int?obj_total=ObjectsTotal();
string?name;
for(int?i=0;i<OBJ_TOTAL;I++)
{
name=ObjectName(i);
Print(i,"Object?name?is?for?object?#",i,"?is?"?+?name);
}
int?ObjectType(?string?name)?
取物件類型?
::?輸入參數
name?-?物件的名稱?
示例:
if(ObjectType("line_object2")!=OBJ_HLINE)?return(0);
預定義變量?[Pre-defined?Variables]?
double?Ask
通貨的買入價
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,
"My?order?#2",3,D'2005.10.10?12:30',Red);
return;
}
int?Bars
返回圖表中的柱數
示例:
int?counter=1;
for(int?i=1;i<=Bars;i++)
{
Print(Close[i-1]);
}
double?Bid
通貨的賣價
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderSend("EURUSD",OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,
"My?order?#2",3,D'2005.10.10?12:30',Red);
return(0);
}
double?Close[]
返回指定索引位置的收盤價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",FILE_CSV|FILE_WRITE,';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
int?Digits
返回當前通貨的匯率小數位
示例:
Print(DoubleToStr(Close[i-1],?Digits));
double?High[]
返回指定索引位置的最高價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Low[]
返回指定索引位置的最低價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?";");
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Open[]
返回指定索引位置的開盤價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Point
返回當前圖表的點值
示例:
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,Red);
datetime?Time[]
返回指定索引位置的時間
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Volume[]
返回指定索引位置的成交量
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?erite?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
)
字符串函數?[String?Functions]
string?StringConcatenate(?...?)?
字符串連接
::?輸入參數
...?-?任意值,用逗號分割?
示例:
string?text;
text=StringConcatenate("Account?free?margin?is?",?AccountFreeMargin(),?"Current?time?is?",?TimeToStr(CurTime()));
//?slow?text="Account?free?margin?is?"?+?AccountFreeMargin()?+?"Current?time?is?"?+?TimeToStr(CurTime())
Print(text);
int?StringFind(?string?text,?string?matched_text,?int?start=0)
在字符串中尋找符合條件的字符串返回索引位置?
::?輸入參數
text?-?被搜索的字符串?
matched_text?-?需要搜索的字符串
start?-?搜索開始索引位置?
示例:
string?text="The?quick?brown?dog?jumps?over?the?lazy?fox";
int?index=StringFind(text,?"dog?jumps",?0);
if(index!=16)
Print("oops!");
int?StringGetChar(?string?text,?int?pos)?
取字符串中的某一個字符?
::?輸入參數
text?-?字符串?
pos?-?取字符的位置?
示例:
int?char_code=StringGetChar("abcdefgh",?3);
//?char?code?'c'?is?99
int?StringLen(?string?text)?
返回字符串長度?
::?輸入參數
text?-?字符串?
示例:
string?str="some?text";
if(StringLen(str)<5)?return(0);
string?StringSetChar(?string?text,?int?pos,?int?value)?
在字符串中設置一個字符?
::?輸入參數
text?-?字符串?
pos?-?設置字符的位置
value?-?新的字符?
示例:
string?str="abcdefgh";
string?str1=StringSetChar(str,?3,?'D');
//?str1?is?"abcDefgh"
string?StringSubstr(?string?text,?int?start,?int?count=EMPTY)?
從字符串中截取一段字符串?
::?輸入參數
text?-?字符串?
start?-?開始索引位置
count?-?截取字符數?
示例:
string?text="The?quick?brown?dog?jumps?over?the?lazy?fox";
string?substr=StringSubstr(text,?4,?5);
//?subtracted?string?is?"quick"?word
string?StringTrimLeft(?string?text)?
字符串左側去空格?
::?輸入參數
text?-?字符串?
示例:
string?str1="?Hello?world?";
string?str2=StringTrimLeft(str);
//?after?trimming?the?str2?variable?will?be?"Hello?World?"
string?StringTrimRight(?string?text)
字符串右側去空格?
::?輸入參數
text?-?字符串?
示例:
string?str1="?Hello?world?";
string?str2=StringTrimRight(str);
//?after?trimming?the?str2?variable?will?be?"?Hello?World"
標準常量?[Standard?Constants]?
Applied?price?enumeration
價格類型枚舉
示例:
Constant Value Description
PRICE_CLOSE? 0? 收盤價
PRICE_OPEN? 1? 開盤價
PRICE_HIGH? 2? 最高價
PRICE_LOW? 3? 最低價
PRICE_MEDIAN? 4? 最高價和最低價的平均價
PRICE_TYPICAL? 5? 最高價、最低價和收盤價的平均價
PRICE_WEIGHTED? 6? 開、收盤價和最高最低價的平均價
Drawing?shape?style?enumeration
畫圖形狀樣式枚舉,
形狀:
Constant Value Description
DRAW_LINE? 0? Drawing?line.?
DRAW_SECTION? 1? Drawing?sections.?
DRAW_HISTOGRAM? 2? Drawing?histogram.?
DRAW_ARROW? 3? Drawing?arrows?(symbols).?
DRAW_NONE? 12? No?drawing.?
樣式:
Constant Value Description
STYLE_SOLID? 0? The?pen?is?solid.?
STYLE_DASH? 1? The?pen?is?dashed.?
STYLE_DOT? 2? The?pen?is?dotted.?
STYLE_DASHDOT? 3? The?pen?has?alternating?dashes?and?dots.?
STYLE_DASHDOTDOT? 4? The?pen?has?alternating?dashes?and?double?dots.?
Error?codes
錯誤代碼,使用GetLastError()可返回錯誤代碼,錯誤代碼定義在stderror.mqh文件里,可以使用ErrorDescription()取得說明
#include?
void?SendMyMessage(string?text)
{
int?check;
SendMail("some?subject",?text);
check=GetLastError();
if(check!=ERR_NO_MQLERROR)?Print("Cannot?send?message,?error:?",ErrorDescription(check));
}
交易服務器返回的錯誤:?
Constant Value Description
ERR_NO_ERROR? 0? No?error?returned.?
ERR_NO_RESULT? 1? No?error?returned,?but?the?result?is?unknown.?
ERR_COMMON_ERROR? 2? Common?error.?
ERR_INVALID_TRADE_PARAMETERS? 3? Invalid?trade?parameters.?
ERR_SERVER_BUSY? 4? Trade?server?is?busy.?
ERR_OLD_VERSION? 5? Old?version?of?the?client?terminal.?
ERR_NO_CONNECTION? 6? No?connection?with?trade?server.?
ERR_NOT_ENOUGH_RIGHTS? 7? Not?enough?rights.?
ERR_TOO_FREQUENT_REQUESTS? 8? Too?frequent?requests.?
ERR_MALFUNCTIONAL_TRADE? 9? Malfunctional?trade?operation.?
ERR_ACCOUNT_DISABLED? 64? Account?disabled.?
ERR_INVALID_ACCOUNT? 65? Invalid?account.?
ERR_TRADE_TIMEOUT? 128? Trade?timeout.?
ERR_INVALID_PRICE? 129? Invalid?price.?
ERR_INVALID_STOPS? 130? Invalid?stops.?
ERR_INVALID_TRADE_VOLUME? 131? Invalid?trade?volume.?
ERR_MARKET_CLOSED? 132? Market?is?closed.?
ERR_TRADE_DISABLED? 133? Trade?is?disabled.?
ERR_NOT_ENOUGH_MONEY? 134? Not?enough?money.?
ERR_PRICE_CHANGED? 135? Price?changed.?
ERR_OFF_QUOTES? 136? Off?quotes.?
ERR_BROKER_BUSY? 137? Broker?is?busy.?
ERR_REQUOTE? 138? Requote.?
ERR_ORDER_LOCKED? 139? Order?is?locked.?
ERR_LONG_POSITIONS_ONLY_ALLOWED? 140? Long?positions?only?allowed.?
ERR_TOO_MANY_REQUESTS? 141? Too?many?requests.?
ERR_TRADE_MODIFY_DENIED? 145? Modification?denied?because?order?too?close?to?market.?
ERR_TRADE_CONTEXT_BUSY? 146? Trade?context?is?busy.?
MT4返回的運行錯誤:
Constant Value Description
ERR_NO_MQLERROR? 4000? No?error.?
ERR_WRONG_FUNCTION_POINTER? 4001? Wrong?function?pointer.?
ERR_ARRAY_INDEX_OUT_OF_RANGE? 4002? Array?index?is?out?of?range.?
ERR_NO_MEMORY_FOR_FUNCTION_CALL_STACK? 4003? No?memory?for?function?call?stack.?
ERR_RECURSIVE_STACK_OVERFLOW? 4004? Recursive?stack?overflow.?
ERR_NOT_ENOUGH_STACK_FOR_PARAMETER? 4005? Not?enough?stack?for?parameter.?
ERR_NO_MEMORY_FOR_PARAMETER_STRING? 4006? No?memory?for?parameter?string.?
ERR_NO_MEMORY_FOR_TEMP_STRING? 4007? No?memory?for?temp?string.?
ERR_NOT_INITIALIZED_STRING? 4008? Not?initialized?string.?
ERR_NOT_INITIALIZED_ARRAYSTRING? 4009? Not?initialized?string?in?array.?
ERR_NO_MEMORY_FOR_ARRAYSTRING? 4010? No?memory?for?array?string.?
ERR_TOO_LONG_STRING? 4011? Too?long?string.?
ERR_REMAINDER_FROM_ZERO_DIVIDE? 4012? Remainder?from?zero?divide.?
ERR_ZERO_DIVIDE? 4013? Zero?divide.?
ERR_UNKNOWN_COMMAND? 4014? Unknown?command.?
ERR_WRONG_JUMP? 4015? Wrong?jump?(never?generated?error).?
ERR_NOT_INITIALIZED_ARRAY? 4016? Not?initialized?array.?
ERR_DLL_CALLS_NOT_ALLOWED? 4017? DLL?calls?are?not?allowed.?
ERR_CANNOT_LOAD_LIBRARY? 4018? Cannot?load?library.?
ERR_CANNOT_CALL_FUNCTION? 4019? Cannot?call?function.?
ERR_EXTERNAL_EXPERT_CALLS_NOT_ALLOWED? 4020? Expert?function?calls?are?not?allowed.?
ERR_NOT_ENOUGH_MEMORY_FOR_RETURNED_STRING? 4021? Not?enough?memory?for?temp?string?returned?from?function.?
ERR_SYSTEM_BUSY? 4022? System?is?busy?(never?generated?error).?
ERR_INVALID_FUNCTION_PARAMETERS_COUNT? 4050? Invalid?function?parameters?count.?
ERR_INVALID_FUNCTION_PARAMETER_VALUE? 4051? Invalid?function?parameter?value.?
ERR_STRING_FUNCTION_INTERNAL_ERROR? 4052? String?function?internal?error.?
ERR_SOME_ARRAY_ERROR? 4053? Some?array?error.?
ERR_INCORRECT_SERIES_ARRAY_USING? 4054? Incorrect?series?array?using.?
ERR_CUSTOM_INDICATOR_ERROR? 4055? Custom?indicator?error.?
ERR_INCOMPATIBLE_ARRAYS? 4056? Arrays?are?incompatible.?
ERR_GLOBAL_VARIABLES_PROCESSING_ERROR? 4057? Global?variables?processing?error.?
ERR_GLOBAL_VARIABLE_NOT_FOUND? 4058? Global?variable?not?found.?
ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE? 4059? Function?is?not?allowed?in?testing?mode.?
ERR_FUNCTION_NOT_CONFIRMED? 4060? Function?is?not?confirmed.?
ERR_SEND_MAIL_ERROR? 4061? Send?mail?error.?
ERR_STRING_PARAMETER_EXPECTED? 4062? String?parameter?expected.?
ERR_INTEGER_PARAMETER_EXPECTED? 4063? Integer?parameter?expected.?
ERR_DOUBLE_PARAMETER_EXPECTED? 4064? Double?parameter?expected.?
ERR_ARRAY_AS_PARAMETER_EXPECTED? 4065? Array?as?parameter?expected.?
ERR_HISTORY_WILL_UPDATED? 4066? Requested?history?data?in?updating?state.?
ERR_END_OF_FILE? 4099? End?of?file.?
ERR_SOME_FILE_ERROR? 4100? Some?file?error.?
ERR_WRONG_FILE_NAME? 4101? Wrong?file?name.?
ERR_TOO_MANY_OPENED_FILES? 4102? Too?many?opened?files.?
ERR_CANNOT_OPEN_FILE? 4103? Cannot?open?file.?
ERR_INCOMPATIBLE_ACCESS_TO_FILE? 4104? Incompatible?access?to?a?file.?
ERR_NO_ORDER_SELECTED? 4105? No?order?selected.?
ERR_UNKNOWN_SYMBOL? 4106? Unknown?symbol.?
ERR_INVALID_PRICE_PARAM? 4107? Invalid?price.?
ERR_INVALID_TICKET? 4108? Invalid?ticket.?
ERR_TRADE_NOT_ALLOWED? 4109? Trade?is?not?allowed.?
ERR_LONGS__NOT_ALLOWED? 4110? Longs?are?not?allowed.?
ERR_SHORTS_NOT_ALLOWED? 4111? Shorts?are?not?allowed.?
ERR_OBJECT_ALREADY_EXISTS? 4200? Object?exists?already.?
ERR_UNKNOWN_OBJECT_PROPERTY? 4201? Unknown?object?property.?
ERR_OBJECT_DOES_NOT_EXIST? 4202? Object?does?not?exist.?
ERR_UNKNOWN_OBJECT_TYPE? 4203? Unknown?object?type.?
ERR_NO_OBJECT_NAME? 4204? No?object?name.?
ERR_OBJECT_COORDINATES_ERROR? 4205? Object?coordinates?error.?
ERR_NO_SPECIFIED_SUBWINDOW? 4206? No?specified?subwindow.?
Ichimoku?Kinko?Hyo?modes?enumeration
Ichimoku指標模式枚舉
Constant Value Description
MODE_TENKANSEN? 1? Tenkan-sen.?
MODE_KIJUNSEN? 2? Kijun-sen.?
MODE_SENKOUSPANA? 3? Senkou?Span?A.?
MODE_SENKOUSPANB? 4? Senkou?Span?B.?
MODE_CHINKOUSPAN? 5? Chinkou?Span.?
Indicators?line?identifiers
指標線標示符
指標線模式,使用在?iMACD(),?iRVI()?和?iStochastic()?中:
Constant Value Description
MODE_MAIN? 0? Base?indicator?line.?
MODE_SIGNAL? 1? Signal?line.?
指標線模式,使用在?iADX()?中:
Constant Value Description
MODE_MAIN? 0? Base?indicator?line.?
MODE_PLUSDI? 1? +DI?indicator?line.?
MODE_MINUSDI? 2? -DI?indicator?line.?
指標線模式,使用在?iBands(),?iEnvelopes(),?iEnvelopesOnArray(),?iFractals()?and?iGator()?中:
Constant Value Description
MODE_UPPER? 1? Upper?line.?
MODE_LOWER? 2? Lower?line.?
Market?information?identifiers
市場信息標識
Constant Value Description
MODE_LOW? 1? Low?day?price.?
MODE_HIGH? 2? High?day?price.?
MODE_TIME? 5? The?last?incoming?quotation?time.?
MODE_BID? 9? Last?incoming?bid?price.?
MODE_ASK? 10? Last?incoming?ask?price.?
MODE_POINT? 11? Point?size.?
MODE_DIGITS? 12? Digits?after?decimal?point.?
MODE_SPREAD? 13? Spread?value?in?points.?
MODE_STOPLEVEL? 14? Stop?level?in?points.?
MODE_LOTSIZE? 15? Lot?size?in?the?base?currency.?
MODE_TICKVALUE? 16? Tick?value.?
MODE_TICKSIZE? 17? Tick?size.?
MODE_SWAPLONG? 18? Swap?of?the?long?position.?
MODE_SWAPSHORT? 19? Swap?of?the?short?position.?
MODE_STARTING? 20? Market?starting?date?(usually?used?for?future?markets).?
MODE_EXPIRATION? 21? Market?expiration?date?(usually?used?for?future?markets).?
MODE_TRADEALLOWED? 22? Trade?is?allowed?for?the?symbol.?
MessageBox?return?codes
消息窗口返回值
Constant Value Description
IDOK? 1? OK?button?was?selected.?
IDCANCEL? 2? Cancel?button?was?selected.?
IDABORT? 3? Abort?button?was?selected.?
IDRETRY? 4? Retry?button?was?selected.?
IDIGNORE? 5? Ignore?button?was?selected.?
IDYES? 6? Yes?button?was?selected.?
IDNO? 7? No?button?was?selected.?
IDTRYAGAIN? 10? Try?Again?button?was?selected.?
IDCONTINUE? 11? Continue?button?was?selected.?
MessageBox?behavior?flags
消息窗口行為代碼
消息窗口顯示的按鈕種類:
Constant Value Description
MB_OK? 0x00000000? The?message?box?contains?one?push?button:?OK.?This?is?the?default.?
MB_OKCANCEL? 0x00000001? The?message?box?contains?two?push?buttons:?OK?and?Cancel.?
MB_ABORTRETRYIGNORE? 0x00000002? The?message?box?contains?three?push?buttons:?Abort,?Retry,?and?Ignore.?
MB_YESNOCANCEL? 0x00000003? The?message?box?contains?three?push?buttons:?Yes,?No,?and?Cancel.?
MB_YESNO? 0x00000004? The?message?box?contains?two?push?buttons:?Yes?and?No.?
MB_RETRYCANCEL? 0x00000005? The?message?box?contains?two?push?buttons:?Retry?and?Cancel.?
MB_CANCELTRYCONTINUE? 0x00000006? Windows?2000:?The?message?box?contains?three?push?buttons:?Cancel,?Try?Again,?Continue.?Use?this?message?box?type?instead?of?MB_ABORTRETRYIGNORE.?
消息窗口顯示圖標的類型:
Constant Value Description
MB_ICONSTOP,?MB_ICONERROR,?MB_ICONHAND? 0x00000010? A?stop-sign?icon?appears?in?the?message?box.?
MB_ICONQUESTION? 0x00000020? A?question-mark?icon?appears?in?the?message?box.?
MB_ICONEXCLAMATION,?MB_ICONWARNING? 0x00000030? An?exclamation-point?icon?appears?in?the?message?box.?
MB_ICONINFORMATION,?MB_ICONASTERISK? 0x00000040? An?icon?consisting?of?a?lowercase?letter?i?in?a?circle?appears?in?the?message?box.?
消息窗口默認按鈕設置:
Constant Value Description
MB_DEFBUTTON1? 0x00000000? The?first?button?is?the?default?button.?MB_DEFBUTTON1?is?the?default?unless?MB_DEFBUTTON2,?MB_DEFBUTTON3,?or?MB_DEFBUTTON4?is?specified.?
MB_DEFBUTTON2? 0x00000100? The?second?button?is?the?default?button.?
MB_DEFBUTTON3? 0x00000200? The?third?button?is?the?default?button.?
MB_DEFBUTTON4? 0x00000300? The?fourth?button?is?the?default?button.?
Moving?Average?method?enumeration
移動平均線模式枚舉,iAlligator(),?iEnvelopes(),?iEnvelopesOnArray,?iForce(),?iGator(),?iMA(),?iMAOnArray(),?iStdDev(),?iStdDevOnArray(),?iStochastic()這些會調用此枚舉
Constant Value Description
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.?
Object?properties?enumeration
物件屬性枚舉
Constant Value Description
OBJPROP_TIME1? 0? Datetime?value?to?set/get?first?coordinate?time?part.?
OBJPROP_PRICE1? 1? Double?value?to?set/get?first?coordinate?price?part.?
OBJPROP_TIME2? 2? Datetime?value?to?set/get?second?coordinate?time?part.?
OBJPROP_PRICE2? 3? Double?value?to?set/get?second?coordinate?price?part.?
OBJPROP_TIME3? 4? Datetime?value?to?set/get?third?coordinate?time?part.?
OBJPROP_PRICE3? 5? Double?value?to?set/get?third?coordinate?price?part.?
OBJPROP_COLOR? 6? Color?value?to?set/get?object?color.?
OBJPROP_STYLE? 7? Value?is?one?of?STYLE_SOLID,?STYLE_DASH,?STYLE_DOT,?STYLE_DASHDOT,?STYLE_DASHDOTDOT?constants?to?set/get?object?line?style.?
OBJPROP_WIDTH? 8? Integer?value?to?set/get?object?line?width.?Can?be?from?1?to?5.?
OBJPROP_BACK? 9? Boolean?value?to?set/get?background?drawing?flag?for?object.?
OBJPROP_RAY? 10? Boolean?value?to?set/get?ray?flag?of?object.?
OBJPROP_ELLIPSE? 11? Boolean?value?to?set/get?ellipse?flag?for?fibo?arcs.?
OBJPROP_SCALE? 12? Double?value?to?set/get?scale?object?property.?
OBJPROP_ANGLE? 13? Double?value?to?set/get?angle?object?property?in?degrees.?
OBJPROP_ARROWCODE? 14? Integer?value?or?arrow?enumeration?to?set/get?arrow?code?object?property.?
OBJPROP_TIMEFRAMES? 15? Value?can?be?one?or?combination?(bitwise?addition)?of?object?visibility?constants?to?set/get?timeframe?object?property.?
OBJPROP_DEVIATION? 16? Double?value?to?set/get?deviation?property?for?Standard?deviation?objects.?
OBJPROP_FONTSIZE? 100? Integer?value?to?set/get?font?size?for?text?objects.?
OBJPROP_CORNER? 101? Integer?value?to?set/get?anchor?corner?property?for?label?objects.?Must?be?from?0-3.?
OBJPROP_XDISTANCE? 102? Integer?value?to?set/get?anchor?X?distance?object?property?in?pixels.?
OBJPROP_YDISTANCE? 103? Integer?value?is?to?set/get?anchor?Y?distance?object?property?in?pixels.?
OBJPROP_FIBOLEVELS? 200? Integer?value?to?set/get?Fibonacci?object?level?count.?Can?be?from?0?to?32.?
OBJPROP_FIRSTLEVEL+?n? 210? Fibonacci?object?level?index,?where?n?is?level?index?to?set/get.?Can?be?from?0?to?31.?
Object?type?enumeration
物件類型枚舉
Constant Value Description
OBJ_VLINE? 0? Vertical?line.?Uses?time?part?of?first?coordinate.?
OBJ_HLINE? 1? Horizontal?line.?Uses?price?part?of?first?coordinate.?
OBJ_TREND? 2? Trend?line.?Uses?2?coordinates.?
OBJ_TRENDBYANGLE? 3? Trend?by?angle.?Uses?1?coordinate.?To?set?angle?of?line?use?ObjectSet()?function.?
OBJ_REGRESSION? 4? Regression.?Uses?time?parts?of?first?two?coordinates.?
OBJ_CHANNEL? 5? Channel.?Uses?3?coordinates.?
OBJ_STDDEVCHANNEL? 6? Standard?deviation?channel.?Uses?time?parts?of?first?two?coordinates.?
OBJ_GANNLINE? 7? Gann?line.?Uses?2?coordinate,?but?price?part?of?second?coordinate?ignored.?
OBJ_GANNFAN? 8? Gann?fan.?Uses?2?coordinate,?but?price?part?of?second?coordinate?ignored.?
OBJ_GANNGRID? 9? Gann?grid.?Uses?2?coordinate,?but?price?part?of?second?coordinate?ignored.?
OBJ_FIBO? 10? Fibonacci?retracement.?Uses?2?coordinates.?
OBJ_FIBOTIMES? 11? Fibonacci?time?zones.?Uses?2?coordinates.?
OBJ_FIBOFAN? 12? Fibonacci?fan.?Uses?2?coordinates.?
OBJ_FIBOARC? 13? Fibonacci?arcs.?Uses?2?coordinates.?
OBJ_EXPANSION? 14? Fibonacci?expansions.?Uses?3?coordinates.?
OBJ_FIBOCHANNEL? 15? Fibonacci?channel.?Uses?3?coordinates.?
OBJ_RECTANGLE? 16? Rectangle.?Uses?2?coordinates.?
OBJ_TRIANGLE? 17? Triangle.?Uses?3?coordinates.?
OBJ_ELLIPSE? 18? Ellipse.?Uses?2?coordinates.?
OBJ_PITCHFORK? 19? Andrews?pitchfork.?Uses?3?coordinates.?
OBJ_CYCLES? 20? Cycles.?Uses?2?coordinates.?
OBJ_TEXT? 21? Text.?Uses?1?coordinate.?
OBJ_ARROW? 22? Arrows.?Uses?1?coordinate.?
OBJ_LABEL? 23? Text?label.?Uses?1?coordinate?in?pixels.?
Object?visibility?enumeration
物件顯示枚舉
Constant Value Description
OBJ_PERIOD_M1? 0x0001? Object?shown?is?only?on?1-minute?charts.?
OBJ_PERIOD_M5? 0x0002? Object?shown?is?only?on?5-minute?charts.?
OBJ_PERIOD_M15? 0x0004? Object?shown?is?only?on?15-minute?charts.?
OBJ_PERIOD_M30? 0x0008? Object?shown?is?only?on?30-minute?charts.?
OBJ_PERIOD_H1? 0x0010? Object?shown?is?only?on?1-hour?charts.?
OBJ_PERIOD_H4? 0x0020? Object?shown?is?only?on?4-hour?charts.?
OBJ_PERIOD_D1? 0x0040? Object?shown?is?only?on?daily?charts.?
OBJ_PERIOD_W1? 0x0080? Object?shown?is?only?on?weekly?charts.?
OBJ_PERIOD_MN1? 0x0100? Object?shown?is?only?on?monthly?charts.?
OBJ_ALL_PERIODS? 0x01FF? Object?shown?is?on?all?timeframes.?
NULL? 0? Object?shown?is?on?all?timeframes.?
EMPTY? -1? Hidden?object?on?all?timeframes.?
Predefined?Arrow?codes?enumeration
預定義箭頭代碼枚舉
Constant Value Description
SYMBOL_THUMBSUP? 67? Thumb?up?symbol?(?C?).?
SYMBOL_THUMBSDOWN? 68? Thumb?down?symbol?(?D?).?
SYMBOL_ARROWUP? 241? Arrow?up?symbol?(???).?
SYMBOL_ARROWDOWN? 242? Arrow?down?symbol?(?ò?).?
SYMBOL_STOPSIGN? 251? Stop?sign?symbol?(???).?
SYMBOL_CHECKSIGN? 252? Check?sign?symbol?(?ü?).?
Constant Value Description
1? Upwards?arrow?with?tip?rightwards?(???).?
2? Downwards?arrow?with?tip?rightwards?(???).?
3? Left?pointing?triangle?(???).?
4? En?Dash?symbol?(–).?
SYMBOL_LEFTPRICE? 5? Left?sided?price?label.?
SYMBOL_RIGHTPRICE? 6? Right?sided?price?label.?
Series?array?identifier
系列數組標識符
Constant Value Description
MODE_OPEN? 0? Open?price.?
MODE_LOW? 1? Low?price.?
MODE_HIGH? 2? High?price.?
MODE_CLOSE? 3? Close?price.?
MODE_VOLUME? 4? Volume,?used?in?Lowest()?and?Highest()?functions.?
MODE_TIME? 5? Bar?open?time,?used?in?ArrayCopySeries()?function.?
Special?constants
特殊常量
Constant Value Description
NULL? 0? Indicates?empty?state?of?the?string.?
EMPTY? -1? Indicates?empty?state?of?the?parameter.?
EMPTY_VALUE? 0x7FFFFFFF? Default?custom?indicator?empty?value.?
CLR_NONE? 0xFFFFFFFF? Indicates?empty?state?of?colors.?
WHOLE_ARRAY? 0? Used?with?array?functions.?Indicates?that?all?array?elements?will?be?processed.?
Time?frame?enumeration
特殊常量
Constant Value Description
PERIOD_M1? 1? 1?minute.?
PERIOD_M5? 5? 5?minutes.?
PERIOD_M15? 15? 15?minutes.?
PERIOD_M30? 30? 30?minutes.?
PERIOD_H1? 60? 1?hour.?
PERIOD_H4? 240? 4?hour.?
PERIOD_D1? 1440? Daily.?
PERIOD_W1? 10080? Weekly.?
PERIOD_MN1? 43200? Monthly.?
0?(zero)? 0? Time?frame?used?on?the?chart.?
Trade?operation?enumeration
交易類型
Constant Value Description
OP_BUY? 0? Buying?position.?
OP_SELL? 1? Selling?position.?
OP_BUYLIMIT? 2? Buy?limit?pending?position.?
OP_SELLLIMIT? 3? Sell?limit?pending?position.?
OP_BUYSTOP? 4? Buy?stop?pending?position.?
OP_SELLSTOP? 5? Sell?stop?pending?position.?
Uninitialize?reason?codes
末初始化理由代碼
Constant Value Description
REASON_REMOVE? 1? Expert?removed?from?chart.?
REASON_RECOMPILE? 2? Expert?recompiled.?
REASON_CHARTCHANGE? 3? symbol?or?timeframe?changed?on?the?chart.?
REASON_CHARTCLOSE? 4? Chart?closed.?
REASON_PARAMETERS? 5? Inputs?parameters?was?changed?by?user.?
REASON_ACCOUNT? 6? Other?account?activated.?
Wingdings?symbols
圖形符號代碼
32? ?? 33? ?? 34? ?? 35? ?? 36? ?? 37? ?? 38? ?? 39? ?? 40? ?? 41? ?? 42? ?? 43? ?? 44? ?? 45? ?? 46? ?? 47?
?? 48? ?? 49? ?? 50? ?? 51? ?? 52? ?? 53? ?? 54? ?? 55? ?? 56? ?? 57? ?? 58? ?? 59? ?? 60? ?? 61? ?? 62? ?? 63?
?? 64? ?? 65? ?? 66? ?? 67? ?? 68? ?? 69? ?? 70? ?? 71? ?? 72? ?? 73? ?? 74? ?? 75? ?? 76? ?? 77? ?? 78? ?? 79?
?? 80? ?? 81? ?? 82? ?? 83? ?? 84? ?? 85? ?? 86? ?? 87? ?? 88? ?? 89? ?? 90? ?? 91? ?? 92? ?? 93? ?? 94? ?? 95?
?? 96? ?? 97? ?? 98? ?? 99? ?? 100? ?? 101? ?? 102? ?? 103? ?? 104? ?? 105? ?? 106? ?? 107? ?? 108? ?? 109? ?? 110? ?? 111?
?? 112? ?? 113? ?? 114? ?? 115? ?? 116? ?? 117? ?? 118? ?? 119? ?? 120? ?? 121? ?? 122? ?? 123? ?? 124? ?? 125? ?? 126? ?? 127?
?? 128? ?? 129? ?? 130? ?? 131? ?? 132? ?? 133? ?? 134? ?? 135? ?? 136? ?? 137? ?? 138? ?? 139? ?? 140? ?? 141? ?? 142? ?? 143?
?? 144? ?? 145? ?? 146? ?? 147? ?? 148? ?? 149? ?? 150? ?? 151? ?? 152? ?? 153? ?? 154? ?? 155? ?? 156? ?? 157? ?? 158? ?? 159?
160? ?? 161? ?? 162? ?? 163? ?? 164? ?? 165? ?? 166? ?? 167? ?? 168? ?? 169? ?? 170? ?? 171? ?? 172? ?? 173? ?? 174? ?? 175?
?? 176? ?? 177? ?? 178? ?? 179? ?? 180? ?? 181? ?? 182? ?? 183? ?? 184? ?? 185? ?? 186? ?? 187? ?? 188? ?? 189? ?? 190? ?? 191?
?? 192? ?? 193? ?? 194? ?? 195? ?? 196? ?? 197? ?? 198? ?? 199? ?? 200? ?? 201? ?? 202? ?? 203? ?? 204? ?? 205? ?? 206? ?? 207?
?? 208? ?? 209? ?? 210? ?? 211? ?? 212? ?? 213? ?? 214? ?? 215? ?? 216? ?? 217? ?? 218? ?? 219? ?? 220? ?? 221? ?? 222? ?? 223?
?? 224? ?? 225? ?? 226? ?? 227? ?? 228? ?? 229? ?? 230? ?? 231? ?? 232? ?? 233? ?? 234? ?? 235? ?? 236? ?? 237? ?? 238? ?? 239?
?? 240? ?? 241? ?? 242? ?? 243? ?? 244? ?? 245? ?? 246? ?? 247? ?? 248? ?? 249? ?? 250? ?? 251? ?? 252? ?? 253? ?? 254? ?? 255?
Web?colors?table
顏色表?
Black DarkGreen DarkSlateGray Olive Green Teal Navy Purple
Maroon Indigo MidnightBlue DarkBlue DarkOliveGreen SaddleBrown ForestGreen OliveDrab
SeaGreen DarkGoldenrod DarkSlateBlue Sienna MediumBlue Brown DarkTurquoise DimGray
LightSeaGreen DarkViolet FireBrick MediumVioletRed MediumSeaGreen Chocolate Crimson SteelBlue
Goldenrod MediumSpringGreen LawnGreen CadetBlue DarkOrchid YellowGreen LimeGreen OrangeRed
DarkOrange Orange Gold Yellow Chartreuse Lime SpringGreen Aqua
DeepSkyBlue Blue Magenta Red Gray SlateGray Peru BlueViolet
LightSlateGray DeepPink MediumTurquoise DodgerBlue Turquoise RoyalBlue SlateBlue DarkKhaki
IndianRed MediumOrchid GreenYellow MediumAquamarine DarkSeaGreen Tomato RosyBrown Orchid
MediumPurple PaleVioletRed Coral CornflowerBlue DarkGray SandyBrown MediumSlateBlue Tan
DarkSalmon BurlyWood HotPink Salmon Violet LightCoral SkyBlue LightSalmon
Plum Khaki LightGreen Aquamarine Silver LightSkyBlue LightSteelBlue LightBlue
PaleGreen Thistle PowderBlue PaleGoldenrod PaleTurquoise LightGrey Wheat NavajoWhite
Moccasin LightPink Gainsboro PeachPuff Pink Bisque LightGoldenRod BlanchedAlmond
LemonChiffon Beige AntiqueWhite PapayaWhip Cornsilk LightYellow LightCyan Linen
Lavender MistyRose OldLace WhiteSmoke Seashell Ivory Honeydew AliceBlue
LavenderBlush MintCream Snow White
技術指標調用?[Technical?Indicator?calls]
double?iAC(?string?symbol,?int?timeframe,?int?shift)?
計算?Bill?Williams'?Accelerator/Decelerator?oscillator?的值
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
示例:
double?result=iAC(NULL,?0,?1);
double?iAD(?string?symbol,?int?timeframe,?int?shift)?
計算?Accumulation/Distribution?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
示例:
double?result=iAD(NULL,?0,?1);
double?iAlligator(?string?symbol,?int?timeframe,?int?jaw_period,?int?jaw_shift,?int?teeth_period,?int?teeth_shift,?int?lips_period,?int?lips_shift,?int?ma_method,?int?applied_price,?int?mode,?int?shift)?
計算?Bill?Williams'?Alligator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
jaw_period?-?顎線周期
jaw_shift?-?顎線位移
teeth_period?-?齒線周期
teeth_shift?-?齒線位移
lips_period?-?唇線周期?
lips_shift?-?唇線位移?
ma_method?-?移動平均線種類
applied_price?-?應用價格類型
mode?-?來源模式,MODE_GATORJAW,MODE_GATORTEETH?或MODE_GATORLIPS?
shift?-?位移數?
double?jaw_val=iAlligator(NULl,?0,?13,?8,?8,?5,?5,?3,?MODE_SMMA,?PRICE_MEDIAN,?MODE_GATORJAW,?1);
double?iADX(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?mode,?int?shift)?
計算?Movement?directional?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iADX(NULL,0,14,PRICE_HIGH,MODE_MAIN,0)>iADX(NULL,0,14,PRICE_HIGH,MODE_PLUSDI,0))?return(0);
double?iATR(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?Indicator?of?the?average?true?range?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
if(iATR(NULL,0,12,0)>iATR(NULL,0,20,0))?return(0);
double?iAO(?string?symbol,?int?timeframe,?int?shift)?
計算?Bill?Williams'?Awesome?oscillator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
double?val=iAO(NULL,?0,?2);
double?iBearsPower(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Bears?Power?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iBearsPower(NULL,?0,?13,PRICE_CLOSE,0);
double?iBands(?string?symbol,?int?timeframe,?int?period,?int?deviation,?int?bands_shift,?int?applied_price,?int?mode,?int?shift)?
計算?Bollinger?bands?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
deviation?-?背離
bands_shift?-?Bands位移?
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0])?return(0);
double?iBandsOnArray(?double?array[],?int?total,?int?period,?double?deviation,?int?bands_shift,?int?mode,?int?shift)?
從數組中計算?Bollinger?bands?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
deviation?-?背離
bands_shift?-?Bands位移?
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0])?return(0);
double?iBullsPower(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Bulls?Power?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iBullsPower(NULL,?0,?13,PRICE_CLOSE,0);
double?iCCI(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Commodity?channel?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iCCI(NULL,0,12,0)>iCCI(NULL,0,20,0))?return(0);
double?iCCIOnArray(?double?array[],?int?total,?int?period,?int?shift)?
從數組中計算?Commodity?channel?index?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
shift?-?位移數?
if(iCCIOnArray(ExtBuffer,total,12,0)>iCCI(NULL,0,20,PRICE_OPEN,?0))?return(0);
double?iCustom(?string?symbol,?int?timeframe,?string?name,?...?,?int?mode,?int?shift)?
計算?自定義指標?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
name?-?自定義指標名稱
...?-?自定義指標參數?
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iCustom(NULL,?0,?"SampleInd",13,1,0);
double?iDeMarker(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?DeMarker?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
double?val=iDeMarker(NULL,?0,?13,?1);
double?iEnvelopes(?string?symbol,?int?timeframe,?int?ma_period,?int?ma_method,?int?ma_shift,?int?applied_price,?double?deviation,?int?mode,?int?shift)?
計算?Envelopes?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
applied_price?-?應用價格類型
deviation?-?背離
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iEnvelopes(NULL,?0,?13,MODE_SMA,10,PRICE_CLOSE,0.2,MODE_UPPER,0);
double?iEnvelopesOnArray(?double?array[],?int?total,?int?ma_period,?int?ma_method,?int?ma_shift,?double?deviation,?int?mode,?int?shift)
從數組中計算?Envelopes?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
deviation?-?背離
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iEnvelopesOnArray(ExtBuffer,?0,?13,?MODE_SMA,?0.2,?MODE_UPPER,0?);
double?iForce(?string?symbol,?int?timeframe,?int?period,?int?ma_method,?int?applied_price,?int?shift)?
計算?Force?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
ma_method?-?移動平均線模式
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iForce(NULL,?0,?13,MODE_SMA,PRICE_CLOSE,0);
double?iFractals(?string?symbol,?int?timeframe,?int?mode,?int?shift)?
計算?Fractals?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iFractals(NULL,?0,?MODE_UPPER,0);
double?iGator(?string?symbol,?int?timeframe,?int?jaw_period,?int?jaw_shift,?int?teeth_period,?int?teeth_shift,?int?lips_period,?int?lips_shift,?int?ma_method,?int?applied_price,?int?mode,?int?shift)?
計算?Fractals?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
jaw_period?-?顎線周期
jaw_shift?-?顎線位移
teeth_period?-?齒線周期
teeth_shift?-?齒線位移
lips_period?-?唇線周期?
lips_shift?-?唇線位移?
ma_method?-?移動平均線種類
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?jaw_val=iGator(NULL,?0,?13,?8,?8,?5,?5,?3,?MODE_SMMA,?PRICE_MEDIAN,?MODE_UPPER,?1);
double?iIchimoku(?string?symbol,?int?timeframe,?int?tenkan_sen,?int?kijun_sen,?int?senkou_span_b,?int?mode,?int?shift)?
計算?Ichimoku?Kinko?Hyo?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
tenkan_sen?-?轉換線?
jkijun_sen?-?基準線?
senkou_span_b?-?參考范圍b?
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?tenkan_sen=iIchimoku(NULL,?0,?9,?26,?52,?MODE_TENKANSEN,?1);
double?iBWMFI(?string?symbol,?int?timeframe,?int?shift)?
計算?Bill?Williams?Market?Facilitation?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
double?val=iBWMFI(NULL,?0,?0);
double?iMomentum(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Momentum?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iMomentum(NULL,0,12,PRICE_CLOSE,0)>iMomentum(NULL,0,20,PRICE_CLOSE,0))?return(0);
double?iMomentumOnArray(?double?array[],?int?total,?int?period,?int?shift)?
從數組中計算?Momentum?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
shift?-?位移數?
if(iMomentumOnArray(mybuffer,100,12,0)>iMomentumOnArray(mubuffer,100,20,0))?return(0);
double?iMFI(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?Money?flow?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
if(iMFI(NULL,0,14,0)>iMFI(NULL,0,14,1))?return(0);
double?iMA(?string?symbol,?int?timeframe,?int?period,?int?ma_shift,?int?ma_method,?int?applied_price,?int?shift)?
計算?Moving?average?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
ma_shift?-?移動平均線位移
ma_method?-?移動平均線模式
applied_price?-?應用價格類型
shift?-?位移數?
AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);
double?iMAOnArray(?double?array[],?int?total,?int?period,?int?ma_shift,?int?ma_method,?int?shift)?
從數組中計算?Moving?average?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
ma_shift?-?移動平均線位移
ma_method?-?移動平均線模式
shift?-?位移數?
double?macurrent=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,0);
double?macurrentslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,0);
double?maprev=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,1);
double?maprevslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,1);
//----
if(maprev=macurrentslow)
Alert("crossing?up");
double?iOsMA(?string?symbol,?int?timeframe,?int?fast_ema_period,?int?slow_ema_period,?int?signal_period,?int?applied_price,?int?shift)?
計算?Moving?Average?of?Oscillator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
fast_ema_period?-?快均線周期
slow_ema_period?-?慢均線周期
signal_period?-?信號周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iOsMA(NULL,0,12,26,9,PRICE_OPEN,1)>iOsMA(NULL,0,12,26,9,PRICE_OPEN,0))?return(0);
double?iMACD(?string?symbol,?int?timeframe,?int?fast_ema_period,?int?slow_ema_period,?int?signal_period,?int?applied_price,?int?mode,?int?shift)?
計算?Moving?averages?convergence/divergence?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
fast_ema_period?-?快均線周期
slow_ema_period?-?慢均線周期
signal_period?-?信號周期
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0))?return(0);
double?iOBV(?string?symbol,?int?timeframe,?int?applied_price,?int?shift)?
計算?On?Balance?Volume?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
double?val=iOBV(NULL,?0,?PRICE_CLOSE,?1);
double?iSAR(?string?symbol,?int?timeframe,?double?step,?double?maximum,?int?shift)?
計算?On?Balance?Volume?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
step?-?步幅
maximum?-?最大值
shift?-?位移數?
if(iSAR(NULL,0,0.02,0.2,0)>Close[0])?return(0);
double?iRSI(?string?symbol,?void?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Relative?strength?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>iRSI(NULL,0,14,PRICE_CLOSE,1))?return(0);
double?iRSIOnArray(?double?array[],?int?total,?int?period,?int?shift)?
從數組中計算?Relative?strength?index?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
shift?-?位移數?
if(iRSIOnBuffer(ExtBuffer,1000,14,0)>iRSI(NULL,0,14,PRICE_CLOSE,1))?return(0);
double?iRVI(?string?symbol,?int?timeframe,?int?period,?int?mode,?int?shift)?
計算?Relative?Vigor?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iRVI(NULL,?0,?10,MODE_MAIN,0);
double?iStdDev(?string?symbol,?int?timeframe,?int?ma_period,?int?ma_method,?int?ma_shift,?int?applied_price,?int?shift)?
計算?Standard?Deviation?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iStdDev(NULL,0,10,MODE_EMA,0,PRICE_CLOSE,0);
double?iStdDevOnArray(?double?array[],?int?total,?int?ma_period,?int?ma_method,?int?ma_shift,?int?shift)?
從數組中計算?Standard?Deviation?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
shift?-?位移數?
double?val=iStdDevOnArray(ExtBuffer,100,10,MODE_EMA,0,0);
double?iStochastic(?string?symbol,?int?timeframe,?int?%Kperiod,?int?%Dperiod,?int?slowing,?int?method,?int?price_field,?int?mode,?int?shift)?
計算?Stochastic?oscillator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
%Kperiod?-?%K線周期?
%Dperiod?-?%D線周期
slowing?-?減速量
method?-?移動平均線種類
price_field?-?價格領域參數:?0?-?Low/High?or?1?-?Close/Close.?
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0))
return(0);
double?iWPR(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?Larry?William's?percent?range?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
if(iWPR(NULL,0,14,0)>iWPR(NULL,0,14,1))?return(0);
int?iBars(?string?symbol,?int?timeframe)?
返回制定圖表的數據數?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線?
Print("Bar?count?on?the?'EUROUSD'?symbol?with?PERIOD_H1?is",iBars("EUROUSD",PERIOD_H1));
int?iBarShift(?string?symbol,?int?timeframe,?datetime?time,?bool?exact=false)?
在制定圖表中搜索數據?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
time?-?時間
exact?-?是否精確的?
datetime?some_time=D'2004.03.21?12:00';
int?shift=iBarShift("EUROUSD",PERIOD_M1,some_time);
Print("shift?of?bar?with?open?time?",TimeToStr(some_time),"?is?",shift);
double?iClose(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的收盤價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iHigh(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的最高價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iLow(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的最低價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iOpen(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的開盤價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
datetime?iTime(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的時間?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iVolume(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的成交量?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
int?Highest(?string?symbol,?int?timeframe,?int?type,?int?count=WHOLE_ARRAY,?int?start=0)?
返回制定圖表的某段數據的最高值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
type?-?數據類型
count?-?計算范圍
start?-?開始點?
double?val;
//?calculating?the?highest?value?in?the?range?from?5?element?to?25?element
//?indicator?charts?symbol?and?indicator?charts?time?frame
val=High[Highest(NULL,0,MODE_HIGH,20,4)];
int?Lowest(?string?symbol,?int?timeframe,?int?type,?int?count=WHOLE_ARRAY,?int?start=0)?
返回制定圖表的某段數據的最高值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
type?-?數據類型
count?-?計算范圍
start?-?開始點?
double?val=Low[Lowest(NULL,0,MODE_LOW,10,10)];
交易函數?[Trading?Functions]
int?HistoryTotal(?)
返回歷史數據的數量
//?retrieving?info?from?trade?history
int?i,hstTotal=HistoryTotal();
for(i=0;i<HSTTOTAL;I++)
{
//----?check?selection?result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Access?to?history?failed?with?error?(",GetLastError(),")");
break;
}
//?some?work?with?order
}
bool?OrderClose(?int?ticket,?double?lots,?double?price,?int?slippage,?color?Color=CLR_NONE)?
對訂單進行平倉操作。?
::?輸入參數
ticket?-?訂單編號
lots?-?手數
price?-?平倉價格
slippage?-?最高劃點數
Color?-?標記顏色?
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderClose(order_id,1,Ask,3,Red);
return(0);
}
bool?OrderCloseBy(?int?ticket,?int?opposite,?color?Color=CLR_NONE)?
對訂單進行平倉操作。?
::?輸入參數
ticket?-?訂單編號
opposite?-?相對訂單編號
Color?-?標記顏色?
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderCloseBy(order_id,opposite_id);
return(0);
}
double?OrderClosePrice(?)?
返回訂單的平倉價
示例:
if(OrderSelect(ticket,SELECT_BY_POS)==true)
Print("Close?price?for?the?order?",ticket,"?=?",OrderClosePrice());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
datetime?OrderCloseTime(?)?
返回訂單的平倉時間
示例:
if(OrderSelect(10,SELECT_BY_POS,MODE_HISTORY)==true)
{
datetime?ctm=OrderOpenTime();
if(ctm>0)?Print("Open?time?for?the?order?10?",?ctm);
ctm=OrderCloseTime();
if(ctm>0)?Print("Close?time?for?the?order?10?",?ctm);
}
else
Print("OrderSelect?failed?error?code?is",GetLastError());
string?OrderComment(?)?
返回訂單的注釋
示例:
string?comment;
if(OrderSelect(10,SELECT_BY_TICKET)==false)
{
Print("OrderSelect?failed?error?code?is",GetLastError());
return(0);
}
comment?=?OrderComment();
//?...
double?OrderCommission(?)?
返回訂單的傭金數
示例:
if(OrderSelect(10,SELECT_BY_POS)==true)
Print("Commission?for?the?order?10?",OrderCommission());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
bool?OrderDelete(?int?ticket)?
刪除未啟用的訂單?
::?輸入參數
ticket?-?訂單編號?
示例:
if(Ask>var1)
{
OrderDelete(order_ticket);
return(0);
}
datetime?OrderExpiration(?)?
返回代辦訂單的有效日期
示例:
if(OrderSelect(10,?SELECT_BY_TICKET)==true)
Print("Order?expiration?for?the?order?#10?is?",OrderExpiration());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
double?OrderLots(?)?
返回選定訂單的手數
示例:
if(OrderSelect(10,SELECT_BY_POS)==true)
Print("lots?for?the?order?10?",OrderLots());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrderMagicNumber(?)?
返回選定訂單的指定編號
示例:
if(OrderSelect(10,SELECT_BY_POS)==true)
Print("Magic?number?for?the?order?10?",?OrderMagicNumber());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
bool?OrderModify(?int?ticket,?double?price,?double?stoploss,?double?takeprofit,?datetime?expiration,?color?arrow_color=CLR_NONE)?
對訂單進行平倉操作。?
::?輸入參數
ticket?-?訂單編號
price?-?平倉價格
stoploss?-?止損價
takeprofit?-?獲利價
expiration?-?有效期
Color?-?標記顏色?
示例:
if(TrailingStop>0)
{
SelectOrder(12345,SELECT_BY_TICKET);
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<BID-POINT*TRAILINGSTOP)
{
OrderModify(OrderTicket(),Ask-10*Point,Ask-35*Point,OrderTakeProfit(),0,Blue);
return(0);
}
}
}
double?OrderOpenPrice(?)?
返回選定訂單的買入價
示例:
if(OrderSelect(10,?SELECT_BY_POS)==true)
Print("open?price?for?the?order?10?",OrderOpenPrice());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
datetime?OrderOpenTime(?)
返回選定訂單的買入時間
示例:
if(OrderSelect(10,?SELECT_BY_POS)==true)
Print("open?time?for?the?order?10?",OrderOpenTime());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
void?OrderPrint(?)?
將訂單打印到窗口上
示例:
if(OrderSelect(10,?SELECT_BY_TICKET)==true)
OrderPrint();
else
Print("OrderSelect?failed?error?code?is",GetLastError());
bool?OrderSelect(?int?index,?int?select,?int?pool=MODE_TRADES)?
選定訂單?
::?輸入參數
index?-?訂單索引
select?-?選定模式,SELECT_BY_POS,SELECT_BY_TICKET
pool?-?Optional?order?pool?index.?Used?when?select?parameter?is?SELECT_BY_POS.It?can?be?any?of?the?following?values:
MODE_TRADES?(default)-?order?selected?from?trading?pool(opened?and?pending?orders),
MODE_HISTORY?-?order?selected?from?history?pool?(closed?and?canceled?order).?
示例:
if(OrderSelect(12470,?SELECT_BY_TICKET)==true)
{
Print("order?#12470?open?price?is?",?OrderOpenPrice());
Print("order?#12470?close?price?is?",?OrderClosePrice());
}
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrderSend(?string?symbol,?int?cmd,?double?volume,?double?price,?int?slippage,?double?stoploss,?double?takeprofit,?string?comment=NULL,?int?magic=0,?datetime?expiration=0,?color?arrow_color=CLR_NONE)?
發送訂單?
::?輸入參數
symbol?-?通貨標示
cmd?-?購買方式
volume?-?購買手數
price?-?平倉價格
slippage?-?最大允許滑點數
stoploss?-?止損價
takeprofit?-?獲利價
comment?-?注釋
magic?-?自定義編號
expiration?-?過期時間(只適用于待處理訂單)
arrow_color?-?箭頭顏色?
示例:
int?ticket;
if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
{
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My?order?#2",16384,0,Green);
if(ticket<0)
{
Print("OrderSend?failed?with?error?#",GetLastError());
return(0);
}
}
double?OrderStopLoss(?)?
返回選定訂單的止損
示例:
if(OrderSelect(ticket,SELECT_BY_POS)==true)
Print("Stop?loss?value?for?the?order?10?",?OrderStopLoss());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrdersTotal(?)?
返回總訂單數
示例:
int?handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
if(handle<0)?return(0);
//?write?header
FileWrite(handle,"#","open?price","open?time","symbol","lots");
int?total=OrdersTotal();
//?write?open?orders
for(int?pos=0;pos<TOTAL;POS++)
{
if(OrderSelect(pos,SELECT_BY_POS)==false)?continue;
FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots());
}
FileClose(handle);
int?OrdersTotal(?)?
返回總訂單數
示例:
if(OrderSelect(order_id,?SELECT_BY_TICKET)==true)
Print("Swap?for?the?order?#",?order_id,?"?",OrderSwap());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
double?OrderSwap(?)?
返回指定訂單的匯率
示例:
if(OrderSelect(order_id,?SELECT_BY_TICKET)==true)
Print("Swap?for?the?order?#",?order_id,?"?",OrderSwap());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
string?OrderSymbol(?)?
返回指定訂單的通貨標識
示例:
if(OrderSelect(12,?SELECT_BY_POS)==true)
Print("symbol?of?order?#",?OrderTicket(),?"?is?",?OrderSymbol());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
double?OrderTakeProfit(?)?
返回指定訂單的獲利點數
示例:
if(OrderSelect(12,?SELECT_BY_POS)==true)
Print("Order?#",OrderTicket(),"?profit:?",?OrderTakeProfit());
else
Print("OrderSelect()?a?eíó????èáêó?-?",GetLastError());
int?OrderTicket(?)?
返回指定訂單的編號
示例:
if(OrderSelect(12,?SELECT_BY_POS)==true)
order=OrderTicket();
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrderType(?)?
返回指定訂單的類型
示例:
int?order_type;
if(OrderSelect(12,?SELECT_BY_POS)==true)
{
order_type=OrderType();
//?...
}
else
Print("OrderSelect()?a?eíó????èáêó?-?",GetLastError());
窗口函數?[Window?Functions]
double?PriceOnDropped(?)?
Returns?price?part?of?dropped?point?where?expert?or?script?was?dropped.?This?value?is?valid?when?expert?or?script?dropped?by?mouse.
Note:?For?custom?indicators?this?value?is?undefined.
示例:
double?drop_price=PriceOnDropped();
datetime?drop_time=TimeOnDropped();
//----?may?be?undefined?(zero)
if(drop_time>0)
{
ObjectCreate("Dropped?price?line",?OBJ_HLINE,?0,?drop_price);
ObjectCreate("Dropped?time?line",?OBJ_VLINE,?0,?drop_time);
}
datetime?TimeOnDropped(?)?
Returns?time?part?of?dropped?point?where?expert?or?script?was?dropped.?This?value?is?valid?when?expert?or?script?dropped?by?mouse.
Note:?For?custom?indicators?this?value?is?undefined.
示例:
double?drop_price=PriceOnDropped();
datetime?drop_time=TimeOnDropped();
//----?may?be?undefined?(zero)
if(drop_time>0)
{
ObjectCreate("Dropped?price?line",?OBJ_HLINE,?0,?drop_price);
ObjectCreate("Dropped?time?line",?OBJ_VLINE,?0,?drop_time);
}
int?WindowFind(?string?name)?
返回窗口的索引號?
::?輸入參數
name?-?指標簡稱?
示例:
int?win_idx=WindowFind("MACD(12,26,9)");
int?WindowHandle(?string?symbol,?int?timeframe)?
返回窗口的句柄?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線?
示例:
int?win_handle=WindowHandle("USDX",PERIOD_H1);
if(win_handle!=0)
Print("Window?with?USDX,H1?detected.?Rates?array?will?be?copied?immediately.");
bool?WindowIsVisible(?int?index)?
返回窗口是否可見?
::?輸入參數
index?-?窗口索引號?
示例:
int?maywin=WindowFind("MyMACD");
if(maywin>-1?&&?WindowIsVisible(maywin)==true)
Print("window?of?MyMACD?is?visible");
else
Print("window?of?MyMACD?not?found?or?is?not?visible");
int?WindowOnDropped(?)?
Returns?window?index?where?expert,?custom?indicator?or?script?was?dropped.?This?value?is?valid?when?expert,?custom?indicator?or?script?dropped?by?mouse.
示例:
if(WindowOnDropped()!=0)
{
Print("Indicator?'MyIndicator'?must?be?applied?to?main?chart?window!");
return(false);
}
int?WindowsTotal(?)?
返回窗口數
示例:
Print("Windows?count?=?",?WindowsTotal());
int?WindowXOnDropped(?)?
Returns?x-axis?coordinate?in?pixels?were?expert?or?script?dropped?to?the?chart.?See?also?WindowYOnDropped(),?WindowOnDropped()
示例:
Print("Expert?dropped?point?x=",WindowXOnDropped(),"?y=",WindowYOnDropped());/div>
int?WindowYOnDropped(?)?
Returns?y-axis?coordinate?in?pixels?were?expert?or?script?dropped?to?the?chart.?See?also?WindowYOnDropped(),?WindowOnDropped()
示例:
Print("Expert?dropped?point?x=",WindowXOnDropped(),"?y=",WindowYOnDropped());
代碼格式
空格建、Tab鍵、換行鍵和換頁符都可以成為代碼排版的分隔符,你能使用各種符號來增加代碼的可讀性。
注釋?
多行注釋使用?/*?作為開始到?*/?結束,在這之間不能夠嵌套。單行注釋使用?//?作為開始到新的一行結束,可以被嵌套到多行注釋之中。
示例:
//?單行注釋?
/*?多行
?????注釋?//?嵌套的單行注釋?
注釋結束?*/
標識符?
標識符用來給變量、函數和數據類型進行命名,長度不能超過31個字節
你可以使用數字0-9、拉丁字母大寫A-Z和小寫a-z(大小寫有區分的)還有下劃線(_)。此外首字母不可以是數字,標識符不能和保留字沖突.
示例:
//?NAME1?namel?Total_5?Paper
保留字?
下面列出的是固定的保留字。不能使用以下任何保留字進行命名。?
數據類型 存儲類型 操作符 其它
bool? extern? break? false?
color? static? case? true?
datetime? continue?
double? default?
int? else?
string? for?
void? if?
return?
switch?
while?
數據類型?[Data?types]
數據類型概述
主要數據類型有:
? Integer?(int)?
? Boolean?(bool)?
? ?èò?eà???(char)?
? String?(string)?
? Floating-point?number?(double)?
? Color?(color)?
? Datetime?(datetime)?
我們用Integer類型數據來作為DateTime和Color數據的存儲。
使用以下方式可以進行類型站換:
int?(bool,color,datetime);
double;
string;
Integer?類型
十進制:?數字0-9;0不能作為第一個字母
示例:
12,?111,?-956?1007
十六進制:?數字0-9;拉丁字母a-f或A-F用來表示10-15;使用0x或者0X作為開始。
示例:
0x0A,?0x12,?0X12,?0x2f,?0xA3,?0Xa3,?0X7C7
Integer?變量的取值范圍為-2147483648到2147483647。
Literal?類型
任意在單引號中的字符或十六進制的任意ASCII碼例如'\x10'都是被看作為一個字符,
一些字符例如單引號('),雙引號("),問號(?),反斜杠(\)和一些控制符都需要在之前加一個反斜杠(\)進行轉意后表示出來:
line?feed?NL?(LF)?\n
horizontal?tab?HT?\t
carriage?return?CR?\r
reverse?slash?\?\\
single?quote?'?\'
double?quote?"?\"
hexadecimal?ASCII-code?hh?\xhh
以上字符如果不經過反斜杠進行轉意將不能被使用
示例:
int?a?=?'A';
int?b?=?'$';
int?c?=?'?';?//?code?0xA9
int?d?=?'\xAE';?//?symbol?code??
Boolean?類型
Boolean?用來表示?是?和?否,?還可以用數字?1?和?0?進行表示。True和Flase可以忽略大小寫。
示例:
bool?a?=?true;
bool?b?=?false;
bool?c?=?1;
Floating-point?number?類型
浮點型變量在整數型后面加一個點(.)用來更精確的表示十進制數字。
示例:
double?a?=?12.111;
double?b?=?-956.1007;
double?c?=?0.0001;
double?d?=?16;
浮點型的取值范圍從?2.2e-308?到?1.8e308.
String?類型
字符串型是用來表示連續的ASCII碼字符的使用連續的兩個雙引號來包括需要表示的內容如:"Character?constant".
示例:
"This?is?a?character?string"
"Copyright?symbol?\t\xA9"
"this?line?with?LF?symbol?\n"
"A"?"1234567890"?"0"?"$"
Color?類型
顏色類型可以使用以下示例里的幾種方式進行定義。?
示例:
//?symbol?constants
C'128,128,128'?//?gray
C'0x00,0x00,0xFF'?//?blue
//?named?color
Red
Yellow
Black
//?integer-valued?representation
0xFFFFFF?//?white
16777215?//?white
0x008000?//?green
32768?//?green
Datetime?類型
時間類型使用年、月、日、時、分、秒來進行定義,你可以使用以下示例中的方式來定義變量。
示例:
D'2004.01.01?00:00'?//?New?Year
D'1980.07.19?12:30:27'
D'19.07.1980?12:30:27'
D'19.07.1980?12'?//equal?to?D'1980.07.19?12:00:00'
D'01.01.2004'?//equal?to?D'01.01.2004?00:00:00'
D'12:30:27'?//equal?to?D'[compilation?date]?12:30:27'
D''?//equal?to?D'[compilation?date]?00:00:00'
運算符和表達式?[Operations?&?Expressions]
表達式
一個表達式可以擁有多個字符和操作符,一個表達式可以寫在幾行里面。
示例:
a++;?b?=?10;?x?=?(y*z)/w;
注:分號(;)是表達式的結束符。
算術運算符
Sum?of?values?i?=?j?+?2;
Difference?of?values?i?=?j?-?3;
Changing?the?operation?sign?x?=?-?x;
Product?of?values?z?=?3?*?x;
Division?quotient?i?=?j?/?5;
Division?remainder?minutes?=?time?%?60;
Adding?1?to?the?variable?value?i++;
Subtracting?1?from?the?variable?value?k--;
加減1的運算符不能被嵌套在表達式中
int?a=3;
a++;?//?可行的表達式
int?b=(a++)*3;?//?不可行的表達式
賦值運算符
注:將右側的結果賦值給左側的變量
將x的值賦值給y?y?=?x;
將x的值加到y上面?y?+=?x;
在y上面減去x的值?y?-=?x;
得到y的x倍的值?y?*=?x;
得到y除以x的值?y?/=?x;
取y除以x后的余數?y?%=?x;
y向右位移x位?y?>>=?x;
y向左位移x位?y?<<=?x;
得到邏輯AND的值?y?&=?x;
得到邏輯OR的值?y?|=?x;
得到邏輯非OR的值?y?^=?x;
注:一個表達式只能有一個賦值運算符.
關系運算符
用返回0(False)或1(True)來表示兩個量之間的關系。
a是否等于b?a?==?b;
a是否不等于b?a?!=?b;
a是否小于b?a?<?b;
a是否大于b?a?>?b;
a是否小于等于b?a?<=?b;
a是否大于等于b?a?>=?b;
真假運算符
否定運算符(!),用來表示真假的反面的結果。
//?如果a不是真的
if(!a)
Print("not?'a'");
邏輯運算符或(||)用來表示兩個表達式只要有一個成立即可。
示例:
if(xl)
Print("out?of?range");
邏輯運算符和(&&)用來表示兩個表達式要同時成立才行。
示例:
if(p!=x?&&?p>y)
Print("true");
n++;
位邏輯運算符
~?運算符對操作數執行按位求補操作。
b?=?~n;
>>?運算符對操作數執行向右位移操作。
x?=?x?>>?y;
<<?運算符對操作數執行向左位移操作。
x?=?x?<<?y;
一元?&?運算符返回操作數的地址
為整型和?bool?類型預定義了二進制?&?運算符。對于整型,&?計算操作數的按位“與”。對于?bool?操作數,&?計算操作數的邏輯“與”;也就是說,當且僅當兩個操作數均為?true?時,其結果才為?true。
b?=?((x?&?y)?!=?0);
二進制?|?運算符是為整型和?bool?類型預定義的。對于整型,|?對操作數進行按位“或”運算。對于?bool?操作數,|?對操作數進行邏輯“或”計算,也就是說,當且僅當兩個操作數均為?false?時,其結果才為?false。
b?=?x?|?y;
為整型和?bool?類型預定義了?^?二進制操作數。對于整型,^?計算操作數的按位“異或”。對于?bool?操作數,^?計算操作數的邏輯“異或”;也就是說,當且僅當只有一個操作數為?true?時,其結果才為?true。
b?=?x?^?y;
注:位邏輯運算符只作用于Integers類型
其它運算符
索引。定位在數組中i位置的值。
array[i]?=?3;
//將3負值到array數組第i位置上
使用?x1,x2,...,xn?這樣的方法將各種值傳送到function中進行運算。
示例:
double?SL=Ask-25*Point;
double?TP=Ask+25*Point;
int?ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,SL,TP,
"My?comment",123,0,Red);
優先級規則
下面是從上到下的運算優先規則,優先級高的將先被運算。
()?Function?call?From?left?to?right
[]?Array?element?selection
!?Negation?From?left?to?right
~?Bitwise?negation
-?Sign?changing?operation
*?Multiplication?From?left?to?right
/?Division
%?Module?division
+?Addition?From?left?to?right
-?Subtraction
<<?Left?shift?From?left?to?right
>>?Right?shift
<?Less?than?From?left?to?right
<=?Less?than?or?equals
>?Greater?than
>=?Greater?than?or?equals
==?Equals?From?left?to?right
!=?Not?equal
&?Bitwise?AND?operation?From?left?to?right
^?Bitwise?exclusive?OR?From?left?to?right
|?Bitwise?OR?operation?From?left?to?right
&&?Logical?AND?From?left?to?right
||?Logical?OR?From?left?to?right
=?Assignment?From?right?to?left
+=?Assignment?addition
-=?Assignment?subtraction
*=?Assignment?multiplication
/=?Assignment?division
%=?Assignment?module
>>=?Assignment?right?shift
<<=?Assignment?left?shift
&=?Assignment?bitwise?AND
|=?Assignment?bitwise?OR
^=?Assignment?exclusive?OR
,?Comma?From?left?to?right
操作符?[Operators]?
格式和嵌套
格式.一個操作符可以占用一行或者多行,兩個或多個操作符可以占用更多的行。
嵌套.執行控制符(if,?if-else,?switch,?while?and?for)可以進行任意嵌套.
復合操作符
一個復合操作符有一個(一個區段)和由一個或多個任何類型的操作符組成的的附件{}.?每個表達式使用分號作為結束(;)
示例:
if(x==0)
{
x=1;?y=2;?z=3;
}
表達式操作符
任何以分號(;)結束的表達式都被視為是一個操作符。
Assignment?operator.
Identifier=expression;
標識符=表達式;
示例:
x=3;
y=x=3;?//?這是錯誤的
一個操作符中只能有一個表達式。
調用函數操作符
Function_name(argument1,...,?argumentN);
函數名稱(參數1,...,參數N);
示例:
fclose(file);
空操作符
只有一個分號組成(;).我們用它來表示沒有任何表達式的空操作符.
停止操作符
一個break;?,?我們將其放在嵌套內的指定位置,用來在指定情況下跳出循環操作.
示例:
//?從0開始搜索數組
for(i=0;i<ARRAY_SIZE;I++)
if((array[i]==0)
break;
繼續操作符
一個continue;我們將其放在嵌套內的指定位置,用來在指定情況下跳過接下來的運算,直接跳入下一次的循環。
示例:
//?summary?of?nonzero?elements?of?array
int?func(int?array[])
{
int?array_size=ArraySize(array);
int?sum=0;
for(int?i=0;i
{
if(a[i]==0)?continue;
sum+=a[i];
}
return(sum);
}
返回操作符
一個return;將需要返回的結果放在return后面的()中。
示例:
return(x+y);
條件操作符?if
if?(expression)
operator;
如果表達式為真那么執行操作。
示例:
if(a==x)
temp*=3;
temp=MathAbs(temp);
條件操作符?if-else
if?(expression)
operator1
else
operator2
如果表達式為真那么執行operator1,如果為假執行operator2,else后還可以跟進多個if執行多項選擇。詳見示例。
示例:
if(x>1)
if(y==2)
z=5;
else
z=6;?
if(x>l)
{
if(y==2)?z=5;
}
else
{
z=6;
}
//?多項選擇
if(x=='a')
{
y=1;
}
else?if(x=='b')
{
y=2;
z=3;
}
else?if(x=='c')
{
y?=?4;
}
else
{
Print("ERROR");
}
選擇操作符?switch
switch?(expression)
{
case?constant1:?operators;?break;
case?constant2:?operators;?break;
...
default:?operators;?break;
}
當表達式expression的值等于結果之一時,執行其結果下的操作。不管結果如何都將執行default中的操作。
示例:
case?3+4:?//正確的
case?X+Y:?//錯誤的
被選擇的結果只可以是常數,不可為變量或表達式。
示例:
switch(x)
{
case?'A':
Print("CASE?A\n");
break;
case?'B':
case?'C':
Print("CASE?B?or?C\n");
break;
default:
Print("NOT?A,?B?or?C\n");
break;
}
循環操作符?while
while?(expression)
operator;
只要表達式expression為真就執行操作operator
示例:
while(k<N)
{
y=y*x;
k++;
}
循環操作符?for
for?(expression1;?expression2;?expression3)
operator;
用表達式1(expression1)來定義初始變量,當表達式2(expression2)為真的時候執行操作operator,在每次循環結束后執行表達式3(expression3)
用while可以表示為這樣:
expression1;
while?(expression2)
{
operator;
expression3;
};
示例:
for(x=1;x<=7;x++)
Print(MathPower(x,2));
使用for(;;)可以造成一個死循環如同while(true)一樣.
表達式1和表達式3都可以內嵌多個用逗號(,)分割的表達式。
示例:
for(i=0,j=n-l;i<N;I++,J--)
a[i]=a[j];
函數?[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());
int?AccountLeverage()
返回杠桿比率
示例:
Print("Account?#",AccountNumber(),?"?leverage?is?",?AccountLeverage());
double?AccountMargin()
Returns?margin?value?of?the?current?account.
示例:
Print("Account?margin?",?AccountMargin());
string?AccountName()
返回賬戶名稱
示例:
Print("Account?name?",?AccountName());
int?AccountNumber()
返回賬戶數字
示例:
Print("account?number?",?AccountNumber());
double?AccountProfit()
返回賬戶利潤
示例:
Print("Account?profit?",?AccountProfit());
數組函數?[Array?Functions]
int?ArrayBsearch(?double?array[],?double?value,?int?count=WHOLE_ARRAY,?int?start=0,?int?direction=MODE_ASCEND)
搜索一個值在數組中的位置
此函數不能用在字符型或連續數字的數組上.
::?輸入參數
array[]?-?需要搜索的數組
value?-?將要搜索的值?
count?-?搜索的數量,默認搜索所有的數組
start?-?搜索的開始點,默認從頭開始
direction?-?搜索的方向,MODE_ASCEND?順序搜索?MODE_DESCEND?倒序搜索?
示例:
datetime?daytimes[];
int?shift=10,dayshift;
//?All?the?Time[]?timeseries?are?sorted?in?descendant?mode
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
if(Time[shift]>>=daytimes[0])?dayshift=0;
else
{
dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()<PERIOD_D1)
dayshift++;
}
Print(TimeToStr(Time[shift]),"?corresponds?to?",dayshift,"?day?bar?opened?at?",
TimeToStr(daytimes[dayshift]));
int?ArrayCopy(?object&?dest[],?object?source[],?int?start_dest=0,?int?start_source=0,?int?count=WHOLE_ARRAY)?
復制一個數組到另外一個數組。
只有double[],?int[],?datetime[],?color[],?和?bool[]?這些類型的數組可以被復制。?
::?輸入參數
dest[]?-?目標數組?
source[]?-?源數組?
start_dest?-?從目標數組的第幾位開始寫入,默認為0?
start_source?-?從源數組的第幾位開始讀取,默認為0?
count?-?讀取多少位的數組?
示例:
double?array1[][6];
double?array2[10][6];
//?fill?array?with?some?data
ArrayCopyRates(array1);
ArrayCopy(array2,?array1,0,Bars-9,10);
//?now?array2?has?first?10?bars?in?the?history
int?ArrayCopyRates(?double&?dest_array[],?string?symbol=NULL,?int?timeframe=0)?
復制一段走勢圖上的數據到一個二維數組,數組的第二維只有6個項目分別是:
0?-?時間,
1?-?開盤價,
2?-?最低價,
3?-?最高價,
4?-?收盤價,
5?-?成交量.?
::?輸入參數
dest_array[]?-?目標數組
symbol?-?標示,當前所需要的通貨的標示
timeframe?-?圖表的時間線?
示例:
double?array1[][6];
ArrayCopyRates(array1,"EURUSD",?PERIOD_H1);
Print("Current?bar?",TimeToStr(array1[0][0]),"Open",?array1[0][1]);
int?ArrayCopySeries(?double&?array[],?int?series_index,?string?symbol=NULL,?int?timeframe=0)?
復制一個系列的走勢圖數據到數組上
注:?如果series_index是MODE_TIME,?那么第一個參數必須是日期型的數組?
::?輸入參數
dest_array[]?-?目標數組
series_index?-?想要取的系列的名稱或編號,0-5
symbol?-?標示,當前所需要的通貨的標示
timeframe?-?圖表的時間線?
示例:
datetime?daytimes[];
int?shift=10,dayshift;
//?All?the?Time[]?timeseries?are?sorted?in?descendant?mode
ArrayCopySeries(daytimes,MODE_TIME,Symbol(),PERIOD_D1);
if(Time[shift]>=daytimes[0])?dayshift=0;
else
{
dayshift=ArrayBsearch(daytimes,Time[shift],WHOLE_ARRAY,0,MODE_DESCEND);
if(Period()
}
Print(TimeToStr(Time[shift]),"?corresponds?to?",dayshift,"?day?bar?opened?at?",?TimeToStr(daytimes[dayshift]));
int?ArrayDimension(?int?array[])?
返回數組的維數?
::?輸入參數
array[]?-?需要檢查的數組?
示例:
int?num_array[10][5];
int?dim_size;
dim_size=ArrayDimension(num_array);
//?dim_size?is?2
bool?ArrayGetAsSeries(object?array[])
檢查數組是否是有組織序列的數組(是否從最后到最開始排序過的),如果不是返回否?
::?輸入參數
array[]?-?需要檢查的數組?
示例:
if(ArrayGetAsSeries(array1)==true)
Print("array1?is?indexed?as?a?series?array");
else
Print("array1?is?indexed?normally?(from?left?to?right)");
int?ArrayInitialize(?double&?array[],?double?value)
對數組進行初始化,返回經過初始化的數組項的個數?
::?輸入參數
array[]?-?需要初始化的數組
value?-?新的數組項的值?
示例:
//----?把所有數組項的值設置為2.1
double?myarray[10];
ArrayInitialize(myarray,2.1);
bool?ArrayIsSeries(?object?array[])?
檢查數組是否連續的(time,open,close,high,low,?or?volume).?
::?輸入參數
array[]?-?需要檢查的數組?
示例:
if(ArrayIsSeries(array1)==false)
ArrayInitialize(array1,0);
else
{
Print("Series?array?cannot?be?initialized!");
return(-1);
}
int?ArrayMaximum(?double?array[],?int?count=WHOLE_ARRAY,?int?start=0)?
找出數組中最大值的定位?
::?輸入參數
array[]?-?需要檢查的數組
count?-?搜索數組中項目的個數
start?-?搜索的開始點?
示例:
double?num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
int?maxValueIdx=ArrayMaximum(num_array);
Print("Max?value?=?",?num_array[maxValueIdx]);
int?ArrayMinimum(?double?array[],?int?count=WHOLE_ARRAY,?int?start=0)?
找出數組中最小值的定位?
::?輸入參數
array[]?-?需要檢查的數組
count?-?搜索數組中項目的個數
start?-?搜索的開始點?
示例:
double?num_array[15]={4,1,6,3,9,4,1,6,3,9,4,1,6,3,9};
double?minValueidx=ArrayMinimum(num_array);
Print("Min?value?=?",?num_array[minValueIdx]);
int?ArrayRange(?object?array[],?int?range_index)?
取數組中指定維數中項目的數量。?
::?輸入參數
array[]?-?需要檢查的數組
range_index?-?指定的維數?
示例:
int?dim_size;
double?num_array[10,10,10];
dim_size=ArrayRange(num_array,?1);
int?ArrayResize(?object&?array[],?int?new_size)?
重定義數組大小?
::?輸入參數
array[]?-?需要檢查的數組
new_size?-?第一維中數組的新大小?
示例:
double?array1[][4];
int?element_count=ArrayResize(array,?20);
//?數組中總項目數為80
bool?ArraySetAsSeries(?double&?array[],?bool?set)?
設置指數數組為系列數組,數組0位的值是最后的值。返回之前的數組狀態?
::?輸入參數
array[]?-?需要處理的數組
set?-?是否是設置為系列數組,true或者false?
示例:
double?macd_buffer[300];
double?signal_buffer[300];
int?i,limit=ArraySize(macd_buffer);
ArraySetAsSeries(macd_buffer,true);
for(i=0;?i
macd_buffer[i]=iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0;?i
signal_buffer[i]=iMAOnArray(macd_buffer,limit,9,0,MODE_SMA,i);
int?ArraySize(?object?array[])?
返回數組的項目數?
::?輸入參數
array[]?-?需要處理的數組?
示例:
int?count=ArraySize(array1);
for(int?i=0;?i
{
//?do?some?calculations.
}
int?ArraySort(?double&?array[],?int?count=WHOLE_ARRAY,?int?start=0,?int?sort_dir=MODE_ASCEND)?
對數組進行排序,系列數組不可進行排序?
::?輸入參數
array[]?-?需要處理的數組
count?-?對多少個數組項進行排序
start?-?排序的開始點
sort_dir?-?排序方式,MODE_ASCEND順序排列?MODE_DESCEND倒序排列?
示例:
double?num_array[5]={4,1,6,3,9};
//?now?array?contains?values?4,1,6,3,9
ArraySort(num_array);
//?now?array?is?sorted?1,3,4,6,9
ArraySort(num_array,MODE_DESCEND);
//?now?array?is?sorted?9,6,4,3,1
類型轉換函數?[Conversion?Functions]
string?CharToStr(?int?char_code)?
將字符型轉換成字符串型結果返回
::?輸入參數
char_code?-?字符的ACSII碼?
示例:
string?str="WORL"?+?CharToStr(44);?//?44?is?code?for?'D'
//?resulting?string?will?be?WORLD
string?DoubleToStr(?double?value,?int?digits)
將雙精度浮點型轉換成字符串型結果返回?
::?輸入參數
value?-?浮點型數字
digits?-?小數點后多少位,0-8?
示例:
string?value=DoubleToStr(1.28473418,?5);
//?value?is?1.28473
double?NormalizeDouble(?double?value,?int?digits)?
將雙精度浮點型格式化后結果返回?
::?輸入參數
value?-?浮點型數字
digits?-?小數點后多少位,0-8?
示例:
double?var1=0.123456789;
Print(NormalizeDouble(var1,5));
//?output:?0.12346
double?StrToDouble(?string?value)
將字符串型轉換成雙精度浮點型結果返回?
::?輸入參數
value?-?數字的字符串?
示例:
double?var=StrToDouble("103.2812");
int?StrToInteger(?string?value)
將字符串型轉換成整型結果返回?
::?輸入參數
value?-?數字的字符串?
示例:
int?var1=StrToInteger("1024");
datetime?StrToTime(?string?value)?
將字符串型轉換成時間型結果返回,輸入格式為?yyyy.mm.dd?hh:mi?
::?輸入參數
value?-?時間的字符串?
示例:
datetime?var1;
var1=StrToTime("2003.8.12?17:35");
var1=StrToTime("17:35");?//?returns?with?current?date
var1=StrToTime("2003.8.12");?//?returns?with?midnight?time?"00:00"
string?TimeToStr(?datetime?value,?int?mode=TIME_DATE|TIME_MINUTES)
將時間型轉換成字符串型返回?
::?輸入參數
value?-?時間的數字,從1970.1.1?0:0:0?到現在的秒數
mode?-?返回字符串的格式?TIME_DATE(yyyy.mm.dd),TIME_MINUTES(hh:mi),TIME_SECONDS(hh:mi:ss)?
示例:
strign?var1=TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS);
公用函數?[Common?Functions]
void?Alert(?...?)?
彈出一個顯示信息的警告窗口
::?輸入參數
...?-?任意值,如有多個可用逗號分割?
示例:
if(Close[0]>SignalLevel)
Alert("Close?price?coming?",?Close[0],"!!!");
string?ClientTerminalName()
返回客戶終端名稱
示例:
Print("Terminal?name?is?",ClientTerminalName());
string?CompanyName()
返回公司名稱
示例:
Print("Company?name?is?",CompanyName());
void?Comment(?...?)
顯示信息在走勢圖左上角?
::?輸入參數
...?-?任意值,如有多個可用逗號分割?
示例:
double?free=AccountFreeMargin();
Comment("Account?free?margin?is?",DoubleToStr(free,2),"\n","Current?time?is?",TimeToStr(CurTime()));
int?GetLastError()
取最后錯誤在錯誤中的索引位置
示例:
int?err;
int?handle=FileOpen("somefile.dat",?FILE_READ|FILE_BIN);
if(handle<1)
{
err=GetLastError();
Print("error(",err,"):?",ErrorDescription(err));
return(0);
}
int?GetTickCount()
取時間標記,函數取回用毫秒標示的時間標記。
示例:
int?start=GetTickCount();
//?do?some?hard?calculation...
Print("Calculation?time?is?",?GetTickCount()-start,?"?milliseconds.");
void?HideTestIndicators(bool?hide)
使用此函數設置一個在Expert?Advisor的開關,在測試完成之前指標不回顯示在圖表上。?
::?輸入參數
hide?-?是否隱藏?True或者False?
示例:
HideTestIndicators(true);
bool?IsConnected()
返回客戶端是否已連接
示例:
if(!IsConnected())
{
Print("Connection?is?broken!");
return(0);
}
//?Expert?body?that?need?opened?connection
//?...
bool?IsDemo()
返回是否是模擬賬戶
示例:
if(IsDemo())?Print("I?am?working?on?demo?account");
else?Print("I?am?working?on?real?account");
bool?IsDllsAllowed()
返回是否允許載入Dll文件
示例:
#import?"user32.dll"
int?MessageBoxA(int?hWnd?,string?szText,?string?szCaption,int?nType);
...
...
if(IsDllsAllowed()==false)
{
Print("DLL?call?is?not?allowed.?Experts?cannot?run.");
return(0);
}
//?expert?body?that?calls?external?DLL?functions
MessageBoxA(0,"an?message","Message",MB_OK);
bool?IsLibrariesAllowed()
返回是否允許載入庫文件
示例:
#import?"somelibrary.ex4"
int?somefunc();
...
...
if(IsLibrariesAllowed()==false)
{
Print("Library?call?is?not?allowed.?Experts?cannot?run.");
return(0);
}
//?expert?body?that?calls?external?DLL?functions
somefunc();
bool?IsStopped()
返回是否處于停止狀態
示例:
while(expr!=false)
{
if(IsStopped()==true)?return(0);
//?long?time?procesing?cycle
//?...
}
bool?IsTesting()
返回是否處于測試模式
示例:
if(IsTesting())?Print("I?am?testing?now");
bool?IsTradeAllowed()
返回是否允許交易
示例:
if(IsTradeAllowed())?Print("Trade?allowed");
double?MarketInfo(?string?symbol,?int?type)
返回市場當前情況?
::?輸入參數
symbol?-?通貨代碼
type?-?返回結果的類型?
示例:
double?var;
var=MarketInfo("EURUSD",MODE_BID);
int?MessageBox(?string?text=NULL,?string?caption=NULL,?int?flags=EMPTY)?
彈出消息窗口,返回消息窗口的結果?
::?輸入參數
text?-?窗口顯示的文字
caption?-?窗口上顯示的標題
flags?-?窗口選項開關?
示例:
#include?
if(ObjectCreate("text_object",?OBJ_TEXT,?0,?D'2004.02.20?12:30',?1.0045)==false)
{
int?ret=MessageBox("ObjectCreate()?fails?with?code?"+GetLastError()+"\nContinue?",?"Question",?MB_YESNO|MB_ICONQUESTION);
if(ret==IDNO)?return(false);
}
//?continue
int?Period()
返回圖表時間線的類型
示例:
Print("Period?is?",?Period());
void?PlaySound(?string?filename)
播放音樂文件?
::?輸入參數
filename?-?音頻文件名?
示例:
if(IsDemo())?PlaySound("alert.wav");
void?Print(?...?)
將文本打印在結果窗口內?
::?輸入參數
...?-?任意值,復數用逗號分割?
示例:
Print("Account?free?margin?is?",?AccountFreeMargin());
Print("Current?time?is?",?TimeToStr(CurTime()));
double?pi=3.141592653589793;
Print("PI?number?is?",?DoubleToStr(pi,8));
//?Output:?PI?number?is?3.14159265
//?Array?printing
for(int?i=0;i<10;i++)
Print(Close[i]);
bool?RefreshRates()
返回數據是否已經被刷新過了
示例:
int?ticket;
while(true)
{
ticket=OrderSend(Symbol(),OP_BUY,1.0,Ask,3,0,0,"expert?comment",255,0,CLR_NONE);
if(ticket<=0)
{
int?error=GetLastError();
if(error==134)?break;?//?not?enough?money
if(error==135)?RefreshRates();?//?prices?changed
break;
}
else?{?OrderPrint();?break;?}
//----?10?seconds?wait
Sleep(10000);
}
void?SendMail(?string?subject,?string?some_text)
發送郵件到指定信箱,需要到菜單?Tools?->?Options?->?Email?中將郵件打開.?
::?輸入參數
subject?-?郵件標題
some_text?-?郵件內容?
示例:
double?lastclose=Close[0];
if(lastclose<MY_SIGNAL)
SendMail("from?your?expert",?"Price?dropped?down?to?"+DoubleToStr(lastclose));
string?ServerAddress()
返回服務器地址
示例:
Print("Server?address?is?",?ServerAddress());
void?Sleep(?int?milliseconds)
設置線程暫停時間?
::?輸入參數
milliseconds?-?暫停時間?1000?=?1秒?
示例:
Sleep(5);
void?SpeechText(?string?text,?int?lang_mode=SPEECH_ENGLISH)
使用Speech進行語音輸出?
::?輸入參數
text?-?閱讀的文字
lang_mode?-?語音模式?SPEECH_ENGLISH?(默認的)?或?SPEECH_NATIVE?
示例:
double?lastclose=Close[0];
SpeechText("Price?dropped?down?to?"+DoubleToStr(lastclose));
string?Symbol()
返回當前當前通貨的名稱
示例:
int?total=OrdersTotal();
for(int?pos=0;pos<TOTAL;POS++)
{
//?check?selection?result?becouse?order?may?be?closed?or?deleted?at?this?time!
if(OrderSelect(pos,?SELECT_BY_POS)==false)?continue;
if(OrderType()>OP_SELL?||?OrderSymbol()!=Symbol())?continue;
//?do?some?orders?processing...
}
int?UninitializeReason()
取得程序末初始化的理由
示例:
//?this?is?example
int?deinit()
{
switch(UninitializeReason())
{
case?REASON_CHARTCLOSE:
case?REASON_REMOVE:?CleanUp();?break;?//?clean?up?and?free?all?expert's?resources.
case?REASON_RECOMPILE:
case?REASON_CHARTCHANGE:
case?REASON_PARAMETERS:
case?REASON_ACCOUNT:?StoreData();?break;?//?prepare?to?restart
}
//...
}
自定義指標函數?[Custom?Indicator?Functions]
void?IndicatorBuffers(int?count)
設置自定義指標緩存數
::?輸入參數
count?-?緩存數量?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
int?IndicatorCounted()
返回緩存數量
示例:
int?start()
{
int?limit;
int?counted_bars=IndicatorCounted();
//----?check?for?possible?errors
if(counted_bars<0)?return(-1);
//----?last?counted?bar?will?be?recounted
if(counted_bars>0)?counted_bars--;
limit=Bars-counted_bars;
//----?main?loop
for(int?i=0;?i
{
//----?ma_shift?set?to?0?because?SetIndexShift?called?abowe
ExtBlueBuffer[i]=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
ExtRedBuffer[i]=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
ExtLimeBuffer[i]=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);
}
//----?done
return(0);
}
void?IndicatorDigits(?int?digits)
設置指標精確度?
::?輸入參數
digits?-?小數點后的小數位數?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
void?IndicatorShortName(?string?name)
設置指標的簡稱?
::?輸入參數
name?-?新的簡稱?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
void?SetIndexArrow(?int?index,?int?code)
在指標上設置一個箭頭符號?
::?輸入參數
index?-?第幾根指標線?0-7
code?-?符號的編碼,參照?Wingdings?字體?
示例:
SetIndexArrow(0,?217);
bool?SetIndexBuffer(?int?index,?double?array[])
設置指標線的緩存數組?
::?輸入參數
index?-?第幾根指標線?0-7
array[]?-?緩存的數組?
示例:
double?ExtBufferSilver[];
int?init()
{
SetIndexBuffer(0,?ExtBufferSilver);?//?set?buffer?for?first?line
//?...
}
void?SetIndexDrawBegin(?int?index,?int?begin)
設置劃線的開始點?
::?輸入參數
index?-?第幾根指標線?0-7
begin?-?劃線的開始點?
示例:
#property?indicator_separate_window
#property?indicator_buffers?1
#property?indicator_color1?Silver
//----?indicator?parameters
extern?int?FastEMA=12;
extern?int?SlowEMA=26;
extern?int?SignalSMA=9;
//----?indicator?buffers
double?ind_buffer1[];
double?ind_buffer2[];
double?ind_buffer3[];
//+------------------------------------------------------------------+
//|?Custom?indicator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?2?additional?buffers?are?used?for?counting.
IndicatorBuffers(3);
//----?drawing?settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//----?name?for?DataWindow?and?indicator?subwindow?label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//----?initialization?done
return(0);
}
void?SetIndexEmptyValue(?int?index,?double?value)?
設置劃線的空值,空值不劃在和出現在數據窗口?
::?輸入參數
index?-?第幾根指標線?0-7
value?-?新的空值?
示例:
SetIndexEmptyValue(6,0.0001);
void?SetIndexLabel(?int?index,?string?text)?
設置指標線的名稱?
::?輸入參數
index?-?第幾根指標線?0-7
text?-?線的名稱,Null不會顯示在數據窗口中?
示例:
//+------------------------------------------------------------------+
//|?Ichimoku?Kinko?Hyo?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,Tenkan_Buffer);
SetIndexDrawBegin(0,Tenkan-1);
SetIndexLabel(0,"Tenkan?Sen");
//----
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,Kijun_Buffer);
SetIndexDrawBegin(1,Kijun-1);
SetIndexLabel(1,"Kijun?Sen");
//----
a_begin=Kijun;?if(a_begin?SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT);
SetIndexBuffer(2,SpanA_Buffer);
SetIndexDrawBegin(2,Kijun+a_begin-1);
SetIndexShift(2,Kijun);
//----?Up?Kumo?bounding?line?does?not?show?in?the?DataWindow
SetIndexLabel(2,NULL);
SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(5,SpanA2_Buffer);
SetIndexDrawBegin(5,Kijun+a_begin-1);
SetIndexShift(5,Kijun);
SetIndexLabel(5,"Senkou?Span?A");
//----
SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT);
SetIndexBuffer(3,SpanB_Buffer);
SetIndexDrawBegin(3,Kijun+Senkou-1);
SetIndexShift(3,Kijun);
//----?Down?Kumo?bounding?line?does?not?show?in?the?DataWindow
SetIndexLabel(3,NULL);
//----
SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
SetIndexBuffer(6,SpanB2_Buffer);
SetIndexDrawBegin(6,Kijun+Senkou-1);
SetIndexShift(6,Kijun);
SetIndexLabel(6,"Senkou?Span?B");
//----
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,Chinkou_Buffer);
SetIndexShift(4,-Kijun);
SetIndexLabel(4,"Chinkou?Span");
//----
return(0);
}
void?SetIndexShift(?int?index,?int?shift)
設置指標線的位移數?
::?輸入參數
index?-?第幾根指標線?0-7
shift?-?位移多少?
示例:
//+------------------------------------------------------------------+
//|?Alligator?initialization?function?|
//+------------------------------------------------------------------+
int?init()
{
//----?line?shifts?when?drawing
SetIndexShift(0,JawsShift);
SetIndexShift(1,TeethShift);
SetIndexShift(2,LipsShift);
//----?first?positions?skipped?when?drawing
SetIndexDrawBegin(0,JawsShift+JawsPeriod);
SetIndexDrawBegin(1,TeethShift+TeethPeriod);
SetIndexDrawBegin(2,LipsShift+LipsPeriod);
//----?3?indicator?buffers?mapping
SetIndexBuffer(0,ExtBlueBuffer);
SetIndexBuffer(1,ExtRedBuffer);
SetIndexBuffer(2,ExtLimeBuffer);
//----?drawing?settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
//----?index?labels
SetIndexLabel(0,"Gator?Jaws");
SetIndexLabel(1,"Gator?Teeth");
SetIndexLabel(2,"Gator?Lips");
//----?initialization?done
return(0);
}
void?SetIndexStyle(?int?index,?int?type,?int?style=EMPTY,?int?width=EMPTY,?color?clr=CLR_NONE)?
設置指標線的樣式?
::?輸入參數
index?-?第幾根指標線?0-7
type?-?線形狀的種類,詳見線條種類
style?-?劃線的樣式
width?-?顯得寬度(1,2,3,4,5)
clr?-?線的顏色?
示例:
SetIndexStyle(3,?DRAW_LINE,?EMPTY,?2,?Red);
日期時間函數?[Date?&?Time?Functions]
datetime?CurTime(?)
返回當前時間
示例:
if(CurTime()-OrderOpenTime()<360)?return(0);
int?Day()
返回當前日期
示例:
if(Day()<5)?return(0);
int?DayOfWeek(?)
返回當前日期是星期幾?0-星期天,1,2,3,4,5,6
示例:
//?do?not?work?on?holidays.
if(DayOfWeek()==0?||?DayOfWeek()==6)?return(0);
int?DayOfYear(?)
返回當前日期在年內的第幾天
示例:
if(DayOfYear()==245)
return(true);
int?Hour()
返回當前的小時數?0-23
示例:
bool?is_siesta=false;
if(Hour()>=12?||?Hour()<17)
is_siesta=true;
datetime?LocalTime()
返回當前電腦時間
示例:
if(LocalTime()-OrderOpenTime()<360)?return(0);
int?Minute()
返回當前分鐘
示例:
if(Minute()<=15)
return("first?quarter");
int?Month()
返回當前月份
示例:
if(Month()<=5)
return("first?half?of?year");
int?Seconds()
返回當前秒數
示例:
if(Seconds()<=15)
return(0);
int?TimeDay(?datetime?date)
返回輸入日期中的日期?
::?輸入參數
date?-?輸入日期?
示例:
int?day=TimeDay(D'2003.12.31');
//?day?is?31
int?TimeDayOfWeek(?datetime?date)
返回輸入日期中的日期是星期幾?(0-6)?
::?輸入參數
date?-?輸入日期?
示例:
int?weekday=TimeDayOfWeek(D'2004.11.2');
//?day?is?2?-?tuesday
int?TimeDayOfYear(?datetime?date)
返回輸入日期中的日期在當年中的第幾天?
::?輸入參數
date?-?輸入日期?
示例:
int?day=TimeDayOfYear(CurTime());
int?TimeHour(?datetime?time)
返回輸入日期中的小時?
::?輸入參數
date?-?輸入日期?
示例:
int?h=TimeHour(CurTime());
int?TimeMinute(?datetime?time)
返回輸入日期中的分鐘?
::?輸入參數
date?-?輸入日期?
示例:
int?m=TimeMinute(CurTime());
int?TimeMonth(?datetime?time)
返回輸入日期中的月份?
::?輸入參數
date?-?輸入日期?
示例:
int?m=TimeMonth(CurTime());
int?TimeSeconds(?datetime?time)
返回輸入日期中的秒鐘?
::?輸入參數
date?-?輸入日期?
示例:
int?m=TimeSeconds(CurTime());
int?TimeYear(?datetime?time)
返回輸入日期中的年份?
::?輸入參數
date?-?輸入日期?
示例:
int?y=TimeYear(CurTime());
int?TimeYear(?datetime?time)
返回當前年份
示例:
//?return?if?date?before?1?May?2002
if(Year()==2002?&&?Month()<5)
return(0);
文件處理函數?[File?Functions]
void?FileClose(int?handle)
關閉正在已經打開的文件.
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle=FileOpen("filename",?FILE_CSV|FILE_READ);
if(handle>0)
{
//?working?with?file?...
FileClose(handle);
}
void?FileDelete(string?filename)
刪除文件,如果發生錯誤可以通過GetLastError()來查詢
注:你只能操作terminal_dir\experts\files目錄下的文件?
::?輸入參數
filename?-?目錄和文件名?
示例:
//?file?my_table.csv?will?be?deleted?from?terminal_dir\experts\files?directory
int?lastError;
FileDelete("my_table.csv");
lastError=GetLastError();
if(laseError!=ERR_NOERROR)
{
Print("An?error?ocurred?while?(",lastError,")?deleting?file?my_table.csv");
return(0);
}
void?FileFlush(int?handle)
將緩存中的數據刷新到磁盤上去?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?bars_count=Bars;
int?handle=FileOpen("mydat.csv",FILE_CSV|FILE_WRITE);
if(handle>0)
{
FileWrite(handle,?"#","OPEN","CLOSE","HIGH","LOW");
for(int?i=0;i<BARS_COUNT;I++)
FileWrite(handle,?i+1,Open[i],Close[i],High[i],?Low[i]);
FileFlush(handle);
...
for(int?i=0;i<BARS_COUNT;I++)
FileWrite(handle,?i+1,Open[i],Close[i],High[i],?Low[i]);
FileClose(handle);
}
bool?FileIsEnding(int?handle)
檢查是否到了文件尾.?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
if(FileIsEnding(h1))
{
FileClose(h1);
return(false);
}
bool?FileIsLineEnding(?int?handle)
檢查行是否到了結束?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
if(FileIsLineEnding(h1))
{
FileClose(h1);
return(false);
}
int?FileOpen(?string?filename,?int?mode,?int?delimiter=';')
打開文件,如果失敗返回值小于1,可以通過GetLastError()獲取錯誤
注:只能操作terminal_dir\experts\files目錄的文件?
::?輸入參數
filename?-?目錄文件名
mode?-?打開模式?FILE_BIN,?FILE_CSV,?FILE_READ,?FILE_WRITE.?
delimiter?-?CSV型打開模式用的分割符,默認為分號(;).?
示例:
int?handle;
handle=FileOpen("my_data.csv",FILE_CSV|FILE_READ,';');
if(handle<1)
{
Print("File?my_data.dat?not?found,?the?last?error?is?",?GetLastError());
return(false);
}
int?FileOpenHistory(?string?filename,?int?mode,?int?delimiter=';')
打開歷史數據文件,如果失敗返回值小于1,可以通過GetLastError()獲取錯誤?
::?輸入參數
filename?-?目錄文件名
mode?-?打開模式?FILE_BIN,?FILE_CSV,?FILE_READ,?FILE_WRITE.?
delimiter?-?CSV型打開模式用的分割符,默認為分號(;).?
示例:
int?handle=FileOpenHistory("USDX240.HST",FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("Cannot?create?file?USDX240.HST");
return(false);
}
//?work?with?file
//?...
FileClose(handle);
int?FileReadArray(?int?handle,?object&?array[],?int?start,?int?count)
將二進制文件讀取到數組中,返回讀取的條數,可以通過GetLastError()獲取錯誤
注:在讀取之前要調整好數組大小?
::?輸入參數
handle?-?FileOpen()返回的句柄
array[]?-?寫入的數組
start?-?在數組中存儲的開始點
count?-?讀取多少個對象?
示例:
int?handle;
double?varray[10];
handle=FileOpen("filename.dat",?FILE_BIN|FILE_READ);
if(handle>0)
{
FileReadArray(handle,?varray,?0,?10);
FileClose(handle);
}
double?FileReadDouble(?int?handle,?int?size=DOUBLE_VALUE)
從文件中讀取浮點型數據,數字可以是8byte的double型或者是4byte的float型。?
::?輸入參數
handle?-?FileOpen()返回的句柄
size?-?數字個是大小,DOUBLE_VALUE(8?bytes)?或者?FLOAT_VALUE(4?bytes).?
示例:
int?handle;
double?value;
handle=FileOpen("mydata.dat",FILE_BIN);
if(handle>0)
{
value=FileReadDouble(handle,DOUBLE_VALUE);
FileClose(handle);
}
int?FileReadInteger(?int?handle,?int?size=LONG_VALUE)
從文件中讀取整形型數據,數字可以是1,2,4byte的長度?
::?輸入參數
handle?-?FileOpen()返回的句柄
size?-?數字個是大小,CHAR_VALUE(1?byte),?SHORT_VALUE(2?bytes)?或者?LONG_VALUE(4?bytes).?
示例:
int?handle;
int?value;
handle=FileOpen("mydata.dat",?FILE_BIN|FILE_READ);
if(handle>0)
{
value=FileReadInteger(h1,2);
FileClose(handle);
}
double?FileReadNumber(?int?handle)
從文件中讀取數字,只能在CSV里使用?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle;
int?value;
handle=FileOpen("filename.csv",?FILE_CSV,?';');
if(handle>0)
{
value=FileReadNumber(handle);
FileClose(handle);
}
string?FileReadString(?int?handle,?int?length=0)
從文件中讀取字符串?
::?輸入參數
handle?-?FileOpen()返回的句柄
length?-?讀取字符串長度?
示例:
int?handle;
string?str;
handle=FileOpen("filename.csv",?FILE_CSV|FILE_READ);
if(handle>0)
{
str=FileReadString(handle);
FileClose(handle);
}
bool?FileSeek(?int?handle,?int?offset,?int?origin)
移動指針移動到某一點,如果成功返回true?
::?輸入參數
handle?-?FileOpen()返回的句柄
offset?-?設置的原點
origin?-?SEEK_CUR從當前位置開始?SEEK_SET從文件頭部開始?SEEK_END?從文件尾部開始?
示例:
int?handle=FileOpen("filename.csv",?FILE_CSV|FILE_READ,?';');
if(handle>0)
{
FileSeek(handle,?10,?SEEK_SET);
FileReadInteger(handle);
FileClose(handle);
handle=0;
}
int?FileSize(?int?handle)
返回文件大小?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle;
int?size;
handle=FileOpen("my_table.dat",?FILE_BIN|FILE_READ);
if(handle>0)
{
size=FileSize(handle);
Print("my_table.dat?size?is?",?size,?"?bytes");
FileClose(handle);
}
int?FileTell(?int?handle)
返回文件讀寫指針當前的位置?
::?輸入參數
handle?-?FileOpen()返回的句柄?
示例:
int?handle;
int?pos;
handle=FileOpen("my_table.dat",?FILE_BIN|FILE_READ);
//?reading?some?data
pos=FileTell(handle);
Print("current?position?is?",?pos);
int?FileWrite(?int?handle,?...?)
向文件寫入數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
...?-?寫入的數據?
示例:
int?handle;
datetime?orderOpen=OrderOpenTime();
handle=FileOpen("filename",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
FileWrite(handle,?Close[0],?Open[0],?High[0],?Low[0],?TimeToStr(orderOpen));
FileClose(handle);
}
int?FileWriteArray(?int?handle,?object?array[],?int?start,?int?count)
向文件寫入數組?
::?輸入參數
handle?-?FileOpen()返回的句柄
array[]?-?要寫入的數組
start?-?寫入的開始點
count?-?寫入的項目數?
示例:
int?handle;
double?BarOpenValues[10];
//?copy?first?ten?bars?to?the?array
for(int?i=0;i<10;?i++)
BarOpenValues[i]=Open[i];
//?writing?array?to?the?file
handle=FileOpen("mydata.dat",?FILE_BIN|FILE_WRITE);
if(handle>0)
{
FileWriteArray(handle,?BarOpenValues,?3,?7);?//?writing?last?7?elements
FileClose(handle);
}
int?FileWriteDouble(?int?handle,?double?value,?int?size=DOUBLE_VALUE)
向文件寫入浮點型數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
value?-?要寫入的值
size?-?寫入的格式,DOUBLE_VALUE?(8?bytes,?default)或FLOAT_VALUE?(4?bytes).?
示例:
int?handle;
double?var1=0.345;
handle=FileOpen("mydata.dat",?FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("can't?open?file?error-",GetLastError());
return(0);
}
FileWriteDouble(h1,?var1,?DOUBLE_VALUE);
//...
FileClose(handle);
int?FileWriteInteger(?int?handle,?int?value,?int?size=LONG_VALUE)
向文件寫入整型數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
value?-?要寫入的值
size?-?寫入的格式,CHAR_VALUE?(1?byte),SHORT_VALUE?(2?bytes),LONG_VALUE?(4?bytes,?default).?
示例:
int?handle;
int?value=10;
handle=FileOpen("filename.dat",?FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("can't?open?file?error-",GetLastError());
return(0);
}
FileWriteInteger(handle,?value,?SHORT_VALUE);
//...
FileClose(handle);
int?FileWriteString(?int?handle,?string?value,?int?length)
向文件寫入字符串數據?
::?輸入參數
handle?-?FileOpen()返回的句柄
value?-?要寫入的值
length?-?寫入的字符長度?
示例:
int?handle;
string?str="some?string";
handle=FileOpen("filename.bin",?FILE_BIN|FILE_WRITE);
if(handle<1)
{
Print("can't?open?file?error-",GetLastError());
return(0);
}
FileWriteString(h1,?str,?8);
FileClose(handle);
全局變量函數?[Global?Variables?Functions]
bool?GlobalVariableCheck(?string?name)
檢查全局變量是否存在
::?輸入參數
name?-?全局變量的名稱?
示例:
//?check?variable?before?use
if(!GlobalVariableCheck("g1"))
GlobalVariableSet("g1",1);
bool?GlobalVariableDel(?string?name)?
刪除全局變量?
::?輸入參數
name?-?全局變量的名稱?
示例:
//?deleting?global?variable?with?name?"gvar_1"
GlobalVariableDel("gvar_1");
double?GlobalVariableGet(?string?name)
獲取全局變量的值?
::?輸入參數
name?-?全局變量的名稱?
示例:
double?v1=GlobalVariableGet("g1");
//----?check?function?call?result
if(GetLastError()!=0)?return(false);
//----?continue?processing
double?GlobalVariableGet(?string?name)
獲取全局變量的值?
::?輸入參數
name?-?全局變量的名稱?
示例:
double?v1=GlobalVariableGet("g1");
//----?check?function?call?result
if(GetLastError()!=0)?return(false);
//----?continue?processing
datetime?GlobalVariableSet(?string?name,?double?value?)
設置全局變量的值?
::?輸入參數
name?-?全局變量的名稱
value?-?全局變量的值?
示例:
//----?try?to?set?new?value
if(GlobalVariableSet("BarsTotal",Bars)==0)
return(false);
//----?continue?processing
bool?GlobalVariableSetOnCondition(?string?name,?double?value,?double?check_value)
有條件的設置全局變量的值?
::?輸入參數
name?-?全局變量的名稱
value?-?全局變量的值
check_value?-?檢查變量的值?
示例:
int?init()
{
//----?create?global?variable
GlobalVariableSet("DATAFILE_SEM",0);
//...
}?
int?start()
{
//----?try?to?lock?common?resource
while(!IsStopped())
{
//----?locking
if(GlobalVariableSetOnCondition("DATAFILE_SEM",1,0)==true)?break;
//----?may?be?variable?deleted?
if(GetLastError()==ERR_GLOBAL_VARIABLE_NOT_FOUND)?return(0);
//----?sleeping
Sleep(500);
}
//----?resource?locked
//?...?do?some?work
//----?unlock?resource
GlobalVariableSet("DATAFILE_SEM",0);
}
void?GlobalVariablesDeleteAll(?)?
刪除所有全局變量
示例:
GlobalVariablesDeleteAll();
數學運算函數?[Math?&?Trig]
double?MathAbs(?double?value)?
返回數字的絕對值
::?輸入參數
value?-?要處理的數字?
示例:
double?dx=-3.141593,?dy;
//?calc?MathAbs
dy=MathAbs(dx);
Print("The?absolute?value?of?",dx,"?is?",dy);
//?Output:?The?absolute?value?of?-3.141593?is?3.141593
double?MathArccos(?double?x)
計算反余弦值?
::?輸入參數
value?-?要處理的數字,范圍-1到1?
示例:
double?x=0.32696,?y;
y=asin(x);
Print("Arcsine?of?",x,"?=?",y);
y=acos(x);
Print("Arccosine?of?",x,"?=?",y);
//Output:?Arcsine?of?0.326960=0.333085
//Output:?Arccosine?of?0.326960=1.237711
double?MathArcsin(?double?x)?
計算反正弦值?
::?輸入參數
x?-?要處理的值?
示例:
double?x=0.32696,?y;
y=MathArcsin(x);
Print("Arcsine?of?",x,"?=?",y);
y=acos(x);
Print("Arccosine?of?",x,"?=?",y);
//Output:?Arcsine?of?0.326960=0.333085
//Output:?Arccosine?of?0.326960=1.237711
double?MathArctan(?double?x)
計算反正切值?
::?輸入參數
x?-?要處理的值?
示例:
double?x=-862.42,?y;
y=MathArctan(x);
Print("Arctangent?of?",x,"?is?",y);
//Output:?Arctangent?of?-862.42?is?-1.5696
double?MathCeil(?double?x)
返回向前進位后的值?
::?輸入參數
x?-?要處理的值?
示例:
double?y;
y=MathCeil(2.8);
Print("The?ceil?of?2.8?is?",y);
y=MathCeil(-2.8);
Print("The?ceil?of?-2.8?is?",y);
/*Output:
The?ceil?of?2.8?is?3
The?ceil?of?-2.8?is?-2*/
double?MathCos(?double?value)
計算余弦值?
::?輸入參數
value?-?要處理的值?
示例:
double?pi=3.1415926535;
double?x,?y;
x=pi/2;
y=MathSin(x);
Print("MathSin(",x,")?=?",y);
y=MathCos(x);
Print("MathCos(",x,")?=?",y);
//Output:?MathSin(1.5708)=1
//?MathCos(1.5708)=0
double?MathExp(?double?d)
Returns?value?the?number?e?raised?to?the?power?d.?On?overflow,?the?function?returns?INF?(infinite)?and?on?underflow,?MathExp?returns?0.?
::?輸入參數
d?-?A?number?specifying?a?power.?
示例:
double?x=2.302585093,y;
y=MathExp(x);
Print("MathExp(",x,")?=?",y);
//Output:?MathExp(2.3026)=10
double?MathFloor(?double?x)
返回向后進位后的值?
::?輸入參數
x?-?要處理的值?
示例:
double?y;
y=MathFloor(2.8);
Print("The?floor?of?2.8?is?",y);
y=MathFloor(-2.8);
Print("The?floor?of?-2.8?is?",y);
/*Output:
The?floor?of?2.8?is?2
The?floor?of?-2.8?is?-3*/
double?MathLog(?double?x)
計算對數?
::?輸入參數
x?-?要處理的值?
示例:
double?x=9000.0,y;
y=MathLog(x);
Print("MathLog(",x,")?=?",?y);
//Output:?MathLog(9000)=9.10498
double?MathMax(?double?value1,?double?value2)?
計算兩個值中的最大值?
::?輸入參數
value1?-?第一個值?
value2?-?第二個值?
示例:
double?result=MathMax(1.08,Bid);
double?MathMin(?double?value1,?double?value2)?
計算兩個值中的最小值?
::?輸入參數
value1?-?第一個值?
value2?-?第二個值?
示例:
double?result=MathMin(1.08,Ask);
double?MathMod(?double?value,?double?value2)?
計算兩個值相除的余數?
::?輸入參數
value?-?被除數?
value2?-?除數?
示例:
double?x=-10.0,y=3.0,z;
z=MathMod(x,y);
Print("The?remainder?of?",x,"?/?",y,"?is?",z);
//Output:?The?remainder?of?-10?/?3?is?-1
double?MathPow(?double?base,?double?exponent)
計算指數?
::?輸入參數
base?-?基數
exponent?-?指數?
示例:
double?x=2.0,y=3.0,z;
z=MathPow(x,y);
Printf(x,"?to?the?power?of?",y,"?is?",?z);
//Output:?2?to?the?power?of?3?is?8
int?MathRand(?)
取隨機數
示例:
MathSrand(LocalTime());
//?Display?10?numbers.
for(int?i=0;i<10;i++?)
Print("random?value?",?MathRand());
double?MathRound(?double?value)?
取四舍五入的值?
::?輸入參數
value?-?要處理的值?
示例:
double?y=MathRound(2.8);
Print("The?round?of?2.8?is?",y);
y=MathRound(2.4);
Print("The?round?of?-2.4?is?",y);
//Output:?The?round?of?2.8?is?3
//?The?round?of?-2.4?is?-2
double?MathSin(?double?value)
計算正弦數?
::?輸入參數
value?-?要處理的值?
示例:
double?pi=3.1415926535;
double?x,?y;
x=pi/2;
y=MathSin(x);
Print("MathSin(",x,")?=?",y);
y=MathCos(x);
Print("MathCos(",x,")?=?",y);
//Output:?MathSin(1.5708)=1
//?MathCos(1.5708)=0
double?MathSqrt(?double?x)
計算平方根?
::?輸入參數
x?-?要處理的值?
示例:
double?question=45.35,?answer;
answer=MathSqrt(question);
if(question<0)
Print("Error:?MathSqrt?returns?",answer,"?answer");
else
Print("The?square?root?of?",question,"?is?",?answer);
//Output:?The?square?root?of?45.35?is?6.73
void?MathSrand(?int?seed)
通過Seed產生隨機數?
::?輸入參數
seed?-?隨機數的種子?
示例:
MathSrand(LocalTime());
//?Display?10?numbers.
for(int?i=0;i<10;i++?)
Print("random?value?",?MathRand());
double?MathTan(?double?x)
計算正切值?
::?輸入參數
x?-?要計算的角度?
示例:
double?pi=3.1415926535;
double?x,y;
x=MathTan(pi/4);
Print("MathTan(",pi/4,"?=?",x);
//Output:?MathTan(0.7856)=1
物體函數?[Object?Functions]
bool?ObjectCreate(?string?name,?int?type,?int?window,?datetime?time1,?double?price1,?datetime?time2=0,?double?price2=0,?datetime?time3=0,?double?price3=0)
創建物件
::?輸入參數
name?-?物件名稱
type?-?物件類型.?
window?-?物件所在窗口的索引值
time1?-?時間點1
price1?-?價格點1
time2?-?時間點2
price2?-?價格點2
time3?-?時間點3
price3?-?價格點3?
示例:
//?new?text?object
if(!ObjectCreate("text_object",?OBJ_TEXT,?0,?D'2004.02.20?12:30',?1.0045))
{
Print("error:?can't?create?text_object!?code?#",GetLastError());
return(0);
}
//?new?label?object
if(!ObjectCreate("label_object",?OBJ_LABEL,?0,?0,?0))
{
Print("error:?can't?create?label_object!?code?#",GetLastError());
return(0);
}
ObjectSet("label_object",?OBJPROP_XDISTANCE,?200);
ObjectSet("label_object",?OBJPROP_YDISTANCE,?100);
bool?ObjectDelete(?string?name)?
刪除物件?
::?輸入參數
name?-?物件名稱?
示例:
ObjectDelete("text_object");
string?ObjectDescription(?string?name)?
返回物件描述?
::?輸入參數
name?-?物件名稱?
示例:
//?writing?chart's?object?list?to?the?file
int?handle,?total;
string?obj_name,fname;
//?file?name
fname="objlist_"+Symbol();
handle=FileOpen(fname,FILE_CSV|FILE_WRITE);
if(handle!=false)
{
total=ObjectsTotal();
for(int?i=-;i<TOTAL;I++)
{
obj_name=ObjectName(i);
FileWrite(handle,"Object?"+obj_name+"?description=?"+ObjectDescription(obj_name));
}
FileClose(handle);
}
int?ObjectFind(?string?name)?
尋找物件,返回物件的索引值?
::?輸入參數
name?-?物件名稱?
示例:
if(ObjectFind("line_object2")!=win_idx)?return(0);
double?ObjectGet(?string?name,?int?index)?
獲取物件的值?
::?輸入參數
name?-?物件名稱
index?-?取值屬性的索引?
示例:
color?oldColor=ObjectGet("hline12",?OBJPROP_COLOR);
string?ObjectGetFiboDescription(?string?name,?int?index)?
取物件的斐波納契數列地描述?
::?輸入參數
name?-?物件名稱
index?-?斐波納契數列的等級索引?
示例:
#include?
...
string?text;
for(int?i=0;i<32;i++)
{
text=ObjectGetFiboDescription(MyObjectName,i);
//----?check.?may?be?objects's?level?count?less?than?32
if(GetLastError()!=ERR_NO_ERROR)?break;
Print(MyObjectName,"level:?",i,"?description:?",text);
}
int?ObjectGetShiftByValue(?string?name,?double?value)?
取物件的位移值?
::?輸入參數
name?-?物件名稱
value?-?價格?
示例:
int?shift=ObjectGetShiftByValue("MyTrendLine#123",?1.34);
double?ObjectGetValueByShift(?string?name,?int?shift)?
取物件位移后的值?
::?輸入參數
name?-?物件名稱
shift?-?位移數?
示例:
double?price=ObjectGetValueByShift("MyTrendLine#123",?11);
bool?ObjectMove(?string?name,?int?point,?datetime?time1,?double?price1)?
移動物件?
::?輸入參數
name?-?物件名稱
point?-?調整的索引?
time1?-?新的時間?
price1?-?新的價格?
示例:
ObjectMove("MyTrend",?1,?D'2005.02.25?12:30',?1.2345);
string?ObjectName(?int?index)?
取物件名稱?
::?輸入參數
index?-?物件的索引?
示例:
int?obj_total=ObjectsTotal();
string?name;
for(int?i=0;i<OBJ_TOTAL;I++)
{
name=ObjectName(i);
Print(i,"Object?name?is?"?+?name);
}
int?ObjectsDeleteAll(?int?window,?int?type=EMPTY)?
刪除所有物件?
::?輸入參數
window?-?物件所在的窗口索引
type?-?刪除物件的類型?
示例:
ObjectsDeleteAll(2,?OBJ_HLINE);?//?removes?all?horizontal?line?objects?from?window?3?(index?2).
bool?ObjectSet(?string?name,?int?index,?double?value)?
設置物件的值?
::?輸入參數
name?-?物件的名稱
index?-?物件屬性的索引值?
value?-?新的屬性值?
示例:
//?moving?first?coord?to?last?bar?time
ObjectSet("MyTrend",?OBJPROP_TIME1,?Time[0]);
//?setting?second?fibo?level
ObjectSet("MyFibo",?OBJPROP_FIRSTLEVEL+1,?1.234);
//?setting?object?visibility.?object?will?be?shown?only?on?15?minute?and?1?hour?charts
ObjectSet("MyObject",?OBJPROP_TIMEFRAMES,?OBJ_PERIOD_M15?|?OBJ_PERIOD_H1);
bool?ObjectSetFiboDescription(?string?name,?int?index,?string?text)?
設置物件斐波納契數列的描述?
::?輸入參數
name?-?物件的名稱
index?-?物件斐波納契數列的索引值?
text?-?新的描述?
示例:
ObjectSetFiboDescription("MyFiboObject,2,"Second?line");
bool?ObjectSetText(?string?name,?string?text,?int?font_size,?string?font=NULL,?color?text_color=CLR_NONE)?
設置物件的描述?
::?輸入參數
name?-?物件的名稱
text?-?文本
font_size?-?字體大小?
font?-?字體名稱?
text_color?-?字體顏色?
示例:
ObjectSetText("text_object",?"Hello?world!",?10,?"Times?New?Roman",?Green);
void?ObjectsRedraw(?)?
重繪所有物件
示例:
ObjectsRedraw();
int?ObjectsTotal(?)?
取物件總數
示例:
int?obj_total=ObjectsTotal();
string?name;
for(int?i=0;i<OBJ_TOTAL;I++)
{
name=ObjectName(i);
Print(i,"Object?name?is?for?object?#",i,"?is?"?+?name);
}
int?ObjectType(?string?name)?
取物件類型?
::?輸入參數
name?-?物件的名稱?
示例:
if(ObjectType("line_object2")!=OBJ_HLINE)?return(0);
預定義變量?[Pre-defined?Variables]?
double?Ask
通貨的買入價
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,
"My?order?#2",3,D'2005.10.10?12:30',Red);
return;
}
int?Bars
返回圖表中的柱數
示例:
int?counter=1;
for(int?i=1;i<=Bars;i++)
{
Print(Close[i-1]);
}
double?Bid
通貨的賣價
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderSend("EURUSD",OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,
"My?order?#2",3,D'2005.10.10?12:30',Red);
return(0);
}
double?Close[]
返回指定索引位置的收盤價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",FILE_CSV|FILE_WRITE,';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
int?Digits
返回當前通貨的匯率小數位
示例:
Print(DoubleToStr(Close[i-1],?Digits));
double?High[]
返回指定索引位置的最高價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Low[]
返回指定索引位置的最低價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?";");
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Open[]
返回指定索引位置的開盤價格
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Point
返回當前圖表的點值
示例:
OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,Red);
datetime?Time[]
返回指定索引位置的時間
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?write?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
}
double?Volume[]
返回指定索引位置的成交量
示例:
int?handle,?bars=Bars;
handle=FileOpen("file.csv",?FILE_CSV|FILE_WRITE,?';');
if(handle>0)
{
//?write?table?columns?headers
FileWrite(handle,?"Time;Open;High;Low;Close;Volume");
//?erite?data
for(int?i=0;?i
FileWrite(handle,?Time[i],?Open[i],?High[i],?Low[i],?Close[i],?Volume[i]);
FileClose(handle);
)
字符串函數?[String?Functions]
string?StringConcatenate(?...?)?
字符串連接
::?輸入參數
...?-?任意值,用逗號分割?
示例:
string?text;
text=StringConcatenate("Account?free?margin?is?",?AccountFreeMargin(),?"Current?time?is?",?TimeToStr(CurTime()));
//?slow?text="Account?free?margin?is?"?+?AccountFreeMargin()?+?"Current?time?is?"?+?TimeToStr(CurTime())
Print(text);
int?StringFind(?string?text,?string?matched_text,?int?start=0)
在字符串中尋找符合條件的字符串返回索引位置?
::?輸入參數
text?-?被搜索的字符串?
matched_text?-?需要搜索的字符串
start?-?搜索開始索引位置?
示例:
string?text="The?quick?brown?dog?jumps?over?the?lazy?fox";
int?index=StringFind(text,?"dog?jumps",?0);
if(index!=16)
Print("oops!");
int?StringGetChar(?string?text,?int?pos)?
取字符串中的某一個字符?
::?輸入參數
text?-?字符串?
pos?-?取字符的位置?
示例:
int?char_code=StringGetChar("abcdefgh",?3);
//?char?code?'c'?is?99
int?StringLen(?string?text)?
返回字符串長度?
::?輸入參數
text?-?字符串?
示例:
string?str="some?text";
if(StringLen(str)<5)?return(0);
string?StringSetChar(?string?text,?int?pos,?int?value)?
在字符串中設置一個字符?
::?輸入參數
text?-?字符串?
pos?-?設置字符的位置
value?-?新的字符?
示例:
string?str="abcdefgh";
string?str1=StringSetChar(str,?3,?'D');
//?str1?is?"abcDefgh"
string?StringSubstr(?string?text,?int?start,?int?count=EMPTY)?
從字符串中截取一段字符串?
::?輸入參數
text?-?字符串?
start?-?開始索引位置
count?-?截取字符數?
示例:
string?text="The?quick?brown?dog?jumps?over?the?lazy?fox";
string?substr=StringSubstr(text,?4,?5);
//?subtracted?string?is?"quick"?word
string?StringTrimLeft(?string?text)?
字符串左側去空格?
::?輸入參數
text?-?字符串?
示例:
string?str1="?Hello?world?";
string?str2=StringTrimLeft(str);
//?after?trimming?the?str2?variable?will?be?"Hello?World?"
string?StringTrimRight(?string?text)
字符串右側去空格?
::?輸入參數
text?-?字符串?
示例:
string?str1="?Hello?world?";
string?str2=StringTrimRight(str);
//?after?trimming?the?str2?variable?will?be?"?Hello?World"
標準常量?[Standard?Constants]?
Applied?price?enumeration
價格類型枚舉
示例:
Constant Value Description
PRICE_CLOSE? 0? 收盤價
PRICE_OPEN? 1? 開盤價
PRICE_HIGH? 2? 最高價
PRICE_LOW? 3? 最低價
PRICE_MEDIAN? 4? 最高價和最低價的平均價
PRICE_TYPICAL? 5? 最高價、最低價和收盤價的平均價
PRICE_WEIGHTED? 6? 開、收盤價和最高最低價的平均價
Drawing?shape?style?enumeration
畫圖形狀樣式枚舉,
形狀:
Constant Value Description
DRAW_LINE? 0? Drawing?line.?
DRAW_SECTION? 1? Drawing?sections.?
DRAW_HISTOGRAM? 2? Drawing?histogram.?
DRAW_ARROW? 3? Drawing?arrows?(symbols).?
DRAW_NONE? 12? No?drawing.?
樣式:
Constant Value Description
STYLE_SOLID? 0? The?pen?is?solid.?
STYLE_DASH? 1? The?pen?is?dashed.?
STYLE_DOT? 2? The?pen?is?dotted.?
STYLE_DASHDOT? 3? The?pen?has?alternating?dashes?and?dots.?
STYLE_DASHDOTDOT? 4? The?pen?has?alternating?dashes?and?double?dots.?
Error?codes
錯誤代碼,使用GetLastError()可返回錯誤代碼,錯誤代碼定義在stderror.mqh文件里,可以使用ErrorDescription()取得說明
#include?
void?SendMyMessage(string?text)
{
int?check;
SendMail("some?subject",?text);
check=GetLastError();
if(check!=ERR_NO_MQLERROR)?Print("Cannot?send?message,?error:?",ErrorDescription(check));
}
交易服務器返回的錯誤:?
Constant Value Description
ERR_NO_ERROR? 0? No?error?returned.?
ERR_NO_RESULT? 1? No?error?returned,?but?the?result?is?unknown.?
ERR_COMMON_ERROR? 2? Common?error.?
ERR_INVALID_TRADE_PARAMETERS? 3? Invalid?trade?parameters.?
ERR_SERVER_BUSY? 4? Trade?server?is?busy.?
ERR_OLD_VERSION? 5? Old?version?of?the?client?terminal.?
ERR_NO_CONNECTION? 6? No?connection?with?trade?server.?
ERR_NOT_ENOUGH_RIGHTS? 7? Not?enough?rights.?
ERR_TOO_FREQUENT_REQUESTS? 8? Too?frequent?requests.?
ERR_MALFUNCTIONAL_TRADE? 9? Malfunctional?trade?operation.?
ERR_ACCOUNT_DISABLED? 64? Account?disabled.?
ERR_INVALID_ACCOUNT? 65? Invalid?account.?
ERR_TRADE_TIMEOUT? 128? Trade?timeout.?
ERR_INVALID_PRICE? 129? Invalid?price.?
ERR_INVALID_STOPS? 130? Invalid?stops.?
ERR_INVALID_TRADE_VOLUME? 131? Invalid?trade?volume.?
ERR_MARKET_CLOSED? 132? Market?is?closed.?
ERR_TRADE_DISABLED? 133? Trade?is?disabled.?
ERR_NOT_ENOUGH_MONEY? 134? Not?enough?money.?
ERR_PRICE_CHANGED? 135? Price?changed.?
ERR_OFF_QUOTES? 136? Off?quotes.?
ERR_BROKER_BUSY? 137? Broker?is?busy.?
ERR_REQUOTE? 138? Requote.?
ERR_ORDER_LOCKED? 139? Order?is?locked.?
ERR_LONG_POSITIONS_ONLY_ALLOWED? 140? Long?positions?only?allowed.?
ERR_TOO_MANY_REQUESTS? 141? Too?many?requests.?
ERR_TRADE_MODIFY_DENIED? 145? Modification?denied?because?order?too?close?to?market.?
ERR_TRADE_CONTEXT_BUSY? 146? Trade?context?is?busy.?
MT4返回的運行錯誤:
Constant Value Description
ERR_NO_MQLERROR? 4000? No?error.?
ERR_WRONG_FUNCTION_POINTER? 4001? Wrong?function?pointer.?
ERR_ARRAY_INDEX_OUT_OF_RANGE? 4002? Array?index?is?out?of?range.?
ERR_NO_MEMORY_FOR_FUNCTION_CALL_STACK? 4003? No?memory?for?function?call?stack.?
ERR_RECURSIVE_STACK_OVERFLOW? 4004? Recursive?stack?overflow.?
ERR_NOT_ENOUGH_STACK_FOR_PARAMETER? 4005? Not?enough?stack?for?parameter.?
ERR_NO_MEMORY_FOR_PARAMETER_STRING? 4006? No?memory?for?parameter?string.?
ERR_NO_MEMORY_FOR_TEMP_STRING? 4007? No?memory?for?temp?string.?
ERR_NOT_INITIALIZED_STRING? 4008? Not?initialized?string.?
ERR_NOT_INITIALIZED_ARRAYSTRING? 4009? Not?initialized?string?in?array.?
ERR_NO_MEMORY_FOR_ARRAYSTRING? 4010? No?memory?for?array?string.?
ERR_TOO_LONG_STRING? 4011? Too?long?string.?
ERR_REMAINDER_FROM_ZERO_DIVIDE? 4012? Remainder?from?zero?divide.?
ERR_ZERO_DIVIDE? 4013? Zero?divide.?
ERR_UNKNOWN_COMMAND? 4014? Unknown?command.?
ERR_WRONG_JUMP? 4015? Wrong?jump?(never?generated?error).?
ERR_NOT_INITIALIZED_ARRAY? 4016? Not?initialized?array.?
ERR_DLL_CALLS_NOT_ALLOWED? 4017? DLL?calls?are?not?allowed.?
ERR_CANNOT_LOAD_LIBRARY? 4018? Cannot?load?library.?
ERR_CANNOT_CALL_FUNCTION? 4019? Cannot?call?function.?
ERR_EXTERNAL_EXPERT_CALLS_NOT_ALLOWED? 4020? Expert?function?calls?are?not?allowed.?
ERR_NOT_ENOUGH_MEMORY_FOR_RETURNED_STRING? 4021? Not?enough?memory?for?temp?string?returned?from?function.?
ERR_SYSTEM_BUSY? 4022? System?is?busy?(never?generated?error).?
ERR_INVALID_FUNCTION_PARAMETERS_COUNT? 4050? Invalid?function?parameters?count.?
ERR_INVALID_FUNCTION_PARAMETER_VALUE? 4051? Invalid?function?parameter?value.?
ERR_STRING_FUNCTION_INTERNAL_ERROR? 4052? String?function?internal?error.?
ERR_SOME_ARRAY_ERROR? 4053? Some?array?error.?
ERR_INCORRECT_SERIES_ARRAY_USING? 4054? Incorrect?series?array?using.?
ERR_CUSTOM_INDICATOR_ERROR? 4055? Custom?indicator?error.?
ERR_INCOMPATIBLE_ARRAYS? 4056? Arrays?are?incompatible.?
ERR_GLOBAL_VARIABLES_PROCESSING_ERROR? 4057? Global?variables?processing?error.?
ERR_GLOBAL_VARIABLE_NOT_FOUND? 4058? Global?variable?not?found.?
ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE? 4059? Function?is?not?allowed?in?testing?mode.?
ERR_FUNCTION_NOT_CONFIRMED? 4060? Function?is?not?confirmed.?
ERR_SEND_MAIL_ERROR? 4061? Send?mail?error.?
ERR_STRING_PARAMETER_EXPECTED? 4062? String?parameter?expected.?
ERR_INTEGER_PARAMETER_EXPECTED? 4063? Integer?parameter?expected.?
ERR_DOUBLE_PARAMETER_EXPECTED? 4064? Double?parameter?expected.?
ERR_ARRAY_AS_PARAMETER_EXPECTED? 4065? Array?as?parameter?expected.?
ERR_HISTORY_WILL_UPDATED? 4066? Requested?history?data?in?updating?state.?
ERR_END_OF_FILE? 4099? End?of?file.?
ERR_SOME_FILE_ERROR? 4100? Some?file?error.?
ERR_WRONG_FILE_NAME? 4101? Wrong?file?name.?
ERR_TOO_MANY_OPENED_FILES? 4102? Too?many?opened?files.?
ERR_CANNOT_OPEN_FILE? 4103? Cannot?open?file.?
ERR_INCOMPATIBLE_ACCESS_TO_FILE? 4104? Incompatible?access?to?a?file.?
ERR_NO_ORDER_SELECTED? 4105? No?order?selected.?
ERR_UNKNOWN_SYMBOL? 4106? Unknown?symbol.?
ERR_INVALID_PRICE_PARAM? 4107? Invalid?price.?
ERR_INVALID_TICKET? 4108? Invalid?ticket.?
ERR_TRADE_NOT_ALLOWED? 4109? Trade?is?not?allowed.?
ERR_LONGS__NOT_ALLOWED? 4110? Longs?are?not?allowed.?
ERR_SHORTS_NOT_ALLOWED? 4111? Shorts?are?not?allowed.?
ERR_OBJECT_ALREADY_EXISTS? 4200? Object?exists?already.?
ERR_UNKNOWN_OBJECT_PROPERTY? 4201? Unknown?object?property.?
ERR_OBJECT_DOES_NOT_EXIST? 4202? Object?does?not?exist.?
ERR_UNKNOWN_OBJECT_TYPE? 4203? Unknown?object?type.?
ERR_NO_OBJECT_NAME? 4204? No?object?name.?
ERR_OBJECT_COORDINATES_ERROR? 4205? Object?coordinates?error.?
ERR_NO_SPECIFIED_SUBWINDOW? 4206? No?specified?subwindow.?
Ichimoku?Kinko?Hyo?modes?enumeration
Ichimoku指標模式枚舉
Constant Value Description
MODE_TENKANSEN? 1? Tenkan-sen.?
MODE_KIJUNSEN? 2? Kijun-sen.?
MODE_SENKOUSPANA? 3? Senkou?Span?A.?
MODE_SENKOUSPANB? 4? Senkou?Span?B.?
MODE_CHINKOUSPAN? 5? Chinkou?Span.?
Indicators?line?identifiers
指標線標示符
指標線模式,使用在?iMACD(),?iRVI()?和?iStochastic()?中:
Constant Value Description
MODE_MAIN? 0? Base?indicator?line.?
MODE_SIGNAL? 1? Signal?line.?
指標線模式,使用在?iADX()?中:
Constant Value Description
MODE_MAIN? 0? Base?indicator?line.?
MODE_PLUSDI? 1? +DI?indicator?line.?
MODE_MINUSDI? 2? -DI?indicator?line.?
指標線模式,使用在?iBands(),?iEnvelopes(),?iEnvelopesOnArray(),?iFractals()?and?iGator()?中:
Constant Value Description
MODE_UPPER? 1? Upper?line.?
MODE_LOWER? 2? Lower?line.?
Market?information?identifiers
市場信息標識
Constant Value Description
MODE_LOW? 1? Low?day?price.?
MODE_HIGH? 2? High?day?price.?
MODE_TIME? 5? The?last?incoming?quotation?time.?
MODE_BID? 9? Last?incoming?bid?price.?
MODE_ASK? 10? Last?incoming?ask?price.?
MODE_POINT? 11? Point?size.?
MODE_DIGITS? 12? Digits?after?decimal?point.?
MODE_SPREAD? 13? Spread?value?in?points.?
MODE_STOPLEVEL? 14? Stop?level?in?points.?
MODE_LOTSIZE? 15? Lot?size?in?the?base?currency.?
MODE_TICKVALUE? 16? Tick?value.?
MODE_TICKSIZE? 17? Tick?size.?
MODE_SWAPLONG? 18? Swap?of?the?long?position.?
MODE_SWAPSHORT? 19? Swap?of?the?short?position.?
MODE_STARTING? 20? Market?starting?date?(usually?used?for?future?markets).?
MODE_EXPIRATION? 21? Market?expiration?date?(usually?used?for?future?markets).?
MODE_TRADEALLOWED? 22? Trade?is?allowed?for?the?symbol.?
MessageBox?return?codes
消息窗口返回值
Constant Value Description
IDOK? 1? OK?button?was?selected.?
IDCANCEL? 2? Cancel?button?was?selected.?
IDABORT? 3? Abort?button?was?selected.?
IDRETRY? 4? Retry?button?was?selected.?
IDIGNORE? 5? Ignore?button?was?selected.?
IDYES? 6? Yes?button?was?selected.?
IDNO? 7? No?button?was?selected.?
IDTRYAGAIN? 10? Try?Again?button?was?selected.?
IDCONTINUE? 11? Continue?button?was?selected.?
MessageBox?behavior?flags
消息窗口行為代碼
消息窗口顯示的按鈕種類:
Constant Value Description
MB_OK? 0x00000000? The?message?box?contains?one?push?button:?OK.?This?is?the?default.?
MB_OKCANCEL? 0x00000001? The?message?box?contains?two?push?buttons:?OK?and?Cancel.?
MB_ABORTRETRYIGNORE? 0x00000002? The?message?box?contains?three?push?buttons:?Abort,?Retry,?and?Ignore.?
MB_YESNOCANCEL? 0x00000003? The?message?box?contains?three?push?buttons:?Yes,?No,?and?Cancel.?
MB_YESNO? 0x00000004? The?message?box?contains?two?push?buttons:?Yes?and?No.?
MB_RETRYCANCEL? 0x00000005? The?message?box?contains?two?push?buttons:?Retry?and?Cancel.?
MB_CANCELTRYCONTINUE? 0x00000006? Windows?2000:?The?message?box?contains?three?push?buttons:?Cancel,?Try?Again,?Continue.?Use?this?message?box?type?instead?of?MB_ABORTRETRYIGNORE.?
消息窗口顯示圖標的類型:
Constant Value Description
MB_ICONSTOP,?MB_ICONERROR,?MB_ICONHAND? 0x00000010? A?stop-sign?icon?appears?in?the?message?box.?
MB_ICONQUESTION? 0x00000020? A?question-mark?icon?appears?in?the?message?box.?
MB_ICONEXCLAMATION,?MB_ICONWARNING? 0x00000030? An?exclamation-point?icon?appears?in?the?message?box.?
MB_ICONINFORMATION,?MB_ICONASTERISK? 0x00000040? An?icon?consisting?of?a?lowercase?letter?i?in?a?circle?appears?in?the?message?box.?
消息窗口默認按鈕設置:
Constant Value Description
MB_DEFBUTTON1? 0x00000000? The?first?button?is?the?default?button.?MB_DEFBUTTON1?is?the?default?unless?MB_DEFBUTTON2,?MB_DEFBUTTON3,?or?MB_DEFBUTTON4?is?specified.?
MB_DEFBUTTON2? 0x00000100? The?second?button?is?the?default?button.?
MB_DEFBUTTON3? 0x00000200? The?third?button?is?the?default?button.?
MB_DEFBUTTON4? 0x00000300? The?fourth?button?is?the?default?button.?
Moving?Average?method?enumeration
移動平均線模式枚舉,iAlligator(),?iEnvelopes(),?iEnvelopesOnArray,?iForce(),?iGator(),?iMA(),?iMAOnArray(),?iStdDev(),?iStdDevOnArray(),?iStochastic()這些會調用此枚舉
Constant Value Description
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.?
Object?properties?enumeration
物件屬性枚舉
Constant Value Description
OBJPROP_TIME1? 0? Datetime?value?to?set/get?first?coordinate?time?part.?
OBJPROP_PRICE1? 1? Double?value?to?set/get?first?coordinate?price?part.?
OBJPROP_TIME2? 2? Datetime?value?to?set/get?second?coordinate?time?part.?
OBJPROP_PRICE2? 3? Double?value?to?set/get?second?coordinate?price?part.?
OBJPROP_TIME3? 4? Datetime?value?to?set/get?third?coordinate?time?part.?
OBJPROP_PRICE3? 5? Double?value?to?set/get?third?coordinate?price?part.?
OBJPROP_COLOR? 6? Color?value?to?set/get?object?color.?
OBJPROP_STYLE? 7? Value?is?one?of?STYLE_SOLID,?STYLE_DASH,?STYLE_DOT,?STYLE_DASHDOT,?STYLE_DASHDOTDOT?constants?to?set/get?object?line?style.?
OBJPROP_WIDTH? 8? Integer?value?to?set/get?object?line?width.?Can?be?from?1?to?5.?
OBJPROP_BACK? 9? Boolean?value?to?set/get?background?drawing?flag?for?object.?
OBJPROP_RAY? 10? Boolean?value?to?set/get?ray?flag?of?object.?
OBJPROP_ELLIPSE? 11? Boolean?value?to?set/get?ellipse?flag?for?fibo?arcs.?
OBJPROP_SCALE? 12? Double?value?to?set/get?scale?object?property.?
OBJPROP_ANGLE? 13? Double?value?to?set/get?angle?object?property?in?degrees.?
OBJPROP_ARROWCODE? 14? Integer?value?or?arrow?enumeration?to?set/get?arrow?code?object?property.?
OBJPROP_TIMEFRAMES? 15? Value?can?be?one?or?combination?(bitwise?addition)?of?object?visibility?constants?to?set/get?timeframe?object?property.?
OBJPROP_DEVIATION? 16? Double?value?to?set/get?deviation?property?for?Standard?deviation?objects.?
OBJPROP_FONTSIZE? 100? Integer?value?to?set/get?font?size?for?text?objects.?
OBJPROP_CORNER? 101? Integer?value?to?set/get?anchor?corner?property?for?label?objects.?Must?be?from?0-3.?
OBJPROP_XDISTANCE? 102? Integer?value?to?set/get?anchor?X?distance?object?property?in?pixels.?
OBJPROP_YDISTANCE? 103? Integer?value?is?to?set/get?anchor?Y?distance?object?property?in?pixels.?
OBJPROP_FIBOLEVELS? 200? Integer?value?to?set/get?Fibonacci?object?level?count.?Can?be?from?0?to?32.?
OBJPROP_FIRSTLEVEL+?n? 210? Fibonacci?object?level?index,?where?n?is?level?index?to?set/get.?Can?be?from?0?to?31.?
Object?type?enumeration
物件類型枚舉
Constant Value Description
OBJ_VLINE? 0? Vertical?line.?Uses?time?part?of?first?coordinate.?
OBJ_HLINE? 1? Horizontal?line.?Uses?price?part?of?first?coordinate.?
OBJ_TREND? 2? Trend?line.?Uses?2?coordinates.?
OBJ_TRENDBYANGLE? 3? Trend?by?angle.?Uses?1?coordinate.?To?set?angle?of?line?use?ObjectSet()?function.?
OBJ_REGRESSION? 4? Regression.?Uses?time?parts?of?first?two?coordinates.?
OBJ_CHANNEL? 5? Channel.?Uses?3?coordinates.?
OBJ_STDDEVCHANNEL? 6? Standard?deviation?channel.?Uses?time?parts?of?first?two?coordinates.?
OBJ_GANNLINE? 7? Gann?line.?Uses?2?coordinate,?but?price?part?of?second?coordinate?ignored.?
OBJ_GANNFAN? 8? Gann?fan.?Uses?2?coordinate,?but?price?part?of?second?coordinate?ignored.?
OBJ_GANNGRID? 9? Gann?grid.?Uses?2?coordinate,?but?price?part?of?second?coordinate?ignored.?
OBJ_FIBO? 10? Fibonacci?retracement.?Uses?2?coordinates.?
OBJ_FIBOTIMES? 11? Fibonacci?time?zones.?Uses?2?coordinates.?
OBJ_FIBOFAN? 12? Fibonacci?fan.?Uses?2?coordinates.?
OBJ_FIBOARC? 13? Fibonacci?arcs.?Uses?2?coordinates.?
OBJ_EXPANSION? 14? Fibonacci?expansions.?Uses?3?coordinates.?
OBJ_FIBOCHANNEL? 15? Fibonacci?channel.?Uses?3?coordinates.?
OBJ_RECTANGLE? 16? Rectangle.?Uses?2?coordinates.?
OBJ_TRIANGLE? 17? Triangle.?Uses?3?coordinates.?
OBJ_ELLIPSE? 18? Ellipse.?Uses?2?coordinates.?
OBJ_PITCHFORK? 19? Andrews?pitchfork.?Uses?3?coordinates.?
OBJ_CYCLES? 20? Cycles.?Uses?2?coordinates.?
OBJ_TEXT? 21? Text.?Uses?1?coordinate.?
OBJ_ARROW? 22? Arrows.?Uses?1?coordinate.?
OBJ_LABEL? 23? Text?label.?Uses?1?coordinate?in?pixels.?
Object?visibility?enumeration
物件顯示枚舉
Constant Value Description
OBJ_PERIOD_M1? 0x0001? Object?shown?is?only?on?1-minute?charts.?
OBJ_PERIOD_M5? 0x0002? Object?shown?is?only?on?5-minute?charts.?
OBJ_PERIOD_M15? 0x0004? Object?shown?is?only?on?15-minute?charts.?
OBJ_PERIOD_M30? 0x0008? Object?shown?is?only?on?30-minute?charts.?
OBJ_PERIOD_H1? 0x0010? Object?shown?is?only?on?1-hour?charts.?
OBJ_PERIOD_H4? 0x0020? Object?shown?is?only?on?4-hour?charts.?
OBJ_PERIOD_D1? 0x0040? Object?shown?is?only?on?daily?charts.?
OBJ_PERIOD_W1? 0x0080? Object?shown?is?only?on?weekly?charts.?
OBJ_PERIOD_MN1? 0x0100? Object?shown?is?only?on?monthly?charts.?
OBJ_ALL_PERIODS? 0x01FF? Object?shown?is?on?all?timeframes.?
NULL? 0? Object?shown?is?on?all?timeframes.?
EMPTY? -1? Hidden?object?on?all?timeframes.?
Predefined?Arrow?codes?enumeration
預定義箭頭代碼枚舉
Constant Value Description
SYMBOL_THUMBSUP? 67? Thumb?up?symbol?(?C?).?
SYMBOL_THUMBSDOWN? 68? Thumb?down?symbol?(?D?).?
SYMBOL_ARROWUP? 241? Arrow?up?symbol?(???).?
SYMBOL_ARROWDOWN? 242? Arrow?down?symbol?(?ò?).?
SYMBOL_STOPSIGN? 251? Stop?sign?symbol?(???).?
SYMBOL_CHECKSIGN? 252? Check?sign?symbol?(?ü?).?
Constant Value Description
1? Upwards?arrow?with?tip?rightwards?(???).?
2? Downwards?arrow?with?tip?rightwards?(???).?
3? Left?pointing?triangle?(???).?
4? En?Dash?symbol?(–).?
SYMBOL_LEFTPRICE? 5? Left?sided?price?label.?
SYMBOL_RIGHTPRICE? 6? Right?sided?price?label.?
Series?array?identifier
系列數組標識符
Constant Value Description
MODE_OPEN? 0? Open?price.?
MODE_LOW? 1? Low?price.?
MODE_HIGH? 2? High?price.?
MODE_CLOSE? 3? Close?price.?
MODE_VOLUME? 4? Volume,?used?in?Lowest()?and?Highest()?functions.?
MODE_TIME? 5? Bar?open?time,?used?in?ArrayCopySeries()?function.?
Special?constants
特殊常量
Constant Value Description
NULL? 0? Indicates?empty?state?of?the?string.?
EMPTY? -1? Indicates?empty?state?of?the?parameter.?
EMPTY_VALUE? 0x7FFFFFFF? Default?custom?indicator?empty?value.?
CLR_NONE? 0xFFFFFFFF? Indicates?empty?state?of?colors.?
WHOLE_ARRAY? 0? Used?with?array?functions.?Indicates?that?all?array?elements?will?be?processed.?
Time?frame?enumeration
特殊常量
Constant Value Description
PERIOD_M1? 1? 1?minute.?
PERIOD_M5? 5? 5?minutes.?
PERIOD_M15? 15? 15?minutes.?
PERIOD_M30? 30? 30?minutes.?
PERIOD_H1? 60? 1?hour.?
PERIOD_H4? 240? 4?hour.?
PERIOD_D1? 1440? Daily.?
PERIOD_W1? 10080? Weekly.?
PERIOD_MN1? 43200? Monthly.?
0?(zero)? 0? Time?frame?used?on?the?chart.?
Trade?operation?enumeration
交易類型
Constant Value Description
OP_BUY? 0? Buying?position.?
OP_SELL? 1? Selling?position.?
OP_BUYLIMIT? 2? Buy?limit?pending?position.?
OP_SELLLIMIT? 3? Sell?limit?pending?position.?
OP_BUYSTOP? 4? Buy?stop?pending?position.?
OP_SELLSTOP? 5? Sell?stop?pending?position.?
Uninitialize?reason?codes
末初始化理由代碼
Constant Value Description
REASON_REMOVE? 1? Expert?removed?from?chart.?
REASON_RECOMPILE? 2? Expert?recompiled.?
REASON_CHARTCHANGE? 3? symbol?or?timeframe?changed?on?the?chart.?
REASON_CHARTCLOSE? 4? Chart?closed.?
REASON_PARAMETERS? 5? Inputs?parameters?was?changed?by?user.?
REASON_ACCOUNT? 6? Other?account?activated.?
Wingdings?symbols
圖形符號代碼
32? ?? 33? ?? 34? ?? 35? ?? 36? ?? 37? ?? 38? ?? 39? ?? 40? ?? 41? ?? 42? ?? 43? ?? 44? ?? 45? ?? 46? ?? 47?
?? 48? ?? 49? ?? 50? ?? 51? ?? 52? ?? 53? ?? 54? ?? 55? ?? 56? ?? 57? ?? 58? ?? 59? ?? 60? ?? 61? ?? 62? ?? 63?
?? 64? ?? 65? ?? 66? ?? 67? ?? 68? ?? 69? ?? 70? ?? 71? ?? 72? ?? 73? ?? 74? ?? 75? ?? 76? ?? 77? ?? 78? ?? 79?
?? 80? ?? 81? ?? 82? ?? 83? ?? 84? ?? 85? ?? 86? ?? 87? ?? 88? ?? 89? ?? 90? ?? 91? ?? 92? ?? 93? ?? 94? ?? 95?
?? 96? ?? 97? ?? 98? ?? 99? ?? 100? ?? 101? ?? 102? ?? 103? ?? 104? ?? 105? ?? 106? ?? 107? ?? 108? ?? 109? ?? 110? ?? 111?
?? 112? ?? 113? ?? 114? ?? 115? ?? 116? ?? 117? ?? 118? ?? 119? ?? 120? ?? 121? ?? 122? ?? 123? ?? 124? ?? 125? ?? 126? ?? 127?
?? 128? ?? 129? ?? 130? ?? 131? ?? 132? ?? 133? ?? 134? ?? 135? ?? 136? ?? 137? ?? 138? ?? 139? ?? 140? ?? 141? ?? 142? ?? 143?
?? 144? ?? 145? ?? 146? ?? 147? ?? 148? ?? 149? ?? 150? ?? 151? ?? 152? ?? 153? ?? 154? ?? 155? ?? 156? ?? 157? ?? 158? ?? 159?
160? ?? 161? ?? 162? ?? 163? ?? 164? ?? 165? ?? 166? ?? 167? ?? 168? ?? 169? ?? 170? ?? 171? ?? 172? ?? 173? ?? 174? ?? 175?
?? 176? ?? 177? ?? 178? ?? 179? ?? 180? ?? 181? ?? 182? ?? 183? ?? 184? ?? 185? ?? 186? ?? 187? ?? 188? ?? 189? ?? 190? ?? 191?
?? 192? ?? 193? ?? 194? ?? 195? ?? 196? ?? 197? ?? 198? ?? 199? ?? 200? ?? 201? ?? 202? ?? 203? ?? 204? ?? 205? ?? 206? ?? 207?
?? 208? ?? 209? ?? 210? ?? 211? ?? 212? ?? 213? ?? 214? ?? 215? ?? 216? ?? 217? ?? 218? ?? 219? ?? 220? ?? 221? ?? 222? ?? 223?
?? 224? ?? 225? ?? 226? ?? 227? ?? 228? ?? 229? ?? 230? ?? 231? ?? 232? ?? 233? ?? 234? ?? 235? ?? 236? ?? 237? ?? 238? ?? 239?
?? 240? ?? 241? ?? 242? ?? 243? ?? 244? ?? 245? ?? 246? ?? 247? ?? 248? ?? 249? ?? 250? ?? 251? ?? 252? ?? 253? ?? 254? ?? 255?
Web?colors?table
顏色表?
Black DarkGreen DarkSlateGray Olive Green Teal Navy Purple
Maroon Indigo MidnightBlue DarkBlue DarkOliveGreen SaddleBrown ForestGreen OliveDrab
SeaGreen DarkGoldenrod DarkSlateBlue Sienna MediumBlue Brown DarkTurquoise DimGray
LightSeaGreen DarkViolet FireBrick MediumVioletRed MediumSeaGreen Chocolate Crimson SteelBlue
Goldenrod MediumSpringGreen LawnGreen CadetBlue DarkOrchid YellowGreen LimeGreen OrangeRed
DarkOrange Orange Gold Yellow Chartreuse Lime SpringGreen Aqua
DeepSkyBlue Blue Magenta Red Gray SlateGray Peru BlueViolet
LightSlateGray DeepPink MediumTurquoise DodgerBlue Turquoise RoyalBlue SlateBlue DarkKhaki
IndianRed MediumOrchid GreenYellow MediumAquamarine DarkSeaGreen Tomato RosyBrown Orchid
MediumPurple PaleVioletRed Coral CornflowerBlue DarkGray SandyBrown MediumSlateBlue Tan
DarkSalmon BurlyWood HotPink Salmon Violet LightCoral SkyBlue LightSalmon
Plum Khaki LightGreen Aquamarine Silver LightSkyBlue LightSteelBlue LightBlue
PaleGreen Thistle PowderBlue PaleGoldenrod PaleTurquoise LightGrey Wheat NavajoWhite
Moccasin LightPink Gainsboro PeachPuff Pink Bisque LightGoldenRod BlanchedAlmond
LemonChiffon Beige AntiqueWhite PapayaWhip Cornsilk LightYellow LightCyan Linen
Lavender MistyRose OldLace WhiteSmoke Seashell Ivory Honeydew AliceBlue
LavenderBlush MintCream Snow White
技術指標調用?[Technical?Indicator?calls]
double?iAC(?string?symbol,?int?timeframe,?int?shift)?
計算?Bill?Williams'?Accelerator/Decelerator?oscillator?的值
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
示例:
double?result=iAC(NULL,?0,?1);
double?iAD(?string?symbol,?int?timeframe,?int?shift)?
計算?Accumulation/Distribution?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
示例:
double?result=iAD(NULL,?0,?1);
double?iAlligator(?string?symbol,?int?timeframe,?int?jaw_period,?int?jaw_shift,?int?teeth_period,?int?teeth_shift,?int?lips_period,?int?lips_shift,?int?ma_method,?int?applied_price,?int?mode,?int?shift)?
計算?Bill?Williams'?Alligator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
jaw_period?-?顎線周期
jaw_shift?-?顎線位移
teeth_period?-?齒線周期
teeth_shift?-?齒線位移
lips_period?-?唇線周期?
lips_shift?-?唇線位移?
ma_method?-?移動平均線種類
applied_price?-?應用價格類型
mode?-?來源模式,MODE_GATORJAW,MODE_GATORTEETH?或MODE_GATORLIPS?
shift?-?位移數?
double?jaw_val=iAlligator(NULl,?0,?13,?8,?8,?5,?5,?3,?MODE_SMMA,?PRICE_MEDIAN,?MODE_GATORJAW,?1);
double?iADX(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?mode,?int?shift)?
計算?Movement?directional?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iADX(NULL,0,14,PRICE_HIGH,MODE_MAIN,0)>iADX(NULL,0,14,PRICE_HIGH,MODE_PLUSDI,0))?return(0);
double?iATR(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?Indicator?of?the?average?true?range?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
if(iATR(NULL,0,12,0)>iATR(NULL,0,20,0))?return(0);
double?iAO(?string?symbol,?int?timeframe,?int?shift)?
計算?Bill?Williams'?Awesome?oscillator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
double?val=iAO(NULL,?0,?2);
double?iBearsPower(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Bears?Power?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iBearsPower(NULL,?0,?13,PRICE_CLOSE,0);
double?iBands(?string?symbol,?int?timeframe,?int?period,?int?deviation,?int?bands_shift,?int?applied_price,?int?mode,?int?shift)?
計算?Bollinger?bands?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
deviation?-?背離
bands_shift?-?Bands位移?
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0])?return(0);
double?iBandsOnArray(?double?array[],?int?total,?int?period,?double?deviation,?int?bands_shift,?int?mode,?int?shift)?
從數組中計算?Bollinger?bands?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
deviation?-?背離
bands_shift?-?Bands位移?
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iBands(NULL,0,20,2,0,PRICE_LOW,MODE_LOWER,0)>Low[0])?return(0);
double?iBullsPower(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Bulls?Power?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iBullsPower(NULL,?0,?13,PRICE_CLOSE,0);
double?iCCI(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Commodity?channel?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iCCI(NULL,0,12,0)>iCCI(NULL,0,20,0))?return(0);
double?iCCIOnArray(?double?array[],?int?total,?int?period,?int?shift)?
從數組中計算?Commodity?channel?index?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
shift?-?位移數?
if(iCCIOnArray(ExtBuffer,total,12,0)>iCCI(NULL,0,20,PRICE_OPEN,?0))?return(0);
double?iCustom(?string?symbol,?int?timeframe,?string?name,?...?,?int?mode,?int?shift)?
計算?自定義指標?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
name?-?自定義指標名稱
...?-?自定義指標參數?
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iCustom(NULL,?0,?"SampleInd",13,1,0);
double?iDeMarker(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?DeMarker?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
double?val=iDeMarker(NULL,?0,?13,?1);
double?iEnvelopes(?string?symbol,?int?timeframe,?int?ma_period,?int?ma_method,?int?ma_shift,?int?applied_price,?double?deviation,?int?mode,?int?shift)?
計算?Envelopes?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
applied_price?-?應用價格類型
deviation?-?背離
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iEnvelopes(NULL,?0,?13,MODE_SMA,10,PRICE_CLOSE,0.2,MODE_UPPER,0);
double?iEnvelopesOnArray(?double?array[],?int?total,?int?ma_period,?int?ma_method,?int?ma_shift,?double?deviation,?int?mode,?int?shift)
從數組中計算?Envelopes?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
deviation?-?背離
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iEnvelopesOnArray(ExtBuffer,?0,?13,?MODE_SMA,?0.2,?MODE_UPPER,0?);
double?iForce(?string?symbol,?int?timeframe,?int?period,?int?ma_method,?int?applied_price,?int?shift)?
計算?Force?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
ma_method?-?移動平均線模式
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iForce(NULL,?0,?13,MODE_SMA,PRICE_CLOSE,0);
double?iFractals(?string?symbol,?int?timeframe,?int?mode,?int?shift)?
計算?Fractals?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iFractals(NULL,?0,?MODE_UPPER,0);
double?iGator(?string?symbol,?int?timeframe,?int?jaw_period,?int?jaw_shift,?int?teeth_period,?int?teeth_shift,?int?lips_period,?int?lips_shift,?int?ma_method,?int?applied_price,?int?mode,?int?shift)?
計算?Fractals?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
jaw_period?-?顎線周期
jaw_shift?-?顎線位移
teeth_period?-?齒線周期
teeth_shift?-?齒線位移
lips_period?-?唇線周期?
lips_shift?-?唇線位移?
ma_method?-?移動平均線種類
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?jaw_val=iGator(NULL,?0,?13,?8,?8,?5,?5,?3,?MODE_SMMA,?PRICE_MEDIAN,?MODE_UPPER,?1);
double?iIchimoku(?string?symbol,?int?timeframe,?int?tenkan_sen,?int?kijun_sen,?int?senkou_span_b,?int?mode,?int?shift)?
計算?Ichimoku?Kinko?Hyo?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
tenkan_sen?-?轉換線?
jkijun_sen?-?基準線?
senkou_span_b?-?參考范圍b?
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?tenkan_sen=iIchimoku(NULL,?0,?9,?26,?52,?MODE_TENKANSEN,?1);
double?iBWMFI(?string?symbol,?int?timeframe,?int?shift)?
計算?Bill?Williams?Market?Facilitation?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
double?val=iBWMFI(NULL,?0,?0);
double?iMomentum(?string?symbol,?int?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Momentum?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iMomentum(NULL,0,12,PRICE_CLOSE,0)>iMomentum(NULL,0,20,PRICE_CLOSE,0))?return(0);
double?iMomentumOnArray(?double?array[],?int?total,?int?period,?int?shift)?
從數組中計算?Momentum?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
shift?-?位移數?
if(iMomentumOnArray(mybuffer,100,12,0)>iMomentumOnArray(mubuffer,100,20,0))?return(0);
double?iMFI(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?Money?flow?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
if(iMFI(NULL,0,14,0)>iMFI(NULL,0,14,1))?return(0);
double?iMA(?string?symbol,?int?timeframe,?int?period,?int?ma_shift,?int?ma_method,?int?applied_price,?int?shift)?
計算?Moving?average?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
ma_shift?-?移動平均線位移
ma_method?-?移動平均線模式
applied_price?-?應用價格類型
shift?-?位移數?
AlligatorJawsBuffer[i]=iMA(NULL,0,13,8,MODE_SMMA,PRICE_MEDIAN,i);
double?iMAOnArray(?double?array[],?int?total,?int?period,?int?ma_shift,?int?ma_method,?int?shift)?
從數組中計算?Moving?average?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
ma_shift?-?移動平均線位移
ma_method?-?移動平均線模式
shift?-?位移數?
double?macurrent=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,0);
double?macurrentslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,0);
double?maprev=iMAOnArray(ExtBuffer,0,5,0,MODE_LWMA,1);
double?maprevslow=iMAOnArray(ExtBuffer,0,10,0,MODE_LWMA,1);
//----
if(maprev=macurrentslow)
Alert("crossing?up");
double?iOsMA(?string?symbol,?int?timeframe,?int?fast_ema_period,?int?slow_ema_period,?int?signal_period,?int?applied_price,?int?shift)?
計算?Moving?Average?of?Oscillator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
fast_ema_period?-?快均線周期
slow_ema_period?-?慢均線周期
signal_period?-?信號周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iOsMA(NULL,0,12,26,9,PRICE_OPEN,1)>iOsMA(NULL,0,12,26,9,PRICE_OPEN,0))?return(0);
double?iMACD(?string?symbol,?int?timeframe,?int?fast_ema_period,?int?slow_ema_period,?int?signal_period,?int?applied_price,?int?mode,?int?shift)?
計算?Moving?averages?convergence/divergence?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
fast_ema_period?-?快均線周期
slow_ema_period?-?慢均線周期
signal_period?-?信號周期
applied_price?-?應用價格類型
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0)>iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_SIGNAL,0))?return(0);
double?iOBV(?string?symbol,?int?timeframe,?int?applied_price,?int?shift)?
計算?On?Balance?Volume?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
double?val=iOBV(NULL,?0,?PRICE_CLOSE,?1);
double?iSAR(?string?symbol,?int?timeframe,?double?step,?double?maximum,?int?shift)?
計算?On?Balance?Volume?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
step?-?步幅
maximum?-?最大值
shift?-?位移數?
if(iSAR(NULL,0,0.02,0.2,0)>Close[0])?return(0);
double?iRSI(?string?symbol,?void?timeframe,?int?period,?int?applied_price,?int?shift)?
計算?Relative?strength?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
applied_price?-?應用價格類型
shift?-?位移數?
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>iRSI(NULL,0,14,PRICE_CLOSE,1))?return(0);
double?iRSIOnArray(?double?array[],?int?total,?int?period,?int?shift)?
從數組中計算?Relative?strength?index?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
period?-?周期
shift?-?位移數?
if(iRSIOnBuffer(ExtBuffer,1000,14,0)>iRSI(NULL,0,14,PRICE_CLOSE,1))?return(0);
double?iRVI(?string?symbol,?int?timeframe,?int?period,?int?mode,?int?shift)?
計算?Relative?Vigor?index?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
double?val=iRVI(NULL,?0,?10,MODE_MAIN,0);
double?iStdDev(?string?symbol,?int?timeframe,?int?ma_period,?int?ma_method,?int?ma_shift,?int?applied_price,?int?shift)?
計算?Standard?Deviation?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
applied_price?-?應用價格類型
shift?-?位移數?
double?val=iStdDev(NULL,0,10,MODE_EMA,0,PRICE_CLOSE,0);
double?iStdDevOnArray(?double?array[],?int?total,?int?ma_period,?int?ma_method,?int?ma_shift,?int?shift)?
從數組中計算?Standard?Deviation?indicator?的值?
::?輸入參數
array[]?-?數組數據
total?-?總數據數量
ma_period?-?移動平均線周期
ma_method?-?移動平均線模式
ma_shift?-?移動平均線位移
shift?-?位移數?
double?val=iStdDevOnArray(ExtBuffer,100,10,MODE_EMA,0,0);
double?iStochastic(?string?symbol,?int?timeframe,?int?%Kperiod,?int?%Dperiod,?int?slowing,?int?method,?int?price_field,?int?mode,?int?shift)?
計算?Stochastic?oscillator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
%Kperiod?-?%K線周期?
%Dperiod?-?%D線周期
slowing?-?減速量
method?-?移動平均線種類
price_field?-?價格領域參數:?0?-?Low/High?or?1?-?Close/Close.?
mode?-?來源模式,參見指標線分類枚舉
shift?-?位移數?
if(iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0)>iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_SIGNAL,0))
return(0);
double?iWPR(?string?symbol,?int?timeframe,?int?period,?int?shift)?
計算?Larry?William's?percent?range?indicator?的值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
period?-?周期
shift?-?位移數?
if(iWPR(NULL,0,14,0)>iWPR(NULL,0,14,1))?return(0);
int?iBars(?string?symbol,?int?timeframe)?
返回制定圖表的數據數?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線?
Print("Bar?count?on?the?'EUROUSD'?symbol?with?PERIOD_H1?is",iBars("EUROUSD",PERIOD_H1));
int?iBarShift(?string?symbol,?int?timeframe,?datetime?time,?bool?exact=false)?
在制定圖表中搜索數據?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
time?-?時間
exact?-?是否精確的?
datetime?some_time=D'2004.03.21?12:00';
int?shift=iBarShift("EUROUSD",PERIOD_M1,some_time);
Print("shift?of?bar?with?open?time?",TimeToStr(some_time),"?is?",shift);
double?iClose(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的收盤價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iHigh(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的最高價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iLow(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的最低價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iOpen(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的開盤價?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
datetime?iTime(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的時間?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
double?iVolume(?string?symbol,?int?timeframe,?int?shift)?
返回制定圖表的成交量?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
shift?-?位移數?
Print("Current?bar?for?USDCHF?H1:?",iTime("USDCHF",PERIOD_H1,i),",?",?iOpen("USDCHF",PERIOD_H1,i),",?",
iHigh("USDCHF",PERIOD_H1,i),",?",?iLow("USDCHF",PERIOD_H1,i),",?",
iClose("USDCHF",PERIOD_H1,i),",?",?iVolume("USDCHF",PERIOD_H1,i));
int?Highest(?string?symbol,?int?timeframe,?int?type,?int?count=WHOLE_ARRAY,?int?start=0)?
返回制定圖表的某段數據的最高值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
type?-?數據類型
count?-?計算范圍
start?-?開始點?
double?val;
//?calculating?the?highest?value?in?the?range?from?5?element?to?25?element
//?indicator?charts?symbol?and?indicator?charts?time?frame
val=High[Highest(NULL,0,MODE_HIGH,20,4)];
int?Lowest(?string?symbol,?int?timeframe,?int?type,?int?count=WHOLE_ARRAY,?int?start=0)?
返回制定圖表的某段數據的最高值?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線
type?-?數據類型
count?-?計算范圍
start?-?開始點?
double?val=Low[Lowest(NULL,0,MODE_LOW,10,10)];
交易函數?[Trading?Functions]
int?HistoryTotal(?)
返回歷史數據的數量
//?retrieving?info?from?trade?history
int?i,hstTotal=HistoryTotal();
for(i=0;i<HSTTOTAL;I++)
{
//----?check?selection?result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Access?to?history?failed?with?error?(",GetLastError(),")");
break;
}
//?some?work?with?order
}
bool?OrderClose(?int?ticket,?double?lots,?double?price,?int?slippage,?color?Color=CLR_NONE)?
對訂單進行平倉操作。?
::?輸入參數
ticket?-?訂單編號
lots?-?手數
price?-?平倉價格
slippage?-?最高劃點數
Color?-?標記顏色?
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderClose(order_id,1,Ask,3,Red);
return(0);
}
bool?OrderCloseBy(?int?ticket,?int?opposite,?color?Color=CLR_NONE)?
對訂單進行平倉操作。?
::?輸入參數
ticket?-?訂單編號
opposite?-?相對訂單編號
Color?-?標記顏色?
示例:
if(iRSI(NULL,0,14,PRICE_CLOSE,0)>75)
{
OrderCloseBy(order_id,opposite_id);
return(0);
}
double?OrderClosePrice(?)?
返回訂單的平倉價
示例:
if(OrderSelect(ticket,SELECT_BY_POS)==true)
Print("Close?price?for?the?order?",ticket,"?=?",OrderClosePrice());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
datetime?OrderCloseTime(?)?
返回訂單的平倉時間
示例:
if(OrderSelect(10,SELECT_BY_POS,MODE_HISTORY)==true)
{
datetime?ctm=OrderOpenTime();
if(ctm>0)?Print("Open?time?for?the?order?10?",?ctm);
ctm=OrderCloseTime();
if(ctm>0)?Print("Close?time?for?the?order?10?",?ctm);
}
else
Print("OrderSelect?failed?error?code?is",GetLastError());
string?OrderComment(?)?
返回訂單的注釋
示例:
string?comment;
if(OrderSelect(10,SELECT_BY_TICKET)==false)
{
Print("OrderSelect?failed?error?code?is",GetLastError());
return(0);
}
comment?=?OrderComment();
//?...
double?OrderCommission(?)?
返回訂單的傭金數
示例:
if(OrderSelect(10,SELECT_BY_POS)==true)
Print("Commission?for?the?order?10?",OrderCommission());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
bool?OrderDelete(?int?ticket)?
刪除未啟用的訂單?
::?輸入參數
ticket?-?訂單編號?
示例:
if(Ask>var1)
{
OrderDelete(order_ticket);
return(0);
}
datetime?OrderExpiration(?)?
返回代辦訂單的有效日期
示例:
if(OrderSelect(10,?SELECT_BY_TICKET)==true)
Print("Order?expiration?for?the?order?#10?is?",OrderExpiration());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
double?OrderLots(?)?
返回選定訂單的手數
示例:
if(OrderSelect(10,SELECT_BY_POS)==true)
Print("lots?for?the?order?10?",OrderLots());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrderMagicNumber(?)?
返回選定訂單的指定編號
示例:
if(OrderSelect(10,SELECT_BY_POS)==true)
Print("Magic?number?for?the?order?10?",?OrderMagicNumber());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
bool?OrderModify(?int?ticket,?double?price,?double?stoploss,?double?takeprofit,?datetime?expiration,?color?arrow_color=CLR_NONE)?
對訂單進行平倉操作。?
::?輸入參數
ticket?-?訂單編號
price?-?平倉價格
stoploss?-?止損價
takeprofit?-?獲利價
expiration?-?有效期
Color?-?標記顏色?
示例:
if(TrailingStop>0)
{
SelectOrder(12345,SELECT_BY_TICKET);
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<BID-POINT*TRAILINGSTOP)
{
OrderModify(OrderTicket(),Ask-10*Point,Ask-35*Point,OrderTakeProfit(),0,Blue);
return(0);
}
}
}
double?OrderOpenPrice(?)?
返回選定訂單的買入價
示例:
if(OrderSelect(10,?SELECT_BY_POS)==true)
Print("open?price?for?the?order?10?",OrderOpenPrice());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
datetime?OrderOpenTime(?)
返回選定訂單的買入時間
示例:
if(OrderSelect(10,?SELECT_BY_POS)==true)
Print("open?time?for?the?order?10?",OrderOpenTime());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
void?OrderPrint(?)?
將訂單打印到窗口上
示例:
if(OrderSelect(10,?SELECT_BY_TICKET)==true)
OrderPrint();
else
Print("OrderSelect?failed?error?code?is",GetLastError());
bool?OrderSelect(?int?index,?int?select,?int?pool=MODE_TRADES)?
選定訂單?
::?輸入參數
index?-?訂單索引
select?-?選定模式,SELECT_BY_POS,SELECT_BY_TICKET
pool?-?Optional?order?pool?index.?Used?when?select?parameter?is?SELECT_BY_POS.It?can?be?any?of?the?following?values:
MODE_TRADES?(default)-?order?selected?from?trading?pool(opened?and?pending?orders),
MODE_HISTORY?-?order?selected?from?history?pool?(closed?and?canceled?order).?
示例:
if(OrderSelect(12470,?SELECT_BY_TICKET)==true)
{
Print("order?#12470?open?price?is?",?OrderOpenPrice());
Print("order?#12470?close?price?is?",?OrderClosePrice());
}
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrderSend(?string?symbol,?int?cmd,?double?volume,?double?price,?int?slippage,?double?stoploss,?double?takeprofit,?string?comment=NULL,?int?magic=0,?datetime?expiration=0,?color?arrow_color=CLR_NONE)?
發送訂單?
::?輸入參數
symbol?-?通貨標示
cmd?-?購買方式
volume?-?購買手數
price?-?平倉價格
slippage?-?最大允許滑點數
stoploss?-?止損價
takeprofit?-?獲利價
comment?-?注釋
magic?-?自定義編號
expiration?-?過期時間(只適用于待處理訂單)
arrow_color?-?箭頭顏色?
示例:
int?ticket;
if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
{
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My?order?#2",16384,0,Green);
if(ticket<0)
{
Print("OrderSend?failed?with?error?#",GetLastError());
return(0);
}
}
double?OrderStopLoss(?)?
返回選定訂單的止損
示例:
if(OrderSelect(ticket,SELECT_BY_POS)==true)
Print("Stop?loss?value?for?the?order?10?",?OrderStopLoss());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrdersTotal(?)?
返回總訂單數
示例:
int?handle=FileOpen("OrdersReport.csv",FILE_WRITE|FILE_CSV,"\t");
if(handle<0)?return(0);
//?write?header
FileWrite(handle,"#","open?price","open?time","symbol","lots");
int?total=OrdersTotal();
//?write?open?orders
for(int?pos=0;pos<TOTAL;POS++)
{
if(OrderSelect(pos,SELECT_BY_POS)==false)?continue;
FileWrite(handle,OrderTicket(),OrderOpenPrice(),OrderOpenTime(),OrderSymbol(),OrderLots());
}
FileClose(handle);
int?OrdersTotal(?)?
返回總訂單數
示例:
if(OrderSelect(order_id,?SELECT_BY_TICKET)==true)
Print("Swap?for?the?order?#",?order_id,?"?",OrderSwap());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
double?OrderSwap(?)?
返回指定訂單的匯率
示例:
if(OrderSelect(order_id,?SELECT_BY_TICKET)==true)
Print("Swap?for?the?order?#",?order_id,?"?",OrderSwap());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
string?OrderSymbol(?)?
返回指定訂單的通貨標識
示例:
if(OrderSelect(12,?SELECT_BY_POS)==true)
Print("symbol?of?order?#",?OrderTicket(),?"?is?",?OrderSymbol());
else
Print("OrderSelect?failed?error?code?is",GetLastError());
double?OrderTakeProfit(?)?
返回指定訂單的獲利點數
示例:
if(OrderSelect(12,?SELECT_BY_POS)==true)
Print("Order?#",OrderTicket(),"?profit:?",?OrderTakeProfit());
else
Print("OrderSelect()?a?eíó????èáêó?-?",GetLastError());
int?OrderTicket(?)?
返回指定訂單的編號
示例:
if(OrderSelect(12,?SELECT_BY_POS)==true)
order=OrderTicket();
else
Print("OrderSelect?failed?error?code?is",GetLastError());
int?OrderType(?)?
返回指定訂單的類型
示例:
int?order_type;
if(OrderSelect(12,?SELECT_BY_POS)==true)
{
order_type=OrderType();
//?...
}
else
Print("OrderSelect()?a?eíó????èáêó?-?",GetLastError());
窗口函數?[Window?Functions]
double?PriceOnDropped(?)?
Returns?price?part?of?dropped?point?where?expert?or?script?was?dropped.?This?value?is?valid?when?expert?or?script?dropped?by?mouse.
Note:?For?custom?indicators?this?value?is?undefined.
示例:
double?drop_price=PriceOnDropped();
datetime?drop_time=TimeOnDropped();
//----?may?be?undefined?(zero)
if(drop_time>0)
{
ObjectCreate("Dropped?price?line",?OBJ_HLINE,?0,?drop_price);
ObjectCreate("Dropped?time?line",?OBJ_VLINE,?0,?drop_time);
}
datetime?TimeOnDropped(?)?
Returns?time?part?of?dropped?point?where?expert?or?script?was?dropped.?This?value?is?valid?when?expert?or?script?dropped?by?mouse.
Note:?For?custom?indicators?this?value?is?undefined.
示例:
double?drop_price=PriceOnDropped();
datetime?drop_time=TimeOnDropped();
//----?may?be?undefined?(zero)
if(drop_time>0)
{
ObjectCreate("Dropped?price?line",?OBJ_HLINE,?0,?drop_price);
ObjectCreate("Dropped?time?line",?OBJ_VLINE,?0,?drop_time);
}
int?WindowFind(?string?name)?
返回窗口的索引號?
::?輸入參數
name?-?指標簡稱?
示例:
int?win_idx=WindowFind("MACD(12,26,9)");
int?WindowHandle(?string?symbol,?int?timeframe)?
返回窗口的句柄?
::?輸入參數
symbol?-?通貨標識
timeframe?-?時間線?
示例:
int?win_handle=WindowHandle("USDX",PERIOD_H1);
if(win_handle!=0)
Print("Window?with?USDX,H1?detected.?Rates?array?will?be?copied?immediately.");
bool?WindowIsVisible(?int?index)?
返回窗口是否可見?
::?輸入參數
index?-?窗口索引號?
示例:
int?maywin=WindowFind("MyMACD");
if(maywin>-1?&&?WindowIsVisible(maywin)==true)
Print("window?of?MyMACD?is?visible");
else
Print("window?of?MyMACD?not?found?or?is?not?visible");
int?WindowOnDropped(?)?
Returns?window?index?where?expert,?custom?indicator?or?script?was?dropped.?This?value?is?valid?when?expert,?custom?indicator?or?script?dropped?by?mouse.
示例:
if(WindowOnDropped()!=0)
{
Print("Indicator?'MyIndicator'?must?be?applied?to?main?chart?window!");
return(false);
}
int?WindowsTotal(?)?
返回窗口數
示例:
Print("Windows?count?=?",?WindowsTotal());
int?WindowXOnDropped(?)?
Returns?x-axis?coordinate?in?pixels?were?expert?or?script?dropped?to?the?chart.?See?also?WindowYOnDropped(),?WindowOnDropped()
示例:
Print("Expert?dropped?point?x=",WindowXOnDropped(),"?y=",WindowYOnDropped());/div>
int?WindowYOnDropped(?)?
Returns?y-axis?coordinate?in?pixels?were?expert?or?script?dropped?to?the?chart.?See?also?WindowYOnDropped(),?WindowOnDropped()
示例:
Print("Expert?dropped?point?x=",WindowXOnDropped(),"?y=",WindowYOnDropped());
轉載于:https://www.cnblogs.com/mingyongcheng/archive/2012/04/20/2460811.html
總結
- 上一篇: c4d导入大模型以及给建筑上贴图笔记
- 下一篇: Three.js实现汽车3D展示/开关门