Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
Please edit your post and use the code button (Alt+S) when pasting code.
EDIT your original post, please do not just post the code correctly in a new post.
Please remove all the unnecessary empty lines in your codes. It makes it easier for others to read.
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 Everyone,
i hope you guys can assist me. I have very little experience with MQL5 but im not sure why im getting an invalid price error sometimes when running my EA. Below is example of my code. I think somtimes the market spikes to quickly for my EA to open pending order therefore the price is invalid. The issue is that the pending order doesnt get set unless price move above say set price for the initial order.
int pen = OrdersTotal();
int i = PositionsTotal();
if(i<= 0)
{
double topline = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
if(!trade.Buy(0.2,NULL,topline,0,0,NULL))
Alert("OrderSend error %d",GetLastError());
if(!trade.SellStop(0.5,topline-diff,NULL,0,0,ORDER_TIME_GTC,0,NULL))
Alert("OrderSend error %d",GetLastError());
}
else
if(i== 1 && pen ==1)
{
/* checking the first trade profits*/
if(AE - AB >= target)
{
CloseBuySellSymbol();
}
}
else
{
/* checking the consolidation profits*/
if(AE - AB >= target2 || AB - AE >TakeLoss)
{
CloseBuySellSymbol();
}
if(i==2 && pen <=0)
{
double B3 = FetchingBPrice();
if(!trade.BuyStop(1.0,B3,NULL,0,0,ORDER_TIME_GTC,0,NULL))
Alert("OrderSend error %d",GetLastError());
}
else
if(i==3 && pen <=0)
{
double B4 = FetchingBPrice();
if(!trade.SellStop(1.8,B4,NULL,0,0,ORDER_TIME_GTC,0,NULL))
Alert("OrderSend error %d",GetLastError());
}
else
if(i==4 && pen <=0)
{
double B5 = FetchingBPrice();
if(!trade.BuyStop(3.2,B5,NULL,0,0,ORDER_TIME_GTC,0,NULL))
Alert("OrderSend error %d",GetLastError());