EA coding help needed for study purpose. - page 2

 
erzo:

RaptorUK,

My is a very bad example for real account, but it's enough for strategy tester, and begin to play with coding and see how the visual tester trading with it. Learning how indicators can combine.

It is a ten-row-snippet, same that i'm seaching for when I start coding something that new to me, least code, that focuses to the essence. As java developer my life was saved by such ten rows many times, because almost everything has been programmed and discussed of for now. With mq4 code searching is different, developers seems not willing to share codes, maybe because it is all of money, and a working idea is working only while just a few people using it.

Error handling is the hardest task, and after 800 row of it I'm at nowhere, and not sure I ever dare place it on any real account. Best way to buy a proven ea from the top 5 and try fortune with it. But playing around indicators and visual tester hurts no one.

And as I see I could provocate even you to share some useful code...

...."With mq4 code searching is different, developers seems not willing to share codes" but You did. I believe You are one of the Very Few Good Guys out there. You are HIGHLY HIGHLY HIGHLY (HIGHLY)*to the power of Infinity* APPRECIATED.

 
RaptorUK:

It is what you need to learn.

Look at aany of the Trading Functions . . . for example, OrderSend() the Documentation says . . . "Returns number of the ticket assigned to the order by the trade server or -1 if it fails." so we chack the return value, if it is equal to -1 then we have an error . . . so we need to handle this error, "error handling".

A little bit of error handling and reporting goes a long way . . . if you make an error on the OrderSend then your error handling will catch it and report it to the log . . . then you can look at the log and have more chance of figuring out what is wrong and fixing it.

Thank You for the constructive criticism and for sharing the piece of information and idea. You are appreciated too.
 

There is as much code as you can eat shared here: https://www.mql5.com/en/code is it any good ? that is another question/issue.

There is some good code shared here: https://www.mql5.com/en/forum/133792

 
RaptorUK:

There is as much code as you can eat shared here: https://www.mql5.com/en/code is it any good ? that is another question/issue.

There is some good code shared here: https://www.mql5.com/en/forum/133792

The second one is really a good topic, full of brilliant idea, many thanks to it's participants.

But most of ea code base are poorly implemented scalping trader ea-s. Just see this: https://www.mql5.com/en/code/10604. At first sight it is the ticket to heaven, the equity curve is smoother than a ski-truck, but if you watch the trades, see that there was almost margin call many times, and the curve hides these. And downloads ten thousend.

As I see, these are for ea runners, who will accumlate some profits with a very known way, until at a sudden movement the ea gives all profit (and the whole account) back to the market, where experienced traders just waits for and profit from it. But the easiest profit is of brokers who likes these scalper robots, with their frequent trading, takes the comission of it, or worst case trading against it.

No fairy tale, this is a zero sum game, the interest rate and all the underlying economy changes are neglectible against the trading volume and costs, only the experienced few will profit anything. It all is similar to western gold-rush, where the best (legal) position was to sell digger to miners. Here is the same: sell EA-s to fortune players (of course not free).

 
erzo:
Hi,
This is the simplest EA I've ever seen :) For study purpose only, without any error handling.

extern int MacdFastEma = 12;
extern int MacdSlowEma = 26;
extern int MacdSignalSma = 9;
extern int CciPeriods = 14;

extern double Lots = 0.1;
extern double StopPoints = 300;
extern double TargetPoints = 600;

datetime LastCandleTime;

int init() {
   LastCandleTime = 0;
   return(0);
}

int start() {
   if (LastCandleTime == Time[0]) {
      return(0);
   }
   
   double MacdPrevPrev = iCustom(NULL, 0, "MACD", MacdFastEma, MacdSlowEma, MacdSignalSma, 0, 2);
   double MacdPrev =     iCustom(NULL, 0, "MACD", MacdFastEma, MacdSlowEma, MacdSignalSma, 0, 1);
   double CciPrev =      iCustom(NULL, 0, "CCI", CciPeriods, 0, 1);

   if (MacdPrevPrev < 0.0 && MacdPrev > 0.0 && CciPrev < 100.0) {
      if( !OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Bid - StopPoints * Point, Ask + TargetPoints * Point, "Example", 6384, 0, Green) )
         Print("Failed BUY order: error " + GetLastError() );
   }
   
   if (MacdPrevPrev > 0.0 && MacdPrev < 0.0 && CciPrev > -100.0) {
      if( !OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Ask + StopPoints * Point, Bid - TargetPoints * Point, "Example", 6384, 0, Red) )
         Print("Failed SELL order: error " + GetLastError() );
   }
   
   LastCandleTime = Time[0];
   return(0);
}

Now we have error reporting at least.

For what it's worth, I agree with you. Beginners need a few lines of code that do something in order to get them started. Giving them 1000 lines of WHR's advanced coding could only be considered a total overwhelm. When you lean a programming language they start of easy and let you print "Hello World" on the screen. You don't teach a baby to walk by starting it on an triathlon.

 

EURUSD, M30, StopPoints=600; TargetPoints=200; All of year 2010

114 trades and a Profit factor of 1.52


 
dabbler:

EURUSD, M30, StopPoints=600; TargetPoints=200; All of year 2010

114 trades and a Profit factor of 1.52



Some questions:

1. The trade result above, is it a good result? (considering the trade factor)

2. The code snippet immediately after the order opening conditions (see below)

Print("Failed SELL order: error " + GetLastError() );

I guess that the code for error reporting (to get last error) with respect to the error handling and reporting that was pointed out by "RaptorUK" is it?

"Dabbler" You are Highly appreciated for Your contribution.

 
I think you did not programm Anything yet, did you?
Shold start with here: https://book.mql4.com//
After successfully programmed at least ten Indicators alone,
and hand trading with them one month long on demo, come back to ea-programming.
It is definitely not for fully beginners.
 
erzo:
I think you did not programm Anything yet, did you?
Shold start with here: https://book.mql4.com//
After successfully programmed at least ten Indicators alone,
and hand trading with them one month long on demo, come back to ea-programming.
It is definitely not for fully beginners.


Not yet (but i have toyed around with some) but i have gone through the book and i am still studying it. Like i said before, I only started studying MQL4 with the hope of automating my trading strategy which is made up of a couple of custom indicators. The only problem I am having is "Time" (time which I don't have) Time to sit down breakdown and fully understand the Language, and "Time" (time which i never had as a result of My job) Time to sit down before a PC to analyse the market so as to trade (which is the initial reason why I decided to try and automate my strategy in the first place). I hope You can see where I am coming from. This is why i think i need all the help i can get. Thanks anyway. I really appreciate every single contribution.
 

I see. But if you have no time for it, you have no chance to automate anything.

Did you watch what your strategy does? It takes positions almost randomly, while you has any money on your account, with no limit. In 2010 there was a lucky year, in any other it would crash.

Why do you has no time? I think to earn some money with your job. But your money will vanish in the very first week if you not have a professional code. Surely do not want it to happen.

You WILL pay, if not to a professional coder, than to the market. And that will be much more expensive, at least 100x. That is the sense the phrase "Learn or Pay" that you read here in every second topic.

Reason: