Hi Folks,
I've been working on this EA. the idea is to follow the trend and enter at pull backs. The problem is when the trend stalls and reverse, we don't know whether it's for real or just another pull back. So I programed the EA to enter an opposite trade with larger position with the hope that it will breakeven.
I don't intent to discuss the strategy itself, but rather, I have a technical problem. That is, my trade (market order) should only open in opposite direction of the last trade. So I did this in my Buy Trade function
It works well. What puzzles me is that I did the same for my Sell Trade function, but it won't execute any Sell Trade. The code goes like this
What did I do wrong? Any help is much appreciated.
Check your lastbuy() function
Thanks for the suggestion. I've indeed checked the lastbuy() many times. Here it is.
double lastbuy(void) { double priceBought=0; orders_total=OrdersTotal(); for(int pos=orders_total-1; pos>=0; pos--) { if(!OrderSelect(pos, SELECT_BY_POS, MODE_TRADES)) continue; if(OrderSymbol()!=Symbol())continue; if(OrderMagicNumber()!=MagicNumber) continue; // not our order if(OrderType()==OP_BUY) { priceBought=OrderOpenPrice(); break; } else continue; } //--- return(priceBought); }

- 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 Folks,
I've been working on this EA. the idea is to follow the trend and enter at pull backs. The problem is when the trend stalls and reverse, we don't know whether it's for real or just another pull back. So I programed the EA to enter an opposite trade with larger position with the hope that it will breakeven.
I don't intent to discuss the strategy itself, but rather, I have a technical problem. That is, my trade (market order) should only open in opposite direction of the last trade. So I did this in my Buy Trade function
It works well. What puzzles me is that I did the same for my Sell Trade function, but it won't execute any Sell Trade. The code goes like this
What did I do wrong? Any help is much appreciated.