Cet EA prend des positions quand deux unités de temps sont en phase [1MN et 30 MN ]
Code
//+------------------------------------------------------------------+
//| SVE_RSI_I_FISH_MULTIFRAME.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//MULTIFRAME ...EURUSD ...1MN ...SVE RSI I FISH
//+------------------------------------------------------------------+
//--- input parameters
extern int MagicNumber=06112020;
extern double StopLoss=80;
extern double TakeProfit=100;
extern int TrailingStop=40;
extern int Slippage=3;
extern double LotFactor =90; //lotsize
int shift0=0;
int shift1=1;
int volume1=1;
int volume0=0;
extern int LevelHigh=80;
extern int LevelLow=5;
extern int adxperiod= 52;
extern int adxthreshold=23;
extern int rsiperiodlow=2;
extern int rsiperiodhigh=2;
extern int rsiperiodclose=9;
extern double multiplicateur=12;
extern int timeframe = PERIOD_M1;
extern int timeframe1 = PERIOD_M30;
double lot;
double MarginFree; // Free margin in percentage
extern double MinMarginLevel = 100; // Lowest allowed Margin level for new positions to be opened.
double wma0L,wma1L,wma2L,wma3L,wma4L,wma5L,wma6L,wma7L,wma8L,wma9L;
double wma0H,wma1H,wma2H,wma3H,wma4H,wma5H,wma6H,wma7H,wma8H,wma9H;
double rainbow[],rsi[],srsi[],fish[];
double ema0[],ema1[];
double rainbowL,rainbowH,rainbowC;
double rainbowC1;
double rainbowCA;
double rainbowC1A;
double rainbowCB;
double rainbowC1B;
double wma0C ,wma1C,wma2C ,wma3C,wma4C ,wma5C ,wma6C ,wma7C ,wma8C ,wma9C;
double wma0C1 ,wma1C1,wma2C1 ,wma3C1,wma4C1 ,wma5C1 ,wma6C1 ,wma7C1 ,wma8C1 ,wma9C1;
double wma0CA ,wma1CA,wma2CA ,wma3CA,wma4CA ,wma5CA ,wma6CA ,wma7CA ,wma8CA ,wma9CA;
double wma0C1A ,wma1C1A,wma2C1A ,wma3C1A,wma4C1A ,wma5C1A ,wma6C1A ,wma7C1A ,wma8C1A ,wma9C1A;
double wma0CB ,wma1CB,wma2CB ,wma3CB,wma4CB ,wma5CB ,wma6CB ,wma7CB ,wma8CB ,wma9CB;
double wma0C1B ,wma1C1B,wma2C1B ,wma3C1B,wma4C1B ,wma5C1B ,wma6C1B ,wma7C1B ,wma8C1B ,wma9C1B;
double rsiL,rsiH;
double srsiL,srsiH,srsiC;
double rsiCA;
double fishCA;
double srsiCA;
double rsiC1;
double srsiC1;
double fishC1;
double srsiCB;
double rsiC1B;
double srsiC1B;
double fishC1B;
double fishL,fishH;
double levelup;
double leveldown;
double fishC;
double rsiCS,rsiCL,rsiLL,rsiHS,rsiHL,rsiLS;
double rsiC;
double imalow ;
double imahigh ;
double imadiff ;
double isbidgreaterthanima ;
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
//Calculate and check spread
double MaxSpreadInPoints = 30;
double Spread = Ask - Bid;
if(Spread>MaxSpreadInPoints*Point)
return(false);
//+------------------------------------------------------------------+
double am = 0.000000001; // Set variable to a very small number
double marginlevel;
// Get the Free Margin
MarginFree = AccountFreeMargin();
// Calculate Margin level
if ( AccountMargin() != 0 )
am = AccountMargin();
marginlevel = AccountEquity() / am * 100;
// Free Margin is less than the value of MinMarginLevel, so no trading is allowed
if ( marginlevel < MinMarginLevel )
{
Comment ( "Warning! Free Margin " + DoubleToStr ( marginlevel, 2 ) + " is lower than MinMarginLevel!" );
Alert ( "Warning! Free Margin " + DoubleToStr ( marginlevel, 2 ) + " is lower than MinMarginLevel!" );
return(0);
}
//+------------------------------------------------------------------+
if( TotalOrdersCount()==0 )
{
int result=0;
//+----------------------------------------
//+----------------------------------------
wma0C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,1);
wma1C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,2);
wma2C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,3);
wma3C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,4);
wma4C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,5);
wma5C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,6);
wma6C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,7);
wma7C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,8);
wma8C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,9);
wma9C1 = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,10);
rainbowC1=(5*wma0C1+4*wma1C1+3*wma2C1+2*wma3C1+wma4C1+wma5C1+wma6C1+wma7C1+wma8C1+wma9C1)/20;
rsiC1=multiplicateur*0.1 *((iRSI(Symbol(), timeframe,rsiperiodclose,PRICE_CLOSE,1))*rainbowC1)-50;
srsiC1=rsiC1+rsiC1-rainbowC1;
fishC1=(((MathExp(2*srsiC1)-1)/(MathExp(2*srsiC1)+1)+1)*50);
//+------------------------------
//+------------------------------
//+----------------------------------------
//+----------------------------------------
wma0C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,0);
wma1C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,1);
wma2C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,2);
wma3C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,3);
wma4C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,4);
wma5C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,5);
wma6C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,6);
wma7C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,7);
wma8C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,8);
wma9C = iMA(NULL, timeframe,2,0,MODE_LWMA,PRICE_CLOSE,9);
rainbowC=(5*wma0C+4*wma1C+3*wma2C+2*wma3C+wma4C+wma5C+wma6C+wma7C+wma8C+wma9C)/20;
rsiC=multiplicateur*0.1 *((iRSI(Symbol(), timeframe,rsiperiodclose,PRICE_CLOSE,0))*rainbowC)-50;
srsiC=rsiC+rsiC-rainbowC;
fishC=(((MathExp(2*srsiC)-1)/(MathExp(2*srsiC)+1)+1)*50);
//+------------------------------
//+------------------------------
//+----------------------------------------
//+----------------------------------------
wma0C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,1);
wma1C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,2);
wma2C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,3);
wma3C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,4);
wma4C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,5);
wma5C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,6);
wma6C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,7);
wma7C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,8);
wma8C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,9);
wma9C1B = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,10);
rainbowC1B=(5*wma0C1B+4*wma1C1B+3*wma2C1B+2*wma3C1B+wma4C1B+wma5C1B+wma6C1B+wma7C1B+wma8C1B+wma9C1B)/20;
rsiC1B=multiplicateur*0.1 *((iRSI(Symbol(), timeframe1,rsiperiodclose,PRICE_CLOSE,1))*rainbowC1B)-50;
srsiC1B=rsiC1B+rsiC1B-rainbowC1B;
fishC1B=(((MathExp(2*srsiC1B)-1)/(MathExp(2*srsiC1B)+1)+1)*50);
//+------------------------------
//+------------------------------
//+----------------------------------------
//+----------------------------------------
wma0CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,0);
wma1CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,1);
wma2CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,2);
wma3CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,3);
wma4CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,4);
wma5CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,5);
wma6CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,6);
wma7CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,7);
wma8CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,8);
wma9CA = iMA(NULL, timeframe1,2,0,MODE_LWMA,PRICE_CLOSE,9);
rainbowCA=(5*wma0CA+4*wma1CA+3*wma2CA+2*wma3CA+wma4CA+wma5CA+wma6CA+wma7CA+wma8CA+wma9CA)/20;
rsiCA=multiplicateur*0.1 *((iRSI(Symbol(), timeframe1,rsiperiodclose,PRICE_CLOSE,0))*rainbowCA)-50;
srsiC=rsiCA+rsiCA-rainbowCA;
fishCA=(((MathExp(2*srsiCA)-1)/(MathExp(2*srsiCA)+1)+1)*50);
//+------------------------------
//+------------------------------
//+------------------------------
//+------------------------------
if((((fishC1 <20 )&& (fishC >20))
&& (fishCA >20))
&&(Volume[volume1]> Volume[volume0])
&&(iADX(Symbol(),0,adxperiod,PRICE_CLOSE,MODE_MAIN,0)> adxthreshold))
{
if (!IsTradeContextBusy() && IsTradeAllowed())
result=OrderSend(Symbol(),OP_BUY,NR(Lot_Volume()),Ask,Slippage,0,0,"BOLLINGER_BANDS_EA",MagicNumber,0,Blue);
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,Green);
}
return(0);
}
if((((fishC1 > 80)&&(fishC<80))
&&(fishCA <80))
&&(Volume[volume1]> Volume[volume0])
&&(iADX(Symbol(),0,adxperiod,PRICE_CLOSE,MODE_MAIN,0)> adxthreshold) )
{
if (!IsTradeContextBusy() && IsTradeAllowed())
result=OrderSend(Symbol(),OP_SELL,NR(Lot_Volume()),Bid,Slippage,0,0,"BOLLINGER_BANDS_EA",MagicNumber,0,Red);
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,Green);
}
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);
}
//+------------------------------------------------------------------+
//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=AccountBalance() * 0.01 /LotFactor ;
return(lot);
}