Help Getting EA to work with Metatrader

Hey everyone. I am very new to Forex Trading and completely new to EAs. I have tried to make an EA for Metatrader4 using this online “Expert Advisor Builder for MetaTrader 4” (Can’t include link in forums until I have 5 posts. Sorry. :)) , which I have attached, that tries to do the following:

BUY if:
Last 2 H1 ticks close above 14 EMA.
RSI is > 50 but < 70 for H1 charts.
Stocastic is increasing for H1 charts.

Last 2 M15 ticks close above 14 EMA.
RSI is > 50 but < 70 for M15 charts.
Stocastic is increasing for M15 charts.

RSI passes through 50 for M1 charts.

Stoploss = 7 and take profit = 15.

SELL if: (inverse of the above).

Anyways, attached is the EA from the builder linked. It compiles just fine but keeps giving “OrderSend error 130”. I did some Google searches and they some claimed the stoploss was too small. But even when I change StopLoss to 70 and TakeProfit to 150 I still get the same error.

Does anyone have any ideas I can do to fix this? Would anyone mid taking a few minutes and looking at my EA and see if there is a straightforward way to get it to work? Thanks a lot in advance.

My guess is, somewhere in that tangled bunch of > && < && < && > statements are most likely some conflicting rules that make trading conditions impossible.

Try taking out all but the first set of rules, and run it then. If it makes trades, you know it’s no longer lot size issues, so then add the second set. If that makes trades, add the third, until you get to the one that makes it stop.

BTW, coding like that makes your program really slow. You need to nest them differently, so that if the first set of conditions aren’t true, it won’t even bother going to the second set. This thing cycles through way too often looking for the lineup of conditions you have coded.

And I don’t see digit accounting for 5 digit brokers, so your assumption that the setting of 7 needs to be 70 to make 7 pips is correct. But that’s not causing it to not make trades.

BTW, I know it’s working because my tester ran very very slow as it cycled through your code.

Debugging an early version of an EA is where you’ll spend most of your time.

Try this. It should make trades now, it did for me:)

Your Expert Advisor.zip (2.37 KB)

Master Tang,

Thank you very much. I really appreciate it. Was the problem just nested loops issues?

I came across your inquiry just by chance (I almos never visit this forum!) and thought about taking a look at the code of your EA. I ran it on the simulator and got the same problem as you. Error 130 refers to “erroneous or unnormalized stop levels”.

The EA’s open order instruction is

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, “Buy(#” + MagicNumber + “)”, MagicNumber, 0, DodgerBlue)

where

StopLossLevel = Bid + StopLoss * Point

and

TakeProfitLevel = Bid - TakeProfit * Point

By default, StopLoss = 7 and TakeProfit = 15

Your problem is that you are using a broker who provides 5 decimals for all pairs except for those related to JPY, and 3 for the JPY pairs, and neither the stoploss or the takeprofit levels are taking this into consideration. So, for pairs whose price has 5 decimals, Point = 0.00001

Say the EA opens a buy order on EURUSD at Ask = 1.25000. Then
StopLossLevel = 1.25000 + 7*0.00001 = 1.25000 + 0.00007 = 1.25007.

The stoploss level is calculated at only 0.7 pip from the order entry price!

So is the take profit level:

TakeProfitLevel = 1.2500 + 15*0.00001 = 1.25000 + 0.00015 = 1.25015, only 1.5 pips from the order entry price.

I see the same situation on all the OrderModify instructions.

This is resolved by the susbtituting “Point” by “10*Point” in the code of all calculations concerning stoploss and takeprofit levels to be used by OrderSend() & OrderModify(). I did it and it works fine. Note that the EA won’t work correctly if you decide to apply it on a chart providing only 4 decimal places!

Thanks Malabar.

As you may run this on other currency or broker account, try retrieve Point and compare with 0.00001, 0.0001, 0.001, 0.01 and use a predefine multiplier “pts” on all your order execution.

To become a successful MQL programmer you must learn it by yourself then you can use tools to build EA quickly. So please visit MQL site and learn basics of MQL programming before building any EA. Otherwise it may contain bugs that will make problem in real money trading. I think building EA without learning MQL is very risky.