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

Start() function



The start() is the only one that is needed in order to work. This function is executed every tick is recieved in Metatrader. So you must set in this function all parameters and variables that have to be calculate at each tick and call the others functions based on it.
In CyberEA-Template, all function calls is envolved into trading hours variables.

void start(){
First piece of code of the loop: check for trade stratus and trade context:
bool tradeallowed=IsTradeAllowed();
if(!tradeallowed){
Print("Trade not allowed");
}
bool contextbusy=IsTradeContextBusy();
if (contextbusy){
Print("Trade context is busy");
}
Next part: On each tick CyberEA take the current time as value of the local variable named hour. Based on the value of hour we set the next action. On this way, if it's time to trade (we are set the trading hours in the external varialbes) . In this way if hour is equal to expiration hour the function Clean() (for close all orders) is called. If hour is between start and end hour the function CheckForSignal() (check for signal) is called. Also is called the function SearhPositions() (check for orders) and if SearchPositons() is not equal to zero the EA will call CheckForClose() (check for close). If SearchPositions() is equal to zero CheckForOpen() function (check for open) is called. Also I have to comment that TrailStop and BreakEven function will be called only if hour is between trading hours and if we have set it to true in the external variables.
int hour = Hour(); if (hour == Expiration) Clean(); if ((StartHour <= hour) && (EndHour >= hour)) {
CheckForSignal();
if (SearchPositions() != 0)
CheckForClose(); else CheckForOpen();
if (SearchPositions() != 0) {
if (UseTrailingStop == true) TrailStop();
if (UseBreakEven == true) BreakEven();
}
}

Commenting(); Commenting function is called on each tick.
}

0 coments: