Tema Expert Advisor

Hallo,

hier ein vielversprechender Expert Advisor von mir. Der EA basiert auf dem Tema (Triple Exponential Moving Average) einem interessanten Indikator aus der Gruppe der gleitenden Durchschnitte. Es wird bei einem Cross zweier Perioden geöffnet/geschlossen, zusätzlich kann noch eine Trailing Stop mit ATR verwendet werden.

Der EA ist funktionsfähig, es fehlt jedoch die Fehlerbehandlung. Er könnte auch eine eigene magic Number gebrauchen.
Die externen Variablen sollte schon relativ gut eingestellt sein, können sicher noch optimiert werden.

Gruß

Dave


//+------------------------------------------------------------------+
//| temaEA.mq4 |
//| |
//| |
//+------------------------------------------------------------------+
#property copyright "www.aomt.de"
#property link "www.aomt.de"

/* Defines */
#define DOWNWARD 2
#define UPWARD 1

extern int iPeriodShort = 56;
extern int iPeriodLong = 280;
extern int iAtrPeriod = 14;
extern bool bExtTrailingStopActive = FALSE;
extern double dPeriodMultiplikator = 7.0;

/* Global variables */
double dLots;
double dStopValue;
double dTakeValue;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
static int ticket = 0;
static datetime oldDate;
//----
if(oldDate != Time[0])
{
oldDate = Time[0];

dLots = 0.01;
if(ticket <= 0) { bEntryStrategy(Symbol(),ticket); } bClosingStrategy(Symbol(),ticket); if(bExtTrailingStopActive) { bClosingTrailing(Symbol(),iAtrPeriod,ticket); } } //---- return(0); } //+------------------------------------------------------------------+ void vResetTrailing(string sSymbol, int iTicket) { dStopValue = 0; dTakeValue = 0; } /* closing via trailing stop */ bool bClosingTrailing(string sSymbol, int iAtrPeriod, int &iTicket) { bool ret; double dAtr; double dValue; ret = TRUE; if(OrderSelect(iTicket,SELECT_BY_TICKET)) { dAtr = iATR(0,0,iAtrPeriod,0); if(OrderType() == OP_BUY) { dValue = MarketInfo(sSymbol,MODE_BID) - dAtr*dPeriodMultiplikator; if(dStopValue < dValue) { dStopValue = dValue; } if(dStopValue > MarketInfo(sSymbol,MODE_BID))
{
//close long
if(true == OrderClose(iTicket,OrderLots(),MarketInfo(sSymbol,MODE_BID),10))
{
iTicket = 0;
}
else
{
//handle error
}
}
}
else if(OrderType() == OP_SELL)
{
dValue = MarketInfo(sSymbol,MODE_ASK) + dAtr*dPeriodMultiplikator;
if((dStopValue == 0) || (dStopValue > dValue))
{
dStopValue = dValue;
}

if(dStopValue < MarketInfo(sSymbol,MODE_ASK)) { //close short if(true == OrderClose(iTicket,OrderLots(),MarketInfo(sSymbol,MODE_ASK),10)) { iTicket = 0; } else { //handle error } } } else { //handle Error } } else { //handle error } } /* closing via strategy */ bool bClosingStrategy(string sSymbol, int &iTicket) { bool ret; int iDirection; ret = TRUE; if(OrderSelect(iTicket,SELECT_BY_TICKET)) { bGetCross(Symbol(),Period(),iDirection); //upward cross occured -> close short
if(iDirection == UPWARD)
{
if(OrderType() == OP_SELL)
{
//close short
if(true == OrderClose(iTicket,OrderLots(),MarketInfo(sSymbol,MODE_ASK),10))
{
iTicket = 0;
}
else
{
//handle error
}
}
else
{
//handle error
}
}

//downward cross occured
if(iDirection == DOWNWARD)
{
if(OrderType() == OP_BUY)
{
//close long
if(true == OrderClose(iTicket,OrderLots(),MarketInfo(sSymbol,MODE_BID),10))
{
iTicket = 0;
}
else
{
//handle error
}
}
else
{
//handle error
}
}
}
else
{
//handle error
}
return (ret);
}

bool bEntryStrategy(string sSymbol, int &iTicket)
{
bool ret;
int iDirection;

ret = FALSE;

bGetCross(Symbol(),Period(),iDirection);

//upward cross occured
if(iDirection == UPWARD)
{
//go long
iTicket = OrderSend(sSymbol,OP_BUY,dLots,MarketInfo(sSymbol,MODE_ASK),10,0,0);
if(iTicket != -1)
{
ret = TRUE;
vResetTrailing(sSymbol,iTicket);
}
else
{
//handle error
}
}

//downward cross occured
if(iDirection == DOWNWARD)
{
//go short
iTicket = OrderSend(sSymbol,OP_SELL,dLots,MarketInfo(sSymbol,MODE_BID),10,0,0);
if(iTicket == -1)
{
ret = TRUE;
vResetTrailing(sSymbol,iTicket);
}
else
{
//handle error
}
}
}

bool bGetCross(string sSymbol, int iPeriod, int &iDirection)
{
double dOldTEMAshort, dOldTEMAlong;
double dNewTEMAshort, dNewTEMAlong;
bool ret;

dOldTEMAshort = iCustom(sSymbol,iPeriod,"tema",iPeriodShort,0,2);
dOldTEMAlong = iCustom(sSymbol,iPeriod,"tema",iPeriodLong,0,2);
dNewTEMAshort = iCustom(sSymbol,iPeriod,"tema",iPeriodShort,0,1);
dNewTEMAlong = iCustom(sSymbol,iPeriod,"tema",iPeriodLong,0,1);
ret = TRUE;

//upward cross occured
if((dOldTEMAshort < dOldTEMAlong) && (dNewTEMAshort > dNewTEMAlong))
{
iDirection = UPWARD;
}

//downward cross occured
if((dOldTEMAshort > dOldTEMAlong) && (dNewTEMAshort < dNewTEMAlong)) { iDirection = DOWNWARD; } }

Leave a Reply

Your email address will not be published. Required fields are marked *


6 − = five

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>