Chers amis
Il serait formidable que certains refassent un Backtest de meilleur qualite que le mien avec un meilleur modelage
et propose les parametres,obtenus, à la suite.
Pour le mettre dans une situation difficile j'ai mis un spread de 10 dans mon backtest qui ne presente malheureusement qu'une qualite de modelage de 25 %.
La strategie consiste en la mise en place simultanée d'un Buystop et d'un Sellstop en utilisant des moyennes sur la hauteur des bougies ,sur la moyenne de Moyenne mobille en position Mode Low et Mode High avec l'utilisation de differents filtres de protection ,associes (ADX RSI volume).
Si des corrections ou ameliorations sont proposées ,elles seront bienvenues.
Il serait formidable que certains refassent un Backtest de meilleur qualite que le mien avec un meilleur modelage
et propose les parametres,obtenus, à la suite.
Pour le mettre dans une situation difficile j'ai mis un spread de 10 dans mon backtest qui ne presente malheureusement qu'une qualite de modelage de 25 %.
La strategie consiste en la mise en place simultanée d'un Buystop et d'un Sellstop en utilisant des moyennes sur la hauteur des bougies ,sur la moyenne de Moyenne mobille en position Mode Low et Mode High avec l'utilisation de differents filtres de protection ,associes (ADX RSI volume).
Si des corrections ou ameliorations sont proposées ,elles seront bienvenues.
Code
//+------------------------------------------------------------------+
//| Scalper-GG-7.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
extern string mn="Scalper-GG-8";
double lot;
extern bool trail=true;
extern int TrailingStop=1;
extern int barnumber =3;
extern int MagicNumber=14072020;
extern double TakeProfit=31;
extern double StopLoss=34;
extern int volume1=1;
extern int volume0=0;
extern int adxperiod= 31;
extern int adxthreshold=23;
extern int rsiperiod=21;
extern int rsilower =48;
extern int rsiupper =80;
extern int Slippage=3;
extern int Indicatorperiod = 85;
input int MaxSpreadAllow = 10; // Enter Maximum allowed spread
extern double LotFactor =134; //lotsize factor
extern int ecartask=7;
extern int ecartbid=12;
extern int Start_Time = 0; // Time to allow trading to start ( hours of 24 hr clock ) 0 for both disables
extern int Finish_Time = 0; // Time to stop trading ( hours of 24 hr clock ) 0 for both disables
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
if(TimeHour(TimeCurrent())>=Start_Time && TimeHour(TimeCurrent())<=Finish_Time )return(0);
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
double booster = Volume[volume1]> Volume[volume0]
&&iADX(Symbol(),0,adxperiod,PRICE_CLOSE,MODE_MAIN,0)> adxthreshold
&&iRSI(Symbol(),0,rsiperiod,PRICE_CLOSE,0)>rsilower && iRSI(Symbol(),0,rsiperiod,PRICE_CLOSE,0)<rsiupper ;
//
if( TotalOrdersCount()==0 )
{
int result=0;
new_del () ;
//
//if (last_bar == Bars) return(0);
//last_bar = Bars;
//
static datetime tmeBar0;
bool newBar = false;
if ( tmeBar0 != Time[0] )
{
tmeBar0 = Time[0];
newBar = true;
}
// Get Ask and Bid for the currency
double ask = MarketInfo ( Symbol(), MODE_ASK );
double bid = MarketInfo ( Symbol(), MODE_BID );
double Spread = MarketInfo(Symbol(), MODE_SPREAD); // This will Obtain broker Spread for current pair
if(Spread > 0 && Spread <= MaxSpreadAllow) // This part compares broker spread with maximum allowed spread, and refuse trade if maxSpread is exceeded
if ( OrdersTotal () == 0 )
if(AccountFreeMargin()>(1000*(AccountEquity() * 0.01 /LotFactor)))
if(booster)
{
//+------------------------------------------------------------------+
// Here is your open buy rule
// Calculate a channel on candels, and check the price
double HighOfLastBars = iHigh ( Symbol (), PERIOD_M1 , iHighest ( Symbol (), PERIOD_M1 , MODE_HIGH, barnumber , 0 ));
double LowOfLastBars = iLow ( Symbol (), PERIOD_M1 , iLowest ( Symbol (), PERIOD_M1 , MODE_LOW, barnumber , 0 ));
double AverageBars=(HighOfLastBars +LowOfLastBars)/2 ;
double PartialLow=((LowOfLastBars+AverageBars)/2);
double PartialHigh = ((HighOfLastBars+AverageBars)/2);
// Calculate a channel on Moving Averages, and check the price
double iMaLow = iMA ( Symbol(), PERIOD_M1, Indicatorperiod, 0, MODE_LWMA, PRICE_LOW, 0 );
double iMaHigh = iMA ( Symbol(), PERIOD_M1, Indicatorperiod, 0, MODE_LWMA, PRICE_HIGH, 0 );
double iMaAverage = (iMaHigh + iMaLow)/2;
double PartialiMalow = (iMaLow + iMaAverage) / 2.0;
double PartialiMahigh =(iMaHigh + iMaAverage) / 2.0;
double UpperPart=(PartialiMahigh+PartialHigh)/2;
double LowerPart= ( PartialiMalow+ PartialLow)/2;
if (bid>= PartialiMahigh )
if (bid>= PartialHigh )
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
result=OrderSend(Symbol(),OP_BUYSTOP, NR(Lot_Volume()),Ask +ecartask*Point,5,PartialLow -StopLoss*Point,PartialHigh +TakeProfit*Point,"Scalper-GG-8",MagicNumber,0,clrLimeGreen);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
if( OrderSelect(result,SELECT_BY_TICKET))
bool modif1= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,clrLawnGreen);
}
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is your open Sell rule/
// Calculate a channel on candels, and check the price
double HighOfLastBars = iHigh ( Symbol (), PERIOD_M1 , iHighest ( Symbol (), PERIOD_M1 , MODE_HIGH, barnumber , 0 ));
double LowOfLastBars = iLow ( Symbol (), PERIOD_M1 , iLowest ( Symbol (), PERIOD_M1 , MODE_LOW, barnumber , 0 ));
double AverageBars=(HighOfLastBars +LowOfLastBars)/2 ;
double PartialLow=((LowOfLastBars+AverageBars)/2);
double PartialHigh = ((HighOfLastBars+AverageBars)/2);
// Calculate a channel on Moving Averages, and check the price
double iMaLow = iMA ( Symbol(), PERIOD_M1, Indicatorperiod, 0, MODE_LWMA, PRICE_LOW, 0 );
double iMaHigh = iMA ( Symbol(), PERIOD_M1, Indicatorperiod, 0, MODE_LWMA, PRICE_HIGH, 0 );
double iMaAverage = (iMaHigh + iMaLow)/2;
double PartialiMalow = (iMaLow + iMaAverage) / 2.0;
double PartialiMahigh =(iMaHigh + iMaAverage) / 2.0;
double UpperPart=(PartialiMahigh+PartialHigh)/2;
double LowerPart= ( PartialiMalow+ PartialLow)/2;
if (PartialiMalow <= bid)
if (PartialLow <= bid)
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
{
result=OrderSend(Symbol(),OP_SELLSTOP, NR(Lot_Volume()),Bid-ecartbid*Point,5,PartialHigh +StopLoss*Point,PartialLow -TakeProfit*Point,"Scalper-GG-8",MagicNumber,0,clrRed);
if(result>0)
{
TheStopLoss=0;
TheTakeProfit=0;
if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
if( OrderSelect(result,SELECT_BY_TICKET))
bool modif2= OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,clrMagenta);
}
return(0);
}
}
for(int cnt=0;cnt<OrdersTotal();cnt++)
{
if( OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
if(OrderType()<=OP_SELL &&
OrderSymbol()==Symbol() &&
OrderMagicNumber()==MagicNumber
)
{
if(OrderType()==OP_BUY)
{
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
bool modif3= OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
bool modif4= OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
return(0);
}
int TotalOrdersCount()
{
int result=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS ,MODE_TRADES))
if (OrderMagicNumber()==MagicNumber) result++;
}
return (result);
}
//+------------------------------------------------------------------+
// ( to close pending order)
//+------------------------------------------------------------------+
int new_del()
{
if(trail) trail();
int i,a;
int total = OrdersTotal();
string comentario,par;
for (i=total-1; i >=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if (OrderType()==OP_BUY || OrderType()==OP_SELL)
{
for (a=total-1; a >=0; a--)
{
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES))
if(OrderType()==OP_SELLSTOP)
{
bool modify1= OrderDelete(OrderTicket());
Print("Deleting SELL_STOP"," Ordertype:",OrderType());
return(1);
}
if(OrderType()==OP_BUYSTOP)
{
bool modify2= OrderDelete(OrderTicket());
Print("Deleting BUY_STOP"," Ordertype:",OrderType());
return(1);
}
}
}
}
return ( 0 );
}
//+------------------------------------------------------------------+
//| Trailing Stoploss après Breakeven |
//+------------------------------------------------------------------+
void trail()
{
for (int i = OrdersTotal()-1; i >= 0; i --)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
if(Bid - OrderOpenPrice() > TrailingStop *10* MarketInfo(OrderSymbol(),MODE_POINT))
{
if(((OrderStopLoss() < Bid - TrailingStop *10* MarketInfo(OrderSymbol(), MODE_POINT))&& ((Bid-OrderOpenPrice())>(Point*TrailingStop)))||
(OrderStopLoss()==0))
{
bool modify1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGreenYellow);
}
}
} else if(OrderType()==OP_SELL) {
if(OrderOpenPrice()-Ask>TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT))
{
if(((OrderStopLoss()>Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT))&& ((OrderOpenPrice()-Ask)>(Point*TrailingStop)))||
(OrderStopLoss()==0))
{
bool modify2=OrderModify(OrderTicket(),OrderOpenPrice(),
Ask+TrailingStop*10*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),clrGreenYellow);
}
}
}
}
}
}
//+------------------------------------------------------------------+
//Calculates Lot Size based on balance and factor
//+------------------------------------------------------------------+
double NR(double thelot)
{
double maxlots=MarketInfo(Symbol(),MODE_MAXLOT),
minilot=MarketInfo(Symbol(),MODE_MINLOT),
lstep=MarketInfo(Symbol(),MODE_LOTSTEP);
double lots=lstep*NormalizeDouble(thelot/lstep,0);
lots=MathMax(MathMin(maxlots,lots),minilot);
return (lots);
}
//+------------------------------------------------------------------+
double Lot_Volume()
{
lot=AccountEquity() * 0.01 /LotFactor ;
return(lot);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+