Orders Average Price (Multiple Magic Numbers)
4 replies
ramacan
11 years ago #111190
Mark Fric
11 years ago #121712
you can check the function sqGetOrdersAveragePrice() in the EA generated code.
Mark
StrategyQuant architect
ramacan
11 years ago #121731
Mark,
Are you saying I should use sqGetOrdersAveragePrice() in the Custom Function area? Bear with me since I am not a programmer, please give me an example of how to retrieve the average price weighted by lots for Magic#1 and Magic#2.
Regards.
Mark Fric
11 years ago #121833
Hello,
sorry for insufficient reply.
You can add the following code to the {EA Wizard}/code/CustomFunctions.mq4 file.
This will make EA Wizard add this function to every EA code generated.
double GetMultiOrdersAveragePrice(int magic1, int magic2) {
double sum = 0.0;
double cnt = 0.0;
for (int cc = OrdersTotal() – 1; cc >= 0; cc–) {
if (!OrderSelect(cc, SELECT_BY_POS) ) continue;
if((OrderMagicNumber() == magic1 || OrderMagicNumber() == magic2) && OrderSymbol() == Symbol()) {
if(OrderType() == OP_BUY && OrderCloseTime() == 0) {
sum += OrderLots() * OrderOpenPrice ();
cnt += OrderLots();
}
if(OrderType() == OP_SELL && OrderCloseTime() == 0) {
sum += OrderLots() * OrderOpenPrice ();
cnt += OrderLots();
}
}
}
if (NormalizeDouble (cnt, Digits) == 0) return (0);
return(sum / cnt);
}
Then in EA Wizard rules you can use this new function like Functions -> Custom Function: GetMultiOrdersAveragePrice(1000, 2000)
to get the average price of orders with magic numbers 1000 and 2000.
Mark
Mark
StrategyQuant architect
ramacan
11 years ago #121843
Viewing 4 replies - 1 through 4 (of 4 total)