
オーダ発行時のチャートを見直したい
自動売買のEAを作成し検証いますが、オーダ発行時のチャート状況を見直すことでEAの改善を検討してます。今までは、オーダ履歴からオーダ発行時のチャートを見返していましたが、結構面倒な作業のためオーダ取得時の画像を取得して確認するための処理を作成しました。
また、今後はWEBサーバへ画像を転送して、WEB上で取引履歴を確認できるようにしたいと考えています。
サンプルソース
/*------------------------------------------------------
関数名 getChartImage
内容 チャート画像取得
引数
string symbol :通貨ペア
NUM_TIMEFRAMES period :タイムフレームワーク
int tichet :チケット番号
戻り値
なし
-------------------------------------------------------*/
void getChartImage(string symbol , ENUM_TIMEFRAMES period , int tichet){
// チャートオープン
long charId = ChartOpen(symbol,period);
// チャートテンプレート指定
ChartApplyTemplate(charId,"myChart");
// ファイル名取得
datetime now = TimeLocal();
MqlDateTime now_struct;
TimeToStruct(now, now_struct);
string stime = StringFormat("%4d%02d%02d%02d%02d%02d",
now_struct.year,
now_struct.mon,
now_struct.day,
now_struct.hour,
now_struct.min,
now_struct.sec);
string fileTitle = symbol+"_"
+ IntegerToString(tichet)+"_"
+ stime+".gif";
// チャートスクリーンショット
ChartScreenShot(charId,fileTitle,800,400,ALIGN_RIGHT);
// チャートクローズ
ChartClose(charId);
// FTP転送
SendFTP(fileTitle);
}
解説
チャートオープン
// チャートオープン
long charId = ChartOpen(symbol,period);
オーダ発行時の通貨とEAの判定足でのチャート画像を取得します。
チャートテンプレート指定
// チャートテンプレート指定
ChartApplyTemplate(charId,”myChart”);
チャートを見やすくするために、表示テンプレート(フォーマット)を指定します。
チャートスクリーンショット
// チャートスクリーンショット
ChartScreenShot(charId,fileTitle,800,400,ALIGN_RIGHT);
オープンしたチャートのスクリーンショットを取得します。
チャートクローズ
// チャートクローズ
ChartClose(charId);
チャートはスクリーンショットを取得するだけに新規に開いているので、画像所得後は閉じます。ここで閉じないと、オーダを発行するたびに開かれたチャートが増え続けていきます。