1万円から始めるFX自動売買(無料EA)の記録

無料EAで稼ぐことができるのか検証中!

マジックナンバーをEA名に変更

今までマジックナンバーを表示していましたがEA名の方が分かりやすいと思いEA名に変更してみました。

拡張子をmq4からtxtに変更し書き換えしました。↓

 

//+------------------------------------------------------------------+
//| ポジションの状態を定期的に知らせる
//} OrderMail_To_Me.mq4 Ver.1.40 [2010.11.12]
//+------------------------------------------------------------------+
#property copyright "Copyright (C) 2008 Kaz. All Rights Reserved."
#property link "http://blog.xe.bz/"

extern int BETWEEN = 15; //チェック間隔(単位:秒)
extern string MAIL_SUBJECT = "MetaTrader4 Status";

//グローバル変数
int tickets_old[1] = {0};
int tickets_now[1] = {0};
int tickets_added[1] = {0};
int tickets_deleted[1] = {0};
int ut_old = 0;

//+------------------------------------------------------------------+
//| スタート
//+------------------------------------------------------------------+
int start() {
int i,j,k,ticket;
bool flag;
ArrayInitialize(tickets_now,0);
ArrayInitialize(tickets_added,0);
ArrayInitialize(tickets_deleted,0);
ArrayResize(tickets_now,1);
ArrayResize(tickets_added,1);
ArrayResize(tickets_deleted,1);

//メイン
int nowloccal_ut = TimeLocal();
if*1 continue;
ticket = OrderTicket();
push(tickets_now,ticket);
//新規ポジションのチェック
if(tickets_old[0] > 0) {
if(! in_array(ticket,tickets_old)) push(tickets_added,ticket);
} else {
push(tickets_added,ticket);
}
}
//削除されたポジションのチェック
for(i=0; i<ArraySize(tickets_old); i++) {
ticket = tickets_old[i];
if(ticket == 0) continue;
if(! in_array(ticket,tickets_now)) push(tickets_deleted,ticket);
}


//for DEBUG
/*
for(i=0; i<ArraySize(tickets_old); i++) {
if(tickets_old[i] == 0) continue;
Print("tickets_old["+i+"]="+tickets_old[i]);
}
for(i=0; i<ArraySize(tickets_now); i++) {
if(tickets_now[i] == 0) continue;
Print("tickets_now["+i+"]="+tickets_now[i]);
}
for(i=0; i<ArraySize(tickets_added); i++) {
if(tickets_added[i] == 0) continue;
Print("tickets_added["+i+"]="+tickets_added[i]);
}
for(i=0; i<ArraySize(tickets_deleted); i++) {
if(tickets_deleted[i] == 0) continue;
Print("tickets_deleted["+i+"]="+tickets_deleted[i]);
}
*/

//変化があったか?
if*2 {
string msg = "";

//新規オーダーの詳細取得
if(tickets_added[0] > 0) {
msg = "*** 新規注文 ***\r\n\r\n";
for(i=0; i<ArraySize(tickets_added); i++) {
ticket = tickets_added[i];
if(ticket == 0) break;
if(! OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) continue;
msg = msg + "通貨ペア : "+OrderSymbol()+"\r\n";
msg = msg + "注文種類 : "+ordertype2str(OrderType())+"\r\n";
msg = msg + "注文数量 : "+DoubleToStr(OrderLots(),2)+"\r\n";
msg = msg + "レート : "+dts2(OrderOpenPrice())+"\r\n";
msg = msg + "ストップ : "+dts2(OrderStopLoss())+"\r\n";
msg = msg + "リミット : "+dts2(OrderTakeProfit())+"\r\n";
msg = msg + "口座残高 : "+DoubleToStr(AccountBalance(),2)+"\r\n";
msg = msg + "使用証拠金 : "+DoubleToStr(AccountMargin(),2)+"\r\n";
msg = msg + "含み損益 : "+DoubleToStr(AccountProfit(),2)+"\r\n";
msg = msg + "EA名 : "+magic2eaname(OrderMagicNumber())+"\r\n";
msg = msg + "オープン日時 : "+TimeToStr(OrderOpenTime(),TIME_DATE|TIME_MINUTES)+"\r\n";
msg = msg + "注文番号 : "+OrderTicket()+"\r\n";
msg = msg + "\r\n";
}
}

//決済の詳細取得
if(tickets_deleted[0] > 0) {
msg = msg + "*** 決済 ***\r\n\r\n";
for(i=0; i<ArraySize(tickets_deleted); i++) {
ticket = tickets_deleted[i];
if(ticket == 0) break;
if(! OrderSelect(ticket,SELECT_BY_TICKET,MODE_HISTORY)) continue;
msg = msg + "通貨ペア : "+OrderSymbol()+"\r\n";
msg = msg + "注文種類 : "+ordertype2str(OrderType())+"\r\n";
msg = msg + "注文数量 : "+DoubleToStr(OrderLots(),2)+"\r\n";
msg = msg + "オープン : "+dts2(OrderOpenPrice())+"\r\n";
msg = msg + "クローズ : "+dts2(OrderClosePrice())+"\r\n";
msg = msg + "損益 : "+DoubleToStr(OrderProfit(),2)+"\r\n";
msg = msg + "スワップ : "+DoubleToStr(OrderSwap(),2)+"\r\n";
msg = msg + "口座残高 : "+DoubleToStr(AccountBalance(),2)+"\r\n";
msg = msg + "使用証拠金 : "+DoubleToStr(AccountMargin(),2)+"\r\n";
msg = msg + "含み損益 : "+DoubleToStr(AccountProfit(),2)+"\r\n";
msg = msg + "EA名 : "+magic2eaname(OrderMagicNumber())+"\r\n";
msg = msg + "オープン日時 : "+TimeToStr(OrderOpenTime(),TIME_DATE|TIME_MINUTES)+"\r\n";
msg = msg + "クローズ日時 : "+TimeToStr(OrderCloseTime(),TIME_DATE|TIME_MINUTES)+"\r\n";
msg = msg + "注文番号 : "+OrderTicket()+"\r\n";
msg = msg + "\r\n";
}
}

//メール送信
SendMail(MAIL_SUBJECT,msg);
//Print("msg="+msg);

}

//現在のチケット番号とチェック時間を保存する
ArrayInitialize(tickets_old,0);
ArrayResize(tickets_old,ArraySize(tickets_now));
for(i=0; i<ArraySize(tickets_now); i++) tickets_old[i] = tickets_now[i];
ut_old = nowloccal_ut;
}

return(0);
}

//配列の最後に値を追加する(0個目の値が0のときだけは上書きする)
int push(int& ary,int val) {
int k2 = 0;
int len = ArraySize(ary);
if((len >= 1) && (ary[0] != 0)) {
ArrayResize(ary,(len+1));
k2 = len;
}
ary[k2] = val;
return(ArraySize(ary));
}

//小数点を適切に切る
string dts2(double val) {
if(val < 10) return(DoubleToStr(val,4));
else return(DoubleToStr(val,2));
}

//OrderTypeの値を文字列で返す
string ordertype2str(int type) {
if(type == OP_BUY) return("BUY");
else if(type == OP_SELL) return("SELL");
else if(type == OP_BUYLIMIT) return("BUYLIMIT");
else if(type == OP_SELLLIMIT) return("SELLLIMIT");
else if(type == OP_BUYSTOP) return("BUYSTOP");
else if(type == OP_SELLSTOP) return("SELLSTOP");
else return("unknown");
}

//配列内に指定した値が存在するか
bool in_array(int val,int ary) {
bool res = false;
for (int i=0; i<ArraySize(ary); i++) {
if(ary[i] == val) {
res = true;
break;
}
}
return(res);
}

//マジックナンバーをEA名にする(必要に応じて修正する)
string magic2eaname(int magic) {
if(magic == 0) return("N/A");
else if(magic == 20141206) return("Break-1");
else if(magic == 201605211) return("Break-1");
else if(magic == 20141207) return("Break-1");
else if(magic == 201412071) return("Break-1");
else if(magic == 20141011) return("Break-2");
else if(magic == 20141012) return("Break-2");
else if(magic == 20150326) return("Scal-1");
else if(magic == 201503267) return("Scal-1");
else if(magic == 201512051) return("Scal-1");
else if(magic == 20180120) return("Scal-1");
else if(magic == 20180121) return("Scal-1");
else if(magic == 20180107) return("Scal-1");
else if(magic == 20151206) return("Scal-1");
else if(magic == 20160118) return("Scal-2");
else if(magic == 20160119) return("Scal-2");
else if(magic == 20150705) return("Scal-3");
else if(magic == 20150706) return("Scal-3");
else if(magic == 20180111) return("Scal-3");
else if(magic == 20150702) return("Scal-3");
else if(magic == 20160102) return("Scal-3");
else if(magic == 20151108) return("Scal-4");
else if(magic == 99991207) return("Scal-4");
else if(magic == 20170303) return("Scal-5");
else if(magic == 201501181) return("Scal-6");
else if(magic == 20150170) return("Scal-7");
else if(magic == 20150171) return("Scal-7");
else if(magic == 20150172) return("Scal-7");
else if(magic == 20150180) return("Scal-7");
else if(magic == 20150181) return("Scal-7");
else if(magic == 20150182) return("Scal-7");
else if(magic == 20170721) return("Scal-8");
else if(magic == 20170820) return("Scal-8");
else if(magic == 20170927) return("Scal-9");
else return(DoubleToStr(magic,0));
}

 
これでEA名にできたかな?(;´Д`)

*1:nowloccal_ut - ut_old) >= BETWEEN) {
//現在のチケット番号を取得する
for(i=0; i<OrdersTotal(); i++) {
if(! OrderSelect(i,SELECT_BY_POS,MODE_TRADES

*2:tickets_added[0] > 0) || (tickets_deleted[0] > 0