こんにちは、皆さん!
今回は「シンプルだけど効果的なブレイクアウト戦略」のアップデートをお届けします。このコードには、プロップファームチャレンジ用のヘルパー関数を追加しました。
プロップファームのチャレンジをクリアするためには、主に以下の3つの基準を満たす必要があります:
- 目標利益を達成すること
- 最大日次損失を超えないこと
- 最大損失を超えないこと
このコードでは、「目標利益」と「最大日次損失に近づいているか」を確認する2つの関数を含めており、これによりすべてのポジションを自動的に終了し、未決済のオーダーを削除します。「最大損失」に関しては、戦略やリスク管理に依存するため、MQL5スクリプト内では言及しません。
//+------------------------------------------------------------------+ //| プロップファームヘルパー関数 | //+------------------------------------------------------------------+ // すべての未決済オーダーを削除し、すべてのポジションを終了します void ClearAll(string message) { Comment(message); for (int i = OrdersTotal() - 1; i >= 0; i--) { ulong orderTicket = OrderGetTicket(i); if (OrderSelect(orderTicket)) { trade.OrderDelete(orderTicket); } } for (int i = PositionsTotal() - 1; i >= 0; i--) { ulong posTicket = PositionGetTicket(i); trade.PositionClose(posTicket); } } // 目標利益を達成したか確認 bool isPassed() { return AccountInfoDouble(ACCOUNT_EQUITY) > PASS_CRITERIA; } // 最大日次損失に近づいているか確認 bool isDailyLimit() { MqlDateTime date_time; TimeToStruct(TimeCurrent(), date_time); int current_day = date_time.day, current_month = date_time.mon, current_year = date_time.year; // 現在の残高 double current_balance = AccountInfoDouble(ACCOUNT_BALANCE); // 今日のクローズトレードPLを取得 HistorySelect(0, TimeCurrent()); int orders = HistoryDealsTotal(); double PL = 0.0; for (int i = orders - 1; i >= 0; i--) { ulong ticket=HistoryDealGetTicket(i); if(ticket==0) { Print("HistoryDealGetTicket失敗、トレード履歴なし"); break; } double profit = HistoryDealGetDouble(ticket,DEAL_PROFIT); if (profit != 0) { // トレードの日時を取得 MqlDateTime deal_time; TimeToStruct(HistoryDealGetInteger(ticket, DEAL_TIME), deal_time); // トレードの時間を確認 if (deal_time.day == current_day && deal_time.mon == current_month && deal_time.year == current_year) { PL += profit; } else break; } } double starting_balance = current_balance - PL; double current_equity = AccountInfoDouble(ACCOUNT_EQUITY); return current_equity < starting_balance - DAILY_LOSS_LIMIT; }
必要なパラメータは以下の通りです:
input string dd = "-------------プロップファームチャレンジ-----------------"; input bool isChallenge = false; input double PASS_CRITERIA = 110100.; input double DAILY_LOSS_LIMIT = 4500.;
このスクリプトが皆さんのお役に立てれば幸いです。