Hi guys,
Im having a problem on a M5 EA for BB. When i set up the conditions for Buy orders, everything works perfect, but when i do with Sell, it ll looks perfect, but doesnt work, i ve printed all values so i could check for any reason , but cannot find. Can you help me with it ?
if(Bid<upper[0] && Open[0]>upper[0] && MA[0]<MA[1] ) { Print("---------- SELL ------------------"); for(int i = PositionsTotal()-1;i>=0;i--) { if(!position.SelectByIndex(i)) continue; if(position.Magic()==MagicNumber && position.Symbol()==_Symbol && position.PositionType()==POSITION_TYPE_BUY && TradeClosureOption1==true) { bool op = ExtTrade.PositionClose(position.Ticket()); if(!op){Print("Error closing opposite order ! Code : ",GetLastError());} else Print("Success closing trade : ",position.Ticket()); } } if(traded==false)OrderEntry(1); }
recheck these marked stuff. or your OrderEntry() function
i have checked them like a million times, this is the OrderEntry()
void OrderEntry(int direction) { double stoplevel=SymbolInfoInteger(Symbol(),SYMBOL_TRADE_STOPS_LEVEL)*point; int pts = 0; if(SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)==0.01)pts=2; if(SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN)==0.1)pts=1; double tp=0,sl=0,Lots; if(CashSize==0)Lots=LotSize; else Lots = NormalizeDouble((AccountInfoDouble(ACCOUNT_BALANCE)/CashSize)*LotSize,pts); if(direction==0) { if(TakeProfit>0){tp=Ask+TakeProfit*point;}else{tp=0;} bool buyop = ExtTrade.PositionOpen(_Symbol,ORDER_TYPE_BUY,Lots,SymbolInfoDouble(_Symbol,SYMBOL_ASK),sl,tp,"BB EA"); if(buyop) traded=true; } if(direction==1) { if(TakeProfit>0){tp=Bid-TakeProfit*point;}else{tp=0;} bool sellop = ExtTrade.PositionOpen(_Symbol,ORDER_TYPE_SELL,Lots,SymbolInfoDouble(_Symbol,SYMBOL_BID),sl,tp,"BB EA"); if(sellop) traded=true; } }
i have printed values, when i use the different parts of the condition separately, they work , but when together, they dont. Only when i combine the first two the problem occurs.
the "traded "variable is of global scope and is turned to false on new bar
but when i change the indices of the upper and MA , it starts to work
doesn't work/starts to work means it fails to open / opens positions ?
OR
it means it enters it wrong moments?
when you enter in current Ask/Bid price (using Ctrade functions), don't need to pass those price parameter.
and your lot size calculation is not OK to my (and probably others') eyes. round lot sizes to lot_step of symbol.
if the trade operation gets executed , check to see what is the returned code of TradeOperations ? (ResultRetCode()....)
if it's not executed at all, then your entrance conditions are messy/contradictory(impossible/rare to happen) or many other possible bugs.
you can check the content of CopyBuffer target arrays,after retrieving the buffers.
doesn't work/starts to work means it fails to open / opens positions ?
OR
it means it enters it wrong moments?
when you enter in current Ask/Bid price (using Ctrade functions), don't need to pass those price parameter.
and your lot size calculation is not OK to my (and probably others') eyes. round lot sizes to lot_step of symbol.
what i mean is when i change the shift of the open and the upper band it starts to take orders, before that i didnt
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys,
Im having a problem on a M5 EA for BB. When i set up the conditions for Buy orders, everything works perfect, but when i do with Sell, it ll looks perfect, but doesnt work, i ve printed all values so i could check for any reason , but cannot find. Can you help me with it ?
the show condition does not allow any code execution within it.
this is how i get bid/ask and the OHLC