double Cr1 = (ma1(1)<ma2(1)&&ma1(0)>ma2(0)); //(buy) double Cr2 = (ma1(1)>ma2(1)&&ma1(0)<ma2(0)); //(sell) if (Ask == Cr1) CloseAll(); if (Bid == Cr2) CloseAll();
- True is one and false is zero. So Cr1/2 is either zero or one. When will price ever be exactly that? Why are you assigning a boolean to a double?
Cr1 is meaningless.
This is why I say: You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.Had you used a meaningful name like hasCrossedUp then your if statement would have made no sense.Doubles are rarely equal.
The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum if(OrderType()<2) result=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,clrYellow);
Don't hard code numbers, use the proper constants.
You must RefreshRates after server calls (before the next select) when processing multiple orders.
Check your return codes for errors and report them.
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 Articlesticket=OrderSend(Symbol(),OP_BUY,NormalizeLots(LotManage(),Symbol()),Ask,3,SL,TP,EA_Comment,MagicNumber,0,clrBlue);
double LotManage() { return (NormalizeDouble(lots,2)); }
Why do you have a NormalizeLots function and then not use it?
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
I thank you in advance.