指定された銘柄のSum Open Profitのロング/ショートポジション
返信 0 件
指定されたシンボルの現在の含み益を取得する必要がある場合は、EA Wizardで次の関数を使用できます。
1) ウィザードフォルダにあるCustomFunction.mq4にカスタムコードを追加する
float sumOpenProfit(string direction, string symbolString) {
float totalProfit = 0;
for(int i=OrdersTotal()-1; i>=0; i--) {
if (OrderSelect(i,SELECT_BY_POS)==true) {
if (direction == "LONG" && symbolString != "" && OrderType() == OP_BUY && OrderSymbol() == symbolString) {
totalProfit += OrderProfit();
}
else if (direction == "LONG" && symbolString == "" && OrderType() == OP_BUY) {
totalProfit += OrderProfit();
}
else if (direction == "SHORT" && symbolString != "" && OrderType() == OP_SELL && OrderSymbol() == symbolString) {
totalProfit += OrderProfit();
}
else if (direction == "SHORT" && symbolString == "" && OrderType() == OP_SELL) {
totalProfit += OrderProfit();
}
}
}
return totalProfit;
}
2) 追加 カスタムアクション ウィザードのようにこのように
EURUSDのロングポジションのオープン損益(P/L)を取得する
sumOpenProfit("LONG", "EURUSD");
または
すべてのオープンな売り建玉の含み益(P/L)を取得する
sumOpenProfit("SHORT", "")
サンプルEAが添付されています
0