Code
//+------------------------------------------------------------------+
//| QPG SPEEDY GONZALES.mq4
//| EURUSD 1 MN QPG
//| https://www.mql5.com
//+------------------------------------------------------------------+
#property copyright "QPG"
#property link "https://www.mql5.com"
#property version "1.00"
//#property strict
extern string mn="MAGIC NUMBER";
extern int MagicNumber=07092018;
extern string mm="MONEY MANAGEMENT";
extern double StopLoss=50;
extern double TakeProfit=50;
extern int TrailingStop=50;
extern int Slippage=3;
extern string re="REGULATOR";
extern int adxperiod =14;
extern int adxthreshold =27;
extern int LotFactor =128;
extern int Limit = 1;
extern int rsiperiod = 2; //rsi period
extern int rsiupper = 80; //rsi upper bound, wont buy above this value
extern int rsilower = 20; //rsi lower bound, wont sell below this value
extern string ob="OPEN BUY";
extern double delta_open_buy=22;
extern int OB1a=8;
extern int OB0a=6;
extern int OB1b=10;
extern int OB0b=7;
extern string os="OPEN SELL";
extern double delta_open_sell=8;
extern int OS0a=2;
extern int OS1a=0;
extern int OS0b=6;
extern int OS1b=7;
extern string cb="CLOSE BUY";
extern double delta_close_buy=8;
extern int CB0a=2;
extern int CB1a=1;
extern int CB0b=6;
extern int CB1b=7;
extern string cs="CLOSE SELL";
extern double delta_close_sell=22;
extern int CS1a=8;
extern int CS0a=6;
extern int CS1b=10;
extern int CS0b=7;
double TP=0,SL=0,TR;
//+------------------------------------------------------------------+
//| Hidden StopLoss Calculations |
//+------------------------------------------------------------------+
void StpLoss()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
TP=TakeProfit*MyPoint;
SL=StopLoss*MyPoint;
double OrdP=0,OrdTP=0,OrdSL=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
if(OrderMagicNumber()==MagicNumber && Symbol()==OrderSymbol())
{
OrdP=OrderProfit()-MathAbs(OrderSwap())-MathAbs(OrderCommission());
OrdSL=(-1)*SL*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)/Point;
OrdTP=TP*OrderLots()*MarketInfo(OrderSymbol(),MODE_TICKVALUE)/Point;
if(OrdP>OrdTP || OrdP<OrdSL)
{
if(OrderType()==OP_BUY)
bool OrdClP=OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,clrGreen);
if(OrderType()==OP_SELL)
bool OrdClL=OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,clrYellow);
}
}
}
}
//+------------------------------------------------------------------+
// expert start function
//+------------------------------------------------------------------+
int start()
{
double MyPoint=Point;
if(Digits==3 || Digits==5) MyPoint=Point*10;
double TheStopLoss=0;
double TheTakeProfit=0;
if( TotalOrdersCount()==0 )
{
int result=0;
//+------------------------------------------------------------------+
// Here is your open buy rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is your open buy rule strategie beginning
//+------------------------------------------------------------------+
double Lots = MathRound(AccountBalance() * 0.01 )/LotFactor ;
//
double booster = Volume[1]> Volume[0]
&&(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
((Ask>Bid*Point)&&(Open[OB1a]>Open[OB0a])
&&((Open[OB1b]-Open[OB0b])>delta_open_buy*Point)
&&(booster) ) // Here is your open buy rule
//+------------------------------------------------------------------+
// Here is your open buy rule strategie end
//+------------------------------------------------------------------+
{
result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA MODEL",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);
}
//+------------------------------------------------------------------+
// Here is your open sell rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is your open sell rule strategie beginning
//+------------------------------------------------------------------+
if
((Bid>Ask*Point)&&(Close[OS0a]>Close[OS1a])
&&((Close[OS0b]-Close[OS1b])>delta_open_sell*Point)
&&(booster) ) // Here is your open sell rule
//+------------------------------------------------------------------+
// Here is your open sell rule strategie end
//+------------------------------------------------------------------+
{
result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA MODEL",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)
{
//+------------------------------------------------------------------+
// Here is your close buy rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is your close buy rule strategie beginning
//+------------------------------------------------------------------+
if((Bid>Ask*Point)&&(Close[CB0a]>Close[CB1a])
&&((Close[CB0b]-Close[CB1b])>delta_close_buy*Point)
&&(booster)) // Here is your close buy rule
//+------------------------------------------------------------------+
// Here is your close buy rule strategie end
//+------------------------------------------------------------------+
{
bool modif3=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
{
if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
{
bool modif4=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
return(0);
}
}
}
}
else
{
//+------------------------------------------------------------------+
// Here is your close sell rule
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
// Here is your close sell rule strategie beginning
//+------------------------------------------------------------------+
if((Ask>Bid*Point)&&(Open[CS1a]>Open[CS0a])
&&((Open[CS1b]-Open[CS0b])>delta_close_sell*Point)
&&(booster)) // Here is your close sell rule
//+------------------------------------------------------------------+
// Here is your close sell rule strategie end
//+------------------------------------------------------------------+
{
bool modif5=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
{
if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
{
bool modif6=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);
}