エントリーロジックとエグジットロジックを書いて、「おーし、OK!」と思っていると、条件に合致すると何度でもエントリーエグジットしてしまいますよね?
あるタイミングでエントリーするようなEAだと1日1回でいいんだけどな〜という時のお話です。
コードはこんな感じでいけます↓
1日に1回だけエントリーする条件
これです!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
string today = StringConcatenate(Year(), ".", Month(), ".", Day(), " 00:00:00"); string todayend = StringConcatenate(Year(), ".", Month(), ".", Day(), " 23:59:59"); for(int historycnt = OrdersHistoryTotal() - 1; historycnt >= 0; historycnt--){ if(OrderSelect(historycnt, SELECT_BY_POS, MODE_HISTORY) == false) break; if(OrderMagicNumber() != MAGIC) continue; if(OrderSymbol() != Symbol()) continue; // 目的のポジションが選択された状態 if (OrderOpenTime() >= StrToTime(today) && OrderOpenTime() <= StrToTime(todayend)) { EntryFlg=false; break; } } |
コード解説
1 |
string today = StringConcatenate(Year(), ".", Month(), ".", Day(), " 00:00:00"); |
1 |
string todayend = StringConcatenate(Year(), ".", Month(), ".", Day(), " 23:59:59"); |
1 |
for(int historycnt = OrdersHistoryTotal() - 1; historycnt >= 0; historycnt--){ |
1 |
if(OrderSelect(historycnt, SELECT_BY_POS, MODE_HISTORY) == false) break; |
1 |
if (OrderOpenTime() >= StrToTime(today) && OrderOpenTime() <= StrToTime(todayend)) { |
先ほど取得しておいた、本日の 00:00〜23:59の間に、エントリーがされているか? というのを判定しています。
これで、本日エントリーされたデータが存在するというのを確認しています。
このコードの例では、その後、booleanのEntryFlg を使って、実際のエントリーロジックに入る部分にif文を定義して、本日エントリーされていればエントリーしないというロジックを想定しています。
それでは!
コメントを残す