Total++; // Counter of market orders if (Total<1) // No more than one order { Alert("Several market orders. EA does not work."); return; // Exit start() }
The IF must be outside the FOR loop and you want (Total>1)for(int i=1; i>=OrdersTotal(); i++) // Loop through orders { if (OrderSelect(i-1,SELECT_BY_POS)==true) // If there is the next one { // Analyzing orders: if (OrderSymbol()!=Symb)continue;
I>=OrdersTotal means an infinite loop. You must count down for modify/close/delete in the presense of multiple orders (multiple charts) No check for magic number makes it incompatible with any other EA including itself on another chart. if(true==true) is redundant.for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and my pair.
New_Bar=0;
You're using an int as a bool. Replace with bool New_Bar=false;Long_SL=Open[0]-Low[1]+5*Point; // SL set 5 pips below pin bar low
5 points below the low is Low[1]-5*Point- EA's must adjust for 4/5 digit brokers. The minimum SL is usually 3 pips (broker dependent.) On a 5 digit broker 5*point is 1/2 pip. Must modify TP, SL, AND slippage.
//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
On ECN brokers you must open the order and then set stops. OrderSend(Symb,OP_SELL,Lots(),Bid,2,Short_SL,Short_TP)
Always test return codesint ticket=OrderSend(... if (ticket<0) Alert("OrderSend failed: ",GetLastError());
double Lot = NormalizeDouble( AccountEquity()*Pct_Risk/100/1000, 1); // Calculate the amount of lots if (Lot<0.1)Lot = 0.1;
Assumes minlot is 0.1 and lotstep is also 0.1.double minLot = MarketInfo(Symbol(), MODE_MINLOT), lotStep = MarketInfo(Symbol(), MODE_LOTSTEP), size = AccountEquity()*Pct_Risk/100/1000, Lot = MathFloor(size/lotStep)*lotStep; if (Lot < minLot) Lot = minLot;

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
After studying up on MQL4 for a few weeks, I decided to create my first EA. The principle is to look for a pin bar (hammer) to form within the trend (prices vs 20EMA) and buy on the open of a new bar with 2 pips to TP for each pip to SL. After some initial hiccups, I finally got the EA to compile...unfortunately it doesn't show any trades conducted in strategy tester.
Are there obvious issues with this code? I'm sure I'm missing something basic but another set of eyes can usually spot things better!
Thanks!