This forum is in read-only mode now. You may discuss your questions on forums of MQL4.community and MQL5.community
problem MT 4 pending ordersBack to topics list |
|
Alexac04
2005.07.14 20:55
hi,
i have problem mit my expert and BuyStop and SellStop Order BuyStop open and immediately Delete :( SellStop open and immediately Delete :( here my Expert code : extern double Lots = 0.1;
extern double StopLoss = 34;
extern double TakeProfit = 17;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double nlots=0.1,L,H,order;
int SC=0,BC=0,cnt=0;
for(cnt=0 ;cnt< OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_SELL && OrderSymbol()==Symbol()) BC=1;
if (OrderType() == OP_BUY && OrderSymbol()==Symbol()) SC=1;
}
for(cnt=0 ;cnt< OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
order=OrderTicket();
if (OrderType() == OP_SELLSTOP && OrderSymbol()==Symbol() && SC==1) OrderDelete(order);
if (OrderType() == OP_BUYSTOP && OrderSymbol()==Symbol() && BC==1) OrderDelete(order);
}
if (Hour() == 15 && Minute() == 00) //EST Hours = 9
{
if (OrdersTotal() >0) return;
if ((High[1] - Low[1]) < 19*Point) return;
L=Low[1]-1*Point;
H=High[1]+1*Point;
OrderSend(Symbol(),OP_SELLSTOP,Lots,L,3,L+StopLoss*Point,L-TakeProfit*Point,0,16,Red);
}
if (Hour() == 15 && Minute() == 00) //EST Hours = 9
{
if (OrdersTotal() >1) return;
if ((High[1] - Low[1]) < 19*Point) return;
L=Low[1]-1*Point;
H=High[1]+1*Point;
OrderSend(Symbol(),OP_BUYSTOP,Lots,H,3,H-StopLoss*Point,H+TakeProfit*Point,0,16,Red);
}
}
|
|
hdb
2005.07.14 22:56
Alex,
Here is the corrected script. OrderSend is a function which returns a result which u should check. The basic logic was right bot u forgot the comment field in the OrderSend function. U also put the expiration field to 16.. not sure what that does as I have not tried it before. Note: this will not work in the backtester as the time function does not seem to return the data's time... this is my interpretation as u get no orders in the backtester. regards, hugues
extern double Lots = 0.1;
extern double StopLoss = 34;
extern double TakeProfit = 17;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
double nlots=0.1,L,H,order;
int SC=0,BC=0,cnt=0;
for(cnt=0 ;cnt< OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType() == OP_SELL && OrderSymbol()==Symbol()) BC=1;
if (OrderType() == OP_BUY && OrderSymbol()==Symbol()) SC=1;
}
for(cnt=0 ;cnt< OrdersTotal(); cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
order=OrderTicket();
if (OrderType() == OP_SELLSTOP && OrderSymbol()==Symbol() && SC==1)
{
OrderDelete(order);
}
if (OrderType() == OP_BUYSTOP && OrderSymbol()==Symbol() && BC==1)
{
OrderDelete(order);
}
}
if (Hour() == 15 && Minute() == 00) //EST Hours = 9
{
if (OrdersTotal() >0) return;
if ((High[1] - Low[1]) < 19*Point) return;
L=Low[1]-1*Point;
H=High[1]+1*Point;
int ticket = OrderSend(Symbol(),OP_SELLSTOP,Lots,L,3,L+StopLoss*Point,L-TakeProfit*Point,"",0,0,Red); // HDB changed - is a function, added comment as "" and removed expiration 16
}
if (Hour() == 15 && Minute() == 00) //EST Hours = 9
{
if (OrdersTotal() >1) return;
if ((High[1] - Low[1]) < 19*Point) return;
L=Low[1]-1*Point;
H=High[1]+1*Point;
ticket = OrderSend(Symbol(),OP_BUYSTOP,Lots,H,3,H-StopLoss*Point,H+TakeProfit*Point,"",0,0,Green); // HDB changed - is a function, added comment as "", removed expiration 16, put as Green
}
}
|
|
Alexac04
2005.07.15 18:19
BIG THANKS hugues
|
|
hdb
2005.07.16 04:06
yw
|
Download MetaTrader 5 (450 Kb, web installer) — a new terminal for financial markets
