Use the GetLastError() and Print() to help narrow down why it's not working.
Defualty:
Hey all, I'm trying to figure out the EA I'm developing will not send any buy orders. It compiles fines and the code for opening buy orders is virtually identical to the sell orders but for some reason the program will not open them even if the conditions have been more than met. Here is the code in question and I'll attach the full EA if it may be of any use. Thanks in advance.
You have a variable call res . . . why don't you make use of it ? then you might know what is going on.
Hi Defualty,
You have this
percentB = (PRICE_CLOSE - Lbands)/(Ubands - Lbands);
PRICE_CLOSE is defined as price constant 0 (https://docs.mql4.com/constants/prices)
Try this instead
percentB = (Close[0] - Lbands)/(Ubands - Lbands);

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
Hey all, I'm trying to figure out the EA I'm developing will not send any buy orders. It compiles fines and the code for opening buy orders is virtually identical to the sell orders but for some reason the program will not open them even if the conditions have been more than met. Here is the code in question and I'll attach the full EA if it may be of any use. Thanks in advance.
void CheckForOpen()
{
int res;
double Ubands, Lbands, percentB;
double ma, MFI;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
RefreshRates();
//---- get Indicators
Ubands=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
Lbands=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
ma=iMA(NULL,0,MovingPeriod,0,MODE_SMA,PRICE_CLOSE,0);
percentB=(PRICE_CLOSE-Lbands)/(Ubands-Lbands);
MFI=iMFI(NULL,0,10,0);
//---- sell conditions
if (percentB<(1/5) && MFI<25)
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,5,Bid+300*Point,Bid-600*Point,"",MAGICMA,0,Red);
return;
}
//---- buy conditions
if(percentB>(4/5) && MFI>75)
{
res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,5,Ask-300*Point,Ask+600*Point,"",MAGICMA,0,Blue);
return;
}
//----
}