Hello, I'm wokring on a code for simple earnings on M5/M15/M30, just so I don't have to work while studying :P Jokes on side.
I can't get it to work like I'd like to, I want it to close positions when middle bollinger band is touching the candle. Here's that part of code. I've tried many different options but i still can't get it right.
I'm also receiving (the only error) OrderSend Error 130, but the positions are opened correctly, seems like it's an error for closing position
here is your code
//+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CloseMiddleBB() { bool MiddleBB=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0); //// 20 SMA is same as middle of BB bool res; for(int i=0; i<=OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS)== true) { if( ((High[0] || Low[0])>= MiddleBB ) || (((High[0]) || (Low[0]))<= MiddleBB )) { if(OrderType()== OP_BUY) res= OrderClose(OrderTicket(),OrderLots(),Bid,30,Yellow); if(OrderType()==OP_SELL) res= OrderClose(OrderTicket(),OrderLots(),Ask,30,Green); } } } } //+------------------------------------------------------------------+
here is your code
for(int i=0; i<=OrdersTotal(); i++)incorrect? It's not like I'm writing this post after 5 minutes of trying to do it myself. I've read a lot that we should use this one execpt
for(int i = OrdersTotal()-1; i >= 0; i--)
as your order change their numbers whenever you close the first one. For eg. you have 3 orders, if you close first one at first, the second one is now numbered as first and so on, so you will close only one position with your loop and make it infinite. Am I wrong?
EDIT: or else, one position will never be closed.
EDIT2: Checked your code, doesn't work either.
which ever loop you use, you will be fine, i have some functions like that and it works perfectly
you need to define for a sell and a buy if Low/ high should be higher or lesser than SMA the given code will close almost every order

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I'm wokring on a code for simple earnings on M5/M15/M30, just so I don't have to work while studying :P Jokes on side. MQL4!!!
I can't get it to work like I'd like to, I want it to close positions when middle bollinger band is touching the candle. Here's that part of code. I've tried many different options but i still can't get it right.
I'm also receiving (the only error) OrderSend Error 130, but the positions are opened correctly, seems like it's an error for closing position
Oh and I forgot, NO, the StopLoss or Take Profit are not too close to market price etc. here's an example of a trade and the point where it should close the position. (BBex.png) The lower bollinger bang is the middle one, when it touches the candle i want to close the position.