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
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
{
// 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
}
//...
}
微博:
閱讀更多 大侃金融 的文章