Moved to mql4 section.
Pedro Moreira:
Hi does somebody could help me?
I want the EA to set a Pending Sell Stop Order when I open manually a Buy Market Order, why this code isnt working?
At least:
if (OrdersTotal == 1 && OrderSelect(0,SELECT_BY_POS,MODE_TRADES) == OP_BUY)
But your code is really strange
- When you post code please use the CODE button (Alt-S)!
(For large amounts of code,
attach it.)
Please edit your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum int OrdersTotal; int OrderType; double OrderOpenPrice;
OrdersTotal, OrderType, and OrderOpenPrice are predefine functions. Your variables aren't going to do what you think. Does that even compile?if (OrdersTotal = 1 && OrderSelect(1,SELECT_BY_POS,MODE_TRADES) == OP_BUY)
Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forumSellTicket = OrderSend (Symbol(),OP_SELLSTOP,LotSize,PendingPrice,15,SellStopLoss,SellStopTP,"Sell Stop Order",MagicNumber,0,clrRed);
Check your return codes for errors, report them and you would know why.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi does somebody could help me?
I want the EA to set a Pending Sell Stop Order when I open manually a Buy Market Order, why this code isnt working?
// External
extern double LotSize = 0.1;
extern double StopLoss = 150;
extern double TakeProfit = 120;
extern double PendingPips = 30;
extern int MagicNumber = 123;
// Globals
int BuyTicket;
int SellTicket;
double UsePoint;
double PendingPrice;
double SellStopLoss;
double BuyStopLoss;
double SellStopTP;
double BuyStopTP;
int OrdersTotal;
int OrderType;
double OrderOpenPrice;
int start()
{
if (OrdersTotal = 1 && OrderSelect(1,SELECT_BY_POS,MODE_TRADES) == OP_BUY)
{
// Calculando Ordem
PendingPrice = OrderOpenPrice - (PendingPips * 0.01); //- 0.01 because its on a 2 decimal digits currency, would be 0.0001 for 4 and 5 digits
SellStopLoss = PendingPrice + (StopLoss * 0.01);
SellStopTP = PendingPrice - (TakeProfit * 0.01);
SellTicket = OrderSend (Symbol(),OP_SELLSTOP,LotSize,PendingPrice,15,SellStopLoss,SellStopTP,"Sell Stop Order",MagicNumber,0,clrRed);
}
return(0);
}