I am just starting to learn MQL4 and working toward building an EA one step at a time, I am at the first step and can't figure out why I can't get it to open a trade. Any ideas? Code is below
//--- input parameters
extern int CCIperiod = 14;
extern double StopTradingBalance = 1000;
extern int HighTimeFrameEMA = 0;
extern int MediumTimeFrameEMA = 0;
extern int LowTimeFrameEMA = 0;
extern double LotSize = 0.01;
double CurrentCCIReading ();
extern double StopTradingBalance();
extern int MagicNumber = 1234;
//| Expert initialization function |
//| Expert deinitialization function |
void OnDeinit(const int reason)
//| Expert tick function |
//---CCI function values
double PreviousCCIReading = iCCI(NULL,5,15,0,2);
double CurrentCCIReading = iCCI(NULL,5,15,0,1);
if(PreviousCCIReading > 100 && CurrentCCIReading < 100)
if(AccountBalance() > StopTradingBalance)
OrderSend(Symbol(),OP_SELL, LotSize, Bid, 3,Bid,Bid,NULL, MagicNumber, 0,Green);
I don't have any errors but it won't enter a trade on the tester, the only if statement I have left is the "if(PreviousCCIReading > 100)". does the order send line look right? "OrderSend(Symbol(),OP_SELL, LotSize, Bid, 3,Bid,Bid,NULL, MagicNumber, 0,Green);"
Remove the parentheses . They not functions
Finally this will never be evaluated to true . Simply you are comparing against empty value which it very big number sure yojr balance will not be greater than it
yeah, no errors at compile. I have changed the OrderSend line to "OrderSend(Symbol(), OP_SELL, LotSize, Bid, 3,Bid+(StopLoss*Pips),Bid- (TakeProfit*Pips),NULL, MagicNumber, 0,Green);" Now it is entering trades when I want the EA to do so. I have taken the parenthesis out of "PreviousCCIReading" and "CurrentCCIReading". I had to comment out the "StopTradingBalance" variable because when I took out the parenthesis it gave me an error at compile saying that it had already been defined. the gaol behind the StopTradingBalance is to not allow any trades if the account balance falls below the stop trading balance as the EA will be running when I sleep. Any ideas for that?
double CurrentCCIReading ();
Irrelevant, extern double StopTradingBalance(); should not compile. An extern can not be a function, so the compiler is taking that as A) an extern double variable with no default value, or B) it is an declaration of a function returning a double, but you never define the function and never call it. It does nothing but confuse the compiler so line with StopTradingBalance should not compile.
All bets are off until you write correct code.
You can't have the SL and TP closer to the market than the minimum
(MODE_STOPLEVEL * _Point /
Requirements and Limitations in Making
Trades - Appendixes - MQL4 Tutorial
Just add this to the top of your code
Edit your original post. Click where you want the code to go. Alt-S and paste your code in the pop up. Click insert.
Click image to play: