//+---------------------------------------------+ //|script program start function | //+---------------------------------------------+ int ActionType = 0; int start() { //---- //inputs checking if (OrderCount < 2) { MessageBox("Not enough OrderCount, must be greater than 1 at least"); return (-1); } double LotsPerOrder, LotsLeft; int i, n; n = TotalLots * 10/OrderCount; LotsPerOrder = n; LotsPerOrder /= 10; LotsLeft = TotalLots - LotsPerOrder * OrderCount; if (LotsPerOrder < 0.1) { MessageBox("Not enough TotalLots or too many OrderCount, each order must be 0.1 lots at least"); return (-1); } if (LotsPerOrder + LotsLeft >= 10000) { MessageBox("Too many TotalLots, each order must be less than 10000 lots"); return (-1); } n = NormalizeDouble((MathAbs(RangeStart - RangeEnd) * MathPow(10, Digits)), 0)/(OrderCount-1);
if (n < 1) { MessageBox("Too many OrderCount, each order must have 1 pips diff at least"); }
extern bool ActionBuy = true;
extern double RangeStart = 1.1850;
extern double RangeEnd = 1.1870;
extern double TotalLots = 1.0;
extern int OrderCount = 5;
extern int Slippage = 0;
extern double StopLoss = 0.0;
extern double TakeProfit = 0.0;
extern string Comments = "BatchOpen Auto Generated";
extern datetime Expiration = 0;
extern int Delay = 0;
#define BATCH_OPEN_MAGIC 06021610
//+---------------------------------------------+
//|script program start function |
//+---------------------------------------------+
int ActionType = 0;
int start()
{
//----
//inputs checking
if (OrderCount < 2) {
MessageBox("Not enough OrderCount, must be greater than 1 at least");
return (-1);
}
double LotsPerOrder, LotsLeft;
int i, n;
n = TotalLots * 10/OrderCount;
LotsPerOrder = n;
LotsPerOrder /= 10;
LotsLeft = TotalLots - LotsPerOrder * OrderCount;
if (LotsPerOrder < 0.1) {
MessageBox("Not enough TotalLots or too many OrderCount, each order must be 0.1 lots at least");
return (-1);
}
if (LotsPerOrder + LotsLeft >= 10000) {
MessageBox("Too many TotalLots, each order must be less than 10000 lots");
return (-1);
}
n = NormalizeDouble((MathAbs(RangeStart - RangeEnd) * MathPow(10, Digits)), 0)/(OrderCount-1);
if (n < 1) {
MessageBox("Too many OrderCount, each order must have 1 pips diff at least");
}
double volume, price;
string symbol;
int cmd, magic, ticket, cnt, failed;
symbol = Symbol();
magic = BATCH_OPEN_MAGIC;
volume = LotsPerOrder;
cnt = 0;
failed = 0;
for (i = 0; i < OrderCount; i++) {
price = RangeStart + i * n * Point;
if (i == OrderCount-1) {
volume += LotsLeft;
//price = RangeEnd;
}
RefreshRates();
if (ActionBuy) {
if (price < Ask) {
cmd = OP_BUYLIMIT;
} else {
cmd = OP_BUYSTOP;
}
} else {
if (price < Bid) {
cmd = OP_SELLSTOP;
} else {
cmd = OP_SELLLIMIT;
}
}
ticket = OrderSend(symbol, cmd, volume, price, Slippage, StopLoss,
TakeProfit, Comments, magic, Expiration, CLR_NONE);
if (ticket < 0) {
Print("Failed to place order at price " + price + ", Error: " + ErrorDescription(GetLastError()));
failed++;
} else {
cnt++;
}
Sleep(Delay);
}
//----
Print(cnt + " orders placed, " + OrderCount + " requested, " + failed + " failed");
return(0);
}
//+---------------------------------------------+