Some coding suggestions

 

Hi All

I would like to sugest a couple of coding practises which may change the professionalism of the EAs being delivered. There are many good reasons for doing this, but the main one being that the people who may be able to make the best improvements to the EAs and therefore make them more profitable and less risky, are not good programmers.

1. Hide the logic!

The start routine is usually one enormous mess of code and cryptic variables. What it should be is the step-by-step processing that is required to make the EA function. Take the cryptic logic and put it into functions and name those functions very explicitly using Hungarian notation, for example:

int start()

{

double tradeLots = Lots;

int tradeTicket = 0;

bool enterTrade = evaluateTradingConditions();

if (enterTrade) {

tradeLots = getTradeLotSize();

tradeTicket = placeTradeAndRecordToLog();

if (tradeTicket==0) {

logFailure(tradeTicket);

}

}

}

bool evaluateTradingConditions() {

bool canTrade = false;

bool oversold = false;

double macdMain = iMACD(....

double macdSignal = iMACD(....

if (macdMain>macdSignal) {

oversold = checkRSIForOverSold();

if (oversold) {

canTrade = true;

} else {

canTrade = false;

}

}

return (canTrade);

}

... the EA becomes a lot easier to read, to debug and to get up to speed on. There is no mistaking the logic as each bit of logic is explicitly stated and programmer and non-programmer alike can read it.

2. Create libraries.

I don't have time to go into the details of how to structure the code, but the basic principle of using libraries to store one's logic and then to seperate the logic components into a flow which is obvious and break it into smaller, simpler steps than one big equation, will allow for the proper sharing of code and the proper expansion of a logic routine, instead of considering an EA to be a discrete piece of code.

3. Use templates as a starting point.

NEVER start an EA from scratch - NEVER! There should be pre-defined structures and options to choose from. These would incorporate all of the tried and tested standard functionality - found in libraries. Things like trailing stops, trend evaluation, market volatility, etc could even be put into standard templates with a section called "your trade entry code goes here..." and "your trade exit code goes here ...". Why spend months writing the same code as everyone else when it already exists - better than you could ever write it, in the public domain?

I'm out of time, but I hope this helps.

Reason: