Skip to content

Instantly share code, notes, and snippets.

@currencysecrets
Created December 18, 2013 09:02
Show Gist options
  • Select an option

  • Save currencysecrets/8019377 to your computer and use it in GitHub Desktop.

Select an option

Save currencysecrets/8019377 to your computer and use it in GitHub Desktop.
This is how my MetaTrader Expert Advisor framework formed throughout 2013. I found myself storing much information into variables and would then recalibrate those variables depending upon fixed time periods.
//+------------------------------------------------------------------+
//| MetaTrader EA Framework.mq4
//| Copyright 2013, Ryan Sheehy
//| http://www.currencysecrets.com
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, Ryan Sheehy"
#property link "http://www.currencysecrets.com"
//--- global variables (keep capitalised)
string VERSION = "1.0.0";
//--- global time variables - needs to correspond to
//--- every different type of time period you use, eg.
// datetime NOWM1, NOWH1, NOWH4, NOWD1, NOWW1;
//--- global gate variables that store double values, eg.
// double GATE_VOLT, GATE_OPEN, GATE_DRAWDOWN;
//--- global gate variables that store integer values, eg.
// int GATE_TREND;
//--- global gate variables that store boolean values, eg.
// bool GATE_ACTIVE, GATE_TRADE_DATE;
//--- global input parameters, eg.
// extern int EXT_BARS = 60;
// extern double EXT_ATR_MULTIPLIER = 2.5;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
string sym = Symbol();
//--- run functions for GATE variables and have them
//--- store their data into their variables, eg.
// GATE_TREND = getTrend( sym );
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
string sym = Symbol();
//--- run functions to alert of deactivation of EA
//--- from this symbol, eg.
// alertMe( "DEINIT for " + sym );
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
datetime t;
string sym = Symbol();
//--- run this function every tick
if ( Bid > 0 ) {
doPerTick( sym );
}
//--- run this function every 1 minute
t = iTime( sym, PERIOD_M1, 0 );
if ( NOWM1 != t ) {
doPerMinute( sym, PERIOD_M1 );
NOWM1 = t;
}
//--- run this function every 1 hour
t = iTime( sym, PERIOD_H1, 0 );
if ( NOWH1 != t ) {
doPerHour( sym, PERIOD_H1 );
NOWH1 = t;
}
//--- run this function every 4 hours
t = iTime( sym, PERIOD_H4, 0 );
if ( NOWH4 != t ) {
doPerHour( sym, PERIOD_H4 );
NOWH4 = t;
}
//--- run this function every day
t = iTime( sym, PERIOD_D1, 0 );
if ( NOWD1 != t ) {
doPerDay( sym, PERIOD_D1 );
NOWD1 = t;
}
//--- run this function every week
t = iTime( sym, PERIOD_W1, 0 );
if ( NOWW1 != t ) {
doPerWeek( sym, PERIOD_W1 );
NOWW1 = t;
}
return(0);
}
//+------------------------------------------------------------------+
void doPerTick( string sym ) {
}
void doPerMinute( string sym, int per ) {
}
void doPerHour( string sym, int per ) {
if ( per == PERIOD_H1 ) {
} else if ( per == PERIOD_H4 ) {
}
}
void doPerDay( string sym, int per ) {
}
void doPerWeek( string sym, int per ) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment