ExpertAdvisor testato in ambiente Demo.
Simbolo EURUSD (Euro vs US Dollar)
Periodo 1 Ora (H1) 2013.08.07 17:00 - 2013.12.26 23:00 (2012.12.27 - 2013.12.27)
Parametri MaxR=0.02; RewRatio=2.1; candlesback=13; rifcandle=1; shift=6; PadAmount=9; HourExp=4;
Deposito iniziale 10.000,00 €
Profitto totale netto 5.200,23 €
Drawdown massimo 13.58%
Massimo vincite consecutive (profitto in denaro) 5 (2321.51)
Massimo perdite consecutive (perdita in denaro) 6 (-1601.93)
Operazioni totali 56
Operazioni con profitto (% del totale) 28 (50%)
Operazioni in perdita (% del totale) 28 (50%)
Questo EA prevede, l'autodeterminazione della quantità investita rischiando il 2% dell'equity per operazione e come regole d'ingresso:
- la formazione di un minimo/massimo relativo a n barre
- l'esistenza di un precedente minimo/massimo relativo a n barre, verificatosi s (shift) barre precedenti
- ingresso con ordine stop pendente (di durata max in ore= HourExp)
- ingresso long su minimo precedente oppure short sotto massimo precedente
Codice Sorgente
//+-------------------------------------------------------------------+
//| Tourtle Soup V1.mq4 |
//| Copyright 2013, Riccardo Placitelli |
//| http://forexsmartsharing.blogspot.it/ |
//+-------------------------------------------------------------------+
#property copyright "Copyright 2013, Riccardo Placitelli"
#property link "http://forexsmartsharing.blogspot.it/"
#define MAGICMA 31101985
extern double MaxR =0.02; // max % risk
extern double RewRatio =2.00; // reward ratio
extern int candlesback =20;
extern int rifcandle =1;
extern int shift =4;
extern int PadAmount =5; // buffer
extern int HourExp =24; // expiration time for Stop_Order
double pips;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
double ticksize=MarketInfo(Symbol(),MODE_TICKSIZE);
if (ticksize==0.00001||ticksize==0.001)
pips=ticksize*10;
else pips=ticksize;
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
int OpenOrdersThisPair(string pair)
{
int total=0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==pair)total++;
}
return(total);
}
//+------------------------------------------------------------------+
bool IsNewCandle()
{
static int BarsOnChart=0;
if(Bars==BarsOnChart)
return(false);
BarsOnChart=Bars;
return(true);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if(IsNewCandle())CheckForTrade();
//----
return(0);
}
//+------------------------------------------------------------------+
void CheckForTrade()
{
int PrevLow= iLowest(NULL,0,MODE_LOW,candlesback,shift);
int PrevHigh=iHighest(NULL,0,MODE_HIGH,candlesback,shift);
int BestLow= iLowest(NULL,0,MODE_LOW,candlesback,rifcandle);
int BestHigh=iHighest(NULL,0,MODE_HIGH,candlesback,rifcandle);
int MediumLow=iLowest(NULL,0,MODE_LOW,BestLow,rifcandle+1);
int MediumHigh=iHighest(NULL,0,MODE_HIGH,BestHigh,rifcandle+1);
double iPrevLow=Low[PrevLow];
double iPrevHigh=High[PrevHigh];
double iBestLow=Low[BestLow];
double iBestHigh=High[BestHigh];
double iMediumLow=Low[MediumLow];
double iMediumHigh=High[MediumHigh];
if(iPrevLow>iBestLow && iMediumLow>iBestLow && iMediumLow>iPrevLow)OrderEntry(0); //Buy
if(iPrevHigh<iBestHigh && iMediumHigh<iBestHigh && iMediumHigh<iPrevHigh)OrderEntry(1); //Sell
}
//+------------------------------------------------------------------+
void OrderEntry(int direction)
{
int PrevLow= iLowest(NULL,0,MODE_LOW,candlesback,shift);
int PrevHigh=iHighest(NULL,0,MODE_HIGH,candlesback,shift);
int BestLow= iLowest(NULL,0,MODE_LOW,candlesback,rifcandle);
int BestHigh=iHighest(NULL,0,MODE_HIGH,candlesback,rifcandle);
double BuyStopPrice= Low[PrevLow]+(PadAmount*pips);
double SellStopPrice= High[PrevHigh]-(PadAmount*pips);
double BuySL=Low[BestLow]-(PadAmount*pips);
double SellSL=High[BestHigh]+(PadAmount*pips);
double pips_to_bsl=BuyStopPrice-BuySL;
double pips_to_ssl=SellSL-SellStopPrice;
double BuyTP=Ask+pips_to_bsl*RewRatio;
double SellTP=Bid-pips_to_ssl*RewRatio;
double Equity=AccountEquity();
double RiskedAmount=Equity*MaxR;
double tickvalue=NormalizeDouble(MarketInfo(Symbol(),MODE_TICKVALUE),4);
double LotSize;
if(direction==0)
{
double bsl=BuySL;
double btp=BuyTP;
LotSize=NormalizeDouble((RiskedAmount/(pips_to_bsl/pips))/(tickvalue*10),2);
if(OpenOrdersThisPair(Symbol())==0) int buyticket=OrderSend(Symbol(),OP_BUYSTOP,LotSize,BuyStopPrice,3,bsl,btp,NULL,MAGICMA,TimeCurrent()+(HourExp*60*60),Green);
}
if(direction==1)
{
double ssl=SellSL;
double stp=SellTP;
LotSize=NormalizeDouble((RiskedAmount/(pips_to_ssl/pips))/(tickvalue*10),2);
if(OpenOrdersThisPair(Symbol())==0) int sellticket=OrderSend(Symbol(),OP_SELLSTOP,LotSize,SellStopPrice,3,ssl,stp,NULL,MAGICMA,TimeCurrent()+(HourExp*60*60),Red);
}
}

Nessun commento:
Posta un commento
condividi la tua opinione...