You are setting the TP at 20 points, that is ridiculously close. If the spread is 20 Points or more the trade would be closed immediately if it was opened.
If the error persists, check that the SL and TP are not closer than SYMBOL_TRADE_STOPS_LEVEL.
Also, the order opening price should not be closer than MarketInfo (Symbol(), MODE_STOPLEVEL) to сurrent price.
If MarketInfo (Symbol (), MODE_STOPLEVEL) is equal to zero, then this value is floating and it is necessary to use an offset from the current price of at least two spreads.
Keith Watford: You are setting the TP at 20 points, that is ridiculously close. If the spread is 20 Points or more the trade would be closed immediately if it was opened.
Keith Watford: You are setting the TP at 20 points, that is ridiculously close. If the spread is 20 Points or more the trade would be closed immediately if it was opened.
Could you write an example code with dummy values ?
I want for pending sell order SL to be 3 pips below of 2nd last candle i.e ( SL = Low[2] - 3 pips)
TP = TradeOpenPrice - 10 pips
TradeOpenPrice = Low[1] - 3 pips
how could I code this? Please write an example code I am stuck on this unable to understand.
// This worked
Ticket1 = OrderSend(Symbol(), OP_SELLSTOP, 0.01, Bid - 20 * Point, 3, Ask+3 *Point, Ask-100*Point, "Pending Sell Order 1", 16384, 0, Red);
// This didn't worked what is the difference???
Ticket1 = OrderSend(Symbol(),OP_SELLSTOP,0.01,Price,3,StopLossSell,TpFirstOrder,"Pending Sell Order 1",16384,0,clrGreen);
I want my EA to work in this manner:
When Close[1] > EMA (EXPONENTIAL MOVING AVERAGE) open a trade immediately on the start of current candle (example: Close[1] = 1.16147 > EMA = 1.16076)
Price for opening pending trade will be High[1] + 3 pips (example: High[1] = 1.16186 + 3 pips, SO TradeOpenPrice = 1.16216)
StopLoss for pending trade will be High[2] - 3 pips (example: High[2] = 1.16180 - 3 pips, SO SL = 1.16150)
TakeProfit for this pending order should be 10 pips above of the trade open price (example: TradeOpenPrice = 1.16216 + 10 pips, SO TP = 1.16316)
voidOnTick()
{
H1EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H1,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
H4EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H4,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
StopLossBuy = NormalizeDouble(High[2] + ((3 * 10) * Point),Digits());
StopLossSell = NormalizeDouble(Low[2] - ((3 * 10) * Point),Digits());
double Spreed = Ask-Bid;
if(
Close[1]>H4EMAprev &&
Close[1]>H1EMAprev
)
{
Price = NormalizeDouble(High[1] + ((3 * 10) * Point),Digits());
TpOrderOne = NormalizeDouble(Price + ((10 * 10) * Point),Digits());
if (StopLossBuy>Price-2*Spreed) Print("Not correct SL BUY");
//Pending order BUYif (Price>Ask+2*Spreed)
{
Ticket1 = OrderSend(Symbol(),OP_BUYSTOP,1,Price,3,StopLossBuy,TpFirstOrder,"Pending Buy Order 1",16384,0,clrGreen);
if(Ticket1<=0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
{
Print("OrderSend placed successfully");
}
}elsePrint("The opening price is too close to the current price.");
if(
Close[1]<H4EMAprev &&
Close[1]<H1EMAprev
)
{
Price = NormalizeDouble(Low[1] - ((3 * 10) * Point),Digits());
TpOrderOne = NormalizeDouble(Price - ((10 * 10) * Point),Digits());
if (StopLossSell<Price+2*Spreed) Print("Not correct SL SELL");
//Pending order BUYif (Price<Bid-2*Spreed)
{
Ticket1 = OrderSend(Symbol(),OP_SELLSTOP,1,Price,3,StopLossSell,TpFirstOrder,"Pending Buy Order 1",16384,0,clrGreen);
if(Ticket1<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
{
Print("OrderSend placed successfully");
}
}elsePrint("The opening price is too close to the current price.")
}
Try this code. I didn't check it myself. The point is: the open Price of BUY STOP should be higher than the current price plus two spreads (I use two spreads instead of MarketInfo (Symbol (), MODE_STOPLEVEL)), SL should be lower than the open price. The open price of the SELL STOP should be below the current price and minus two spreads, SL should be above the open price plus two spreads.
............
TpOrderOne = NormalizeDouble(Price + ((10 * 10) * Point),Digits());
.....................
if (Price>Ask+2*Spreed)
{
Ticket1 = OrderSend(Symbol(),OP_BUYSTOP,1,Price,3,StopLossBuy,TpFirstOrder,"Pending Buy Order 1",16384,0,clrGreen);
Note that it is not clear from your code what the value of the variable is TpFirstOrder. In the code, it is not implanted anywhere of any value.
Try this code. I didn't check it myself. The point is: the open Price of BUY STOP should be higher than the current price plus two spreads (I use two spreads instead of MarketInfo (Symbol (), MODE_STOPLEVEL)), SL should be lower than the open price. The open price of the SELL STOP should be below the current price and minus two spreads, SL should be above the open price plus two spreads.
This is the difference between Ask and Bid. I used two spreads, because it happens that the value of MarketInfo (Symbol (), MODE_STOPLEVEL) is zero. If it is equal to zero, it means that it is "floating" and each time can be different. Therefore, I usually use the value of two spread sizes ((Ask-Bid)*2 ).
Try this code. I didn't check it myself. The point is: the open Price of BUY STOP should be higher than the current price plus two spreads (I use two spreads instead of MarketInfo (Symbol (), MODE_STOPLEVEL)), SL should be lower than the open price. The open price of the SELL STOP should be below the current price and minus two spreads, SL should be above the open price plus two spreads.
Note that it is not clear from your code what the value of the variable is TpFirstOrder. In the code, it is not implanted anywhere of any value.
//+------------------------------------------------------------------+//| MyPending.mq4 |//| Copyright 2018, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2018, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"#property strictdouble
H1EMA, H1EMAprev, H4EMA, H4EMAprev, StopLossBuy, StopLossSell, Price, TpOrderOne;
int
MagicNo = 4352, Ticket1, Ticket2, Ticket3;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//---
H1EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H1,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
H4EMAprev = NormalizeDouble(iMA(NULL,PERIOD_H4,14,0,MODE_EMA,PRICE_CLOSE,1), 5);
StopLossBuy = NormalizeDouble(High[2] + ((3 * 10) * Point),Digits());
StopLossSell = NormalizeDouble(Low[2] - ((3 * 10) * Point),Digits());
double Spreed = Ask-Bid;
if(
Close[1]>H4EMAprev &&
Close[1]>H1EMAprev
)
{
Price = NormalizeDouble(High[1] + ((3 * 10) * Point),Digits());
TpOrderOne = NormalizeDouble(Price + ((10 * 10) * Point),Digits());
if (StopLossBuy>Price-2*Spreed) Print("Not correct SL BUY");
//Pending order BUYif (Price>Ask+2*Spreed)
{
Ticket1 = OrderSend(Symbol(),OP_BUYSTOP,1,Price,3,StopLossBuy,TpOrderOne,"Pending Buy Order 1",16384,0,clrGreen);
if(Ticket1<=0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
{
Print("OrderSend placed successfully");
}
}elsePrint("The opening price is too close to the current price.");
}
if(
Close[1]<H4EMAprev &&
Close[1]<H1EMAprev
)
{
Price = NormalizeDouble(Low[1] - ((3 * 10) * Point),Digits());
TpOrderOne = NormalizeDouble(Price - ((10 * 10) * Point),Digits());
if (StopLossSell<Price+2*Spreed) Print("Not correct SL SELL");
//Pending order BUYif (Price<Bid-2*Spreed)
{
Ticket1 = OrderSend(Symbol(),OP_SELLSTOP,1,Price,3,StopLossSell,TpOrderOne,"Pending Buy Order 1",16384,0,clrGreen);
if(Ticket1<0)
{
Print("OrderSend failed with error #",GetLastError());
}
else
{
Print("OrderSend placed successfully");
}
}elsePrint("The opening price is too close to the current price.");
}
}
//+------------------------------------------------------------------+
Here it is TpFirstOrder = 10 which you have already set in
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
If the error persists, check that the SL and TP are not closer than SYMBOL_TRADE_STOPS_LEVEL.
Also, the order opening price should not be closer than MarketInfo (Symbol(), MODE_STOPLEVEL) to сurrent price.
If MarketInfo (Symbol (), MODE_STOPLEVEL) is equal to zero, then this value is floating and it is necessary to use an offset from the current price of at least two spreads.
STOPLEVEL = Getting 8.0Still not understanding the issue
You are setting the TP at 20 points, that is ridiculously close. If the spread is 20 Points or more the trade would be closed immediately if it was opened.
Is this is the main reason or getting 130 error?
You are setting the TP at 20 points, that is ridiculously close. If the spread is 20 Points or more the trade would be closed immediately if it was opened.
Could you write an example code with dummy values ?
I want for pending sell order SL to be 3 pips below of 2nd last candle i.e ( SL = Low[2] - 3 pips)
TP = TradeOpenPrice - 10 pips
TradeOpenPrice = Low[1] - 3 pips
how could I code this? Please write an example code I am stuck on this unable to understand.
I want my EA to work in this manner:
Try this code. I didn't check it myself. The point is: the open Price of BUY STOP should be higher than the current price plus two spreads (I use two spreads instead of MarketInfo (Symbol (), MODE_STOPLEVEL)), SL should be lower than the open price. The open price of the SELL STOP should be below the current price and minus two spreads, SL should be above the open price plus two spreads.
Note that it is not clear from your code what the value of the variable is TpFirstOrder. In the code, it is not implanted anywhere of any value.
Try this code. I didn't check it myself. The point is: the open Price of BUY STOP should be higher than the current price plus two spreads (I use two spreads instead of MarketInfo (Symbol (), MODE_STOPLEVEL)), SL should be lower than the open price. The open price of the SELL STOP should be below the current price and minus two spreads, SL should be above the open price plus two spreads.
What is spreads? why u have used it?
What is spreads? why u have used it?
This is the difference between Ask and Bid. I used two spreads, because it happens that the value of MarketInfo (Symbol (), MODE_STOPLEVEL) is zero. If it is equal to zero, it means that it is "floating" and each time can be different. Therefore, I usually use the value of two spread sizes ((Ask-Bid)*2 ).
Try this code. I didn't check it myself. The point is: the open Price of BUY STOP should be higher than the current price plus two spreads (I use two spreads instead of MarketInfo (Symbol (), MODE_STOPLEVEL)), SL should be lower than the open price. The open price of the SELL STOP should be below the current price and minus two spreads, SL should be above the open price plus two spreads.
Note that it is not clear from your code what the value of the variable is TpFirstOrder. In the code, it is not implanted anywhere of any value.
Here it is TpFirstOrder = 10 which you have already set in
but your code is still not working still getting error.
See the log messages, most of the errors are not correct SL