Code
//+------------------------------------------------------------------+
//| LEFEUVRE CUSTOMIZED MTF |
//| EURUSD 1 MN SFK Corp. |
//+------------------------------------------------------------------+
#property copyright "LaDreamTeam"
//#property strict
//---- input parameters
extern int min_gapsizePERIOD_M1 = 6;
extern int min_gapsizePERIOD_M5 = 6;
extern int min_gapsizePERIOD_M15 = 6;
extern int min_gapsizePERIOD_M30 = 6;
extern int min_gapsizePERIOD_H1 = 6;
extern int min_gapsizePERIOD_H4 = 6;
//----
extern bool PERIOD_M1=true;
extern bool PERIOD_M5=true;
extern bool PERIOD_M15=true;
extern bool PERIOD_M30=true;
extern bool PERIOD_H1=true;
extern bool PERIOD_H4=true;
//----
extern string mm="MONEY MANAGEMENT";
double lot; //lotsize
extern double LotFactor = 49; //lotsize factor
extern string mn="MAGIC NUMBER";
extern int MagicNumber=20180821; //magic
//----
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
static datetime order_time = 0;
int ticket = 0;
if(OrdersTotal()==0)
order_time=0;
// Defining the variables to decide.
Print("order time", order_time);
// catching the gap on sell upper gap
if(PERIOD_M1==True && iOpen(Symbol(), PERIOD_M1, 0) > (iHigh(Symbol(), PERIOD_M1, 1) + (min_gapsizePERIOD_M1 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M1, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_SELL, NR(Lot_Volume()), Bid, 0, 0,
iHigh(Symbol(), PERIOD_M1, 1) + MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Red);
order_time = iTime(Symbol(), PERIOD_M1, 0);
Print("I am inside (sell) :-)", order_time);
//----
//----
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_M5==True && iOpen(Symbol(), PERIOD_M5, 0) > (iHigh(Symbol(), PERIOD_M5, 1) + (min_gapsizePERIOD_M5 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M5, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_SELL, NR(Lot_Volume()), Bid, 0, 0,
iHigh(Symbol(), PERIOD_M5, 1) + MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Red);
order_time = iTime(Symbol(), PERIOD_M5, 0);
Print("I am inside (sell) :-)", order_time);
//----
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_M15==True && iOpen(Symbol(), PERIOD_M15, 0) > (iHigh(Symbol(), PERIOD_M15, 1) + (min_gapsizePERIOD_M15 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M15, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_SELL, NR(Lot_Volume()), Bid, 0, 0,
iHigh(Symbol(), PERIOD_M15, 1) + MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Red);
order_time = iTime(Symbol(), PERIOD_M15, 0);
Print("I am inside (sell) :-)", order_time);
//----
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_M30==True && iOpen(Symbol(), PERIOD_M30, 0) > (iHigh(Symbol(), PERIOD_M30, 1) + (min_gapsizePERIOD_M30 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M30, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_SELL, NR(Lot_Volume()), Bid, 0, 0,
iHigh(Symbol(), PERIOD_M30, 1) + MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Red);
order_time = iTime(Symbol(), PERIOD_M30, 0);
Print("I am inside (sell) :-)", order_time);
//----
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_H1==True && iOpen(Symbol(), PERIOD_H1 ,0) > (iHigh(Symbol(), PERIOD_H1, 1) + (min_gapsizePERIOD_H1 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_H1, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_SELL, NR(Lot_Volume()), Bid, 0, 0,
iHigh(Symbol(), PERIOD_H1, 1) + MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Red);
order_time = iTime(Symbol(), PERIOD_H1, 0);
Print("I am inside (sell) :-)", order_time);
//----
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_H4==True && iOpen(Symbol(), PERIOD_H4, 0) > (iHigh(Symbol(), PERIOD_H4, 1) + (min_gapsizePERIOD_H4 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_H4, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_SELL, NR(Lot_Volume()), Bid, 0, 0,
iHigh(Symbol(), PERIOD_H4, 1) + MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Red);
order_time = iTime(Symbol(), PERIOD_H4, 0);
Print("I am inside (sell) :-)", order_time);
//----
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
//catching the gap on buy down gap
if(PERIOD_M1==True && iOpen(Symbol(), PERIOD_M1, 0) < (iLow(Symbol(), PERIOD_M1, 1) - (min_gapsizePERIOD_M1 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M1, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_BUY, NR(Lot_Volume()), Ask, 0, 0,
iLow(Symbol(), PERIOD_M1, 1) - MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Green);
order_time = iTime(Symbol(), PERIOD_M1, 0);
Print("I am inside (buy) :-)", order_time);
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_M5==True && iOpen(Symbol(), PERIOD_M5, 0) < (iLow(Symbol(), PERIOD_M5, 1) - (min_gapsizePERIOD_M5 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M5, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_BUY, NR(Lot_Volume()), Ask, 0, 0,
iLow(Symbol(), PERIOD_M5, 1) - MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Green);
order_time = iTime(Symbol(), PERIOD_M5, 0);
Print("I am inside (buy) :-)", order_time);
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_M15==True && iOpen(Symbol(), PERIOD_M15, 0) < (iLow(Symbol(), PERIOD_M15, 1) - (min_gapsizePERIOD_M15 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M15, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_BUY, NR(Lot_Volume()), Ask, 0, 0,
iLow(Symbol(), PERIOD_M15, 1) - MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Green);
order_time = iTime(Symbol(), PERIOD_M15, 0);
Print("I am inside (buy) :-)", order_time);
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_M30==True && iOpen(Symbol(), PERIOD_M30, 0) < (iLow(Symbol(), PERIOD_M30, 1) - (min_gapsizePERIOD_M30 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_M30, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_BUY, NR(Lot_Volume()), Ask, 0, 0,
iLow(Symbol(), PERIOD_M30, 1) - MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Green);
order_time = iTime(Symbol(), PERIOD_M30, 0);
Print("I am inside (buy) :-)", order_time);
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_H1==True && iOpen(Symbol(), PERIOD_H1, 0) < (iLow(Symbol(), PERIOD_H1, 1) - (min_gapsizePERIOD_H1 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_H1, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_BUY, NR(Lot_Volume()), Ask, 0, 0,
iLow(Symbol(), PERIOD_H1, 1) - MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Green);
order_time = iTime(Symbol(), PERIOD_H1, 0);
Print("I am inside (buy) :-)", order_time);
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
if(PERIOD_H4==True && iOpen(Symbol(), PERIOD_H4, 0) < (iLow(Symbol(), PERIOD_H4, 1) - (min_gapsizePERIOD_H4 + MarketInfo(Symbol(), MODE_SPREAD))*MarketInfo(Symbol(), MODE_POINT)) && iTime(Symbol(), PERIOD_H4, 0) != order_time)
{
ticket = OrderSend(Symbol(), OP_BUY, NR(Lot_Volume()), Ask, 0, 0,
iLow(Symbol(), PERIOD_H4, 1) - MarketInfo(Symbol(), MODE_SPREAD)*MarketInfo(Symbol(), MODE_POINT),
"", MagicNumber, 0, Green);
order_time = iTime(Symbol(), PERIOD_H4, 0);
Print("I am inside (buy) :-)", order_time);
if(ticket < 0)
{
Print("OrderSend failed with error #", GetLastError());
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//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);
}
//+------------------------------------------------------------------+