EA will send sell order but not buy orders

 

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;
}
//----
}

 

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.

What are Function return values ? How do I use them ?

 

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); 

Reason: