Simpler EA, aber mehrere Timeframes
Hi, habe mir einen simplen EA gebaut. Die Regeln sind:
Gehe Long, wenn: ((Close(1) > SMA(200) im 4h Chart) And ((Close(1) > SMA(200)im 1h Chart) And (EMA(5)im 15min Chart Crosses Above SMA(200) im 15min Chart)))
Gehe Short, wenn: ((Close(1) < SMA(200) im 4h Chart) And ((Close(1) < SMA(200)im 1h Chart) And (EMA(5)im 15min Chart Crosses below SMA(200) im 15min Chart)))
Dann gilt jeweils ein Take Profit von: AverageTrueRange(Periode 2) * einer Konstanten
und ein StopLoss von: AverageTrueRange(Periode 2) * einer Konstanten
Wie ihr vieleicht gemerkt habt benutzt der EA 3 verschiedene Timeframes nämlich: 4h, 1h und 15min.
Ich wollte den EA in Metatrader Testen, aber es kommen immer 0 Trades raus, egal auf welcher Zeitbasis ich simuliere - ist wohl klar - scheinbar kann man einen EA, der mehrere Zeitbasen verwendet nicht simulieren ?
Deshalb wollte ich euch mal fragen, ob ihr mal drübergucken könnt und mir sagen könnt ob er funktionieren kann. (Nur von der Funktion - nicht vom Profit ;) )
Dann hab ich glaube ich noch ein Problem:
Bevor ich eine Order öffne, frage ich mit OrdersTotal() ab, ob schon eine Order existiert. Ich will damit erreichen, das nur immer eine Order pro Symbol offen ist. Ich will den EA auf vielen Symbolen gleichzeitig laufen lassen. Dann würde die Abfrage aber dazu führen das es immer nur insgesamt nur eine Order gibt oder ? Ich brauche es aber so das es pro Symbol nur eine Order geben kann ...
So hier kommt der Code, ist nich viel, währe euch dankbar für eure Hilfe :)
Code:
//+------------------------------------------------------------------+
//| My_First_EA.mq4 |
//| M.W. |
//| |
//+------------------------------------------------------------------+
#property copyright "M.W."
#property link ""
//--- input parameters
extern double AtrPeriod=2;
extern double ATR_Faktor_tp=4;
extern double ATR_Faktor_sl=2;
extern double Lots=0.1;
// interne Variablen
double TakeProfit=0.0;
double StopLoss=0.0;
double atrValue=0.0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
int cnt, ticket, total;
if(Bars<100)
{
Print("bars less than 100");
return(0);
}
// LONG: ((Close(1) > SMA(200) im 4h Chart) And ((Close(1) > SMA(200)im 1h Chart) And (EMA(5)im 15min Chart Crosses Above SMA(200) im 15min Chart)))
bool LongEntryCondition = ((Close[1] > iMA(NULL, PERIOD_H4, 200, 0, MODE_SMA, PRICE_CLOSE, 1)) && ((Close[1] > iMA(NULL, PERIOD_H1, 200, 0, MODE_SMA, PRICE_CLOSE, 1)) && ((iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, PRICE_CLOSE, 2) < iMA(NULL, PERIOD_M15, 200, 0, MODE_SMA, PRICE_CLOSE, 2)) && (iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, PRICE_CLOSE, 1) > iMA(NULL, PERIOD_M15, 200, 0, MODE_SMA, PRICE_CLOSE, 1)))));
// SHORT: ((Close(1) < SMA(200) im 4h Chart) And ((Close(1) < SMA(200)im 1h Chart) And (EMA(5)im 15min Chart Crosses below SMA(200) im 15min Chart)))
bool ShortEntryCondition = ((Close[1] < iMA(NULL, PERIOD_H4, 200, 0, MODE_SMA, PRICE_CLOSE, 1)) && ((Close[1] < iMA(NULL, PERIOD_H1, 200, 0, MODE_SMA, PRICE_CLOSE, 1)) && ((iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, PRICE_CLOSE, 2) > iMA(NULL, PERIOD_M15, 200, 0, MODE_SMA, PRICE_CLOSE, 2)) && (iMA(NULL, PERIOD_M15, 5, 0, MODE_EMA, PRICE_CLOSE, 1) < iMA(NULL, PERIOD_M15, 200, 0, MODE_SMA, PRICE_CLOSE, 1)))));
total = OrdersTotal();
if(total < 1)
{
if(LongEntryCondition == 1) /// Long Position
{
// StopLoss und Take Profit berechnen
atrValue = iATR(NULL, PERIOD_M15, AtrPeriod, 1);
StopLoss=atrValue*ATR_Faktor_sl;
TakeProfit=atrValue*ATR_Faktor_tp;
//
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Bid-StopLoss*Point,Ask+TakeProfit*Point,"My EA",12345,0,Green);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print("Error opening BUY order : ",GetLastError());
return(0);
}
if(LongEntryCondition == 1) /// Fast MA kreuzt slow MA von oben nach unten -> Short Position
{
// StopLoss und Take Profit berechnen
atrValue = iATR(NULL, PERIOD_M15, AtrPeriod, 1);
StopLoss=atrValue*ATR_Faktor_sl;
TakeProfit=atrValue*ATR_Faktor_tp;
//
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"My EA",12345,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ", OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}
}
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
|