-
-
Save ronta-trader/e3805bb2eb7b7144a6e68439ea95dff9 to your computer and use it in GitHub Desktop.
バイナリーオプションの検証結果(エントリー価格・時刻、イグジット価格・時刻)をCSVに出力するEA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#property strict // コンパイルのモード | |
input int EXIT_TIME_M = 5; // 決済時間(分) | |
double Total = 0; // トレード回数 | |
double Win = 0; // 勝ち回数 | |
double Entry_price = 0; // エントリー価格 | |
double Exit_price = 0; // イグジット価格 | |
datetime Entry_time = 0; // エントリー時刻 | |
datetime Exit_time = 0; // イグジット時刻 | |
int OnInit() | |
{ | |
// csvファイル 「Trade_result.csv」 を作成する。 | |
// 名前が同じファイルが存在する場合には、上書きされる。 | |
// ファイルが開いたままだと正常に動作しない。 | |
int Handle = FileOpen("Trade_result.csv", FILE_CSV | FILE_WRITE | FILE_COMMON, ","); | |
if(Handle != INVALID_HANDLE){ | |
FileWrite(Handle, "エントリー時刻", "エントリー価格", "イグジット時刻", "イグジット価格"); | |
FileClose(Handle); | |
} | |
return(INIT_SUCCEEDED); | |
} | |
void OnTick() | |
{ | |
double rsi1 = iRSI(NULL, 0, 14, PRICE_CLOSE, 1); | |
double rsi2 = iRSI(NULL, 0, 14, PRICE_CLOSE, 2); | |
if(Entry_price == 0 && rsi2 > 25 && rsi1 < 25 ) { // ポジションなし & 条件発生 | |
Total = Total + 1; // トレード回数を1回追加 | |
Entry_price = Open[0]; // エントリー価格を記録 | |
Entry_time = Time[0]; // エントリー時刻を記録 | |
} | |
if(Entry_price !=0 && (TimeCurrent() - Entry_time) >= (EXIT_TIME_M * 60) ){ // ポジションあり & 条件発生 | |
Exit_price = Open[0]; // イグジット価格を記録 | |
Exit_time = Time[0]; // イグジット時刻を記録 | |
if(Entry_price < Exit_price ){ // エントリー価格 < イグジット価格 なら | |
Win = Win + 1; // 勝ちを1回追加 | |
} | |
// ファイル書き込み | |
if (Entry_price != 0){ | |
int Handle = FileOpen("Trade_result.csv", FILE_CSV | FILE_READ | FILE_WRITE | FILE_COMMON, ","); | |
if(Handle != INVALID_HANDLE){ | |
FileSeek(Handle, 0, SEEK_END); | |
FileWrite(Handle, Entry_time, Entry_price, Exit_time, Exit_price); | |
FileClose(Handle); | |
Entry_price = 0; | |
} | |
} | |
} | |
if(Total != 0){ | |
Comment("トレード回数:",(int)Total, " 勝ち:", (int)Win, " 負け:", (int)Total - (int)Win, " 勝率:", NormalizeDouble(Win / Total * 100, 1), "%"); | |
} | |
else{ | |
Comment("トレードなし"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment