Here you can download a Metatrader 4 Expert Advisor Template which you can use to start to build your automated system. The template has a lot of tools, all of them works fine (I use it on live), you only have to add the rules for open an close position. I've written this Expert Advisor, some piece of the code are mine, others has been modified from open source EAs I've found on the net.

The template includes a ma croos example for open and close position, it just an example, please don´t use it with real money!!!

Download CyberEA-Template

Check for Signals: The core of your system



This loop, in the code named CheckForSignal() es used to get the singal for open or close a trade.

The loop return the value of two bools, signalBuy and signalSell.
The result of this bools will be used to open or close positions.
Let going to see the example of the Expert Advisor CyberEA-Template.

In the template if signalBuy=true is a buy signal and if signalSell=true is a sell signal.

CyberEA gets the value of slowMA (Slow MA) and fastMA (Fast MA) and if fastMA>slowMA return signalBuy=true so, a buy signal.
This value will be called from check for open and check for close loops, wich we will see in other post, to take action.

Note that the settings of MA are selected from external variables that can be changed after compilation of the code.


void BuscarSenal()
{
if (time_now != Time[0])
{
time_now = Time[0];
slowMA = iMA(NULL,0,SlowMAPeriod,SlowMAShift,SlowMAMode,SlowMAApplyPrice,Bar);
fastMA = iMA(NULL,0,FastMAPeriod,FastMAShift,FastMAMode,FastMAApplyPrice,Bar);
}

signalSell = false;
signalBuy = false;
if (fastMA>slowMA) signalBuy = true;
if (slowMA>fastMA) signalSell=true;
goLong = signalBuy;
goShort = signalSell;
if (goLong || goShort) return;

if (BuscarOrdenes() != 0)
{
goLong = false;
goShort = false;
}
}