#property strict
#include <stderror.mqh>
#include <stdlib.mqh>
static bool EntryBool = false ;
void OnTick (void) {
int order_resend_num;
int close_resend_num;
int ea_ticket_res;
int errorcode;
double ea_order_entry_price;
double ea_order_close_price;
bool closeret;
bool selbool;
double closelot;
if ( EntryBool == false ) {
EntryBool = true ;
} else {
return ;
}
if ( IsDemo () == false ) {
MessageBox ("実際に新規オーダーするので、デモ口座で動作させて下さい。","エラー" ,MB_ICONEXCLAMATION );
return ;
}
ea_order_entry_price = Ask ;
for ( order_resend_num = 0; order_resend_num < 10; order_resend_num++ ) {
if ( IsDemo () == true ) {
ea_ticket_res = OrderSend (
Symbol () ,
OP_BUY ,
0.01,
ea_order_entry_price,
20,
0,
0,
"テストオーダー" ,
999,
0,
clrRed
);
}
if ( ea_ticket_res == -1) {
errorcode = GetLastError ();
if ( errorcode != ERR_NO_ERROR ) {
printf ("エラーコード:%d , 詳細:%s " ,errorcode , ErrorDescription (errorcode));
if ( errorcode == ERR_TRADE_NOT_ALLOWED ) {
MessageBox (ErrorDescription (errorcode),"オーダーエラー" ,MB_ICONEXCLAMATION );
return ;
}
}
Sleep (1000);
RefreshRates ();
ea_order_entry_price = Ask ;
printf ("再エントリー要求回数:%d, 更新エントリーレート:%g" ,order_resend_num+1 ,ea_order_entry_price);
} else {
Print ("新規オーダー約定。 チケットNo=" ,ea_ticket_res);
Sleep (1000);
ea_order_close_price = Bid ;
selbool = OrderSelect (ea_ticket_res,SELECT_BY_TICKET );
if ( selbool == true ) {
closelot = OrderLots ();
} else {
closelot = 0.01;
}
for ( close_resend_num = 0; close_resend_num < 20; close_resend_num++ ) {
closeret = OrderClose (
ea_ticket_res,
closelot,
ea_order_close_price,
20,
clrBlue
);
if ( closeret == false ) {
Sleep (1000);
RefreshRates ();
ea_order_close_price = Bid ;
printf ("再決済要求回数:%d, 更新決済レート:%g" ,close_resend_num+1 ,ea_order_close_price);
} else {
Print ("決済オーダー約定。 チケットNo=" ,ea_ticket_res);
break ;
}
}
break ;
}
}
}
クリップボードにコピー
open #15164459 buy 0.01 EURGBP at 0.72617 ok
新規オーダー約定。 チケットNo=15164459
再決済要求回数:1, 更新決済レート:0.72614
close #15164459 buy 0.01 EURGBP at 0.72617 at price 0.72614
決済オーダー約定。 チケットNo=15164459
クリップボードにコピー