平均約定価格を算出するための関数です。
double getAverageOpenPrice(
int magic,
string symbol
);
パラメータ
magic
平均約定価格を算出するポジションのマジックナンバーを指定します。
symbol
平均約定価格を算出するポジションの通貨ペア名を指定します。
戻り値
パラメータに指定したマジックナンバー・通貨ペアのポジションの平均約定価格を返します。
ポジションが存在しない場合には結果は0となります。
計算過程でエラーが生じた場合には結果は-1となります。
double getAverageOpenPrice(int magic, string symbol){
double total = 0;
double lots = 0;
for(int i = OrdersTotal() - 1; i >= 0; i--){
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) return(-1);
if(OrderMagicNumber() != magic) continue;
if(OrderSymbol() != symbol) continue;
if(OrderType() == OP_BUY || OrderType() == OP_SELL){
total += OrderOpenPrice() * OrderLots();
lots += OrderLots();
}
}
if(total <= 0){
return(0);
}
return(total / lots);
}
検索結果がありません。 |
検索結果がありません。 |