EABreak Out

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

//+------------------------------------------------------------------+

//| EABreakOut.mq4 |
//| Copyright 2015, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict

enum _TOSHOW{
SHOW_NONE,
SHOW_COMMENT,
SHOW_PANNEL,
};
//--- input parameters
input bool BE_UseGMT = false;
input int BE_Magic=8888;
input double BE_Gap=20;//point digit=3 or 5
input double BE_Lots=0.1;
input _TOSHOW BE_UseShow=SHOW_COMMENT;
///////////////////////1/////////////////
input int BE_Period1=8;
input double BE_EarnPer1=0.15;
input int BE_Time1=9;
///////////////////////3/////////////////
input bool BE_UseTime2=true;
input int BE_Period2=5;
input double BE_EarnPer2=0.3;
input int BE_Time2=15;
///////////////////////3/////////////////
input bool BE_UseTime3=true;
input int BE_Period3=3;
input double BE_EarnPer3=0.6;
input int BE_Time3=20;
///////////////////////3/////////////////
input bool BE_ToCloseOpenOrder=false;
input int BE_TOClosePendingOrderTime=2;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
if(Period() != 60){
Alert("Only Use H1.");
return(INIT_FAILED);
}
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---

}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
bool ispendorder1=false,ispendorder2=false,ispendorder3=false;
void OnTick()
{
//---
if(BE_UseShow == SHOW_COMMENT) ShowTradeComment();
if(BE_UseShow == SHOW_PANNEL) ShowTradeResultInfo();

MqlDateTime mdt;
if(BE_UseGMT) TimeGMT(mdt);
else TimeLocal(mdt);

if(!ispendorder1){
ispendorder1 = toSetOrder(mdt,BE_Time1,BE_Period1,BE_EarnPer1);
}

if(BE_UseTime2 &&!ispendorder2){
ispendorder2 = toSetOrder(mdt,BE_Time2,BE_Period2,BE_EarnPer2);
}

if(BE_UseTime3 &&!ispendorder3){
ispendorder3 = toSetOrder(mdt,BE_Time3,BE_Period3,BE_EarnPer3);
}

if(mdt.hour==BE_TOClosePendingOrderTime && (ispendorder1 || ispendorder2 ||


ispendorder3)){
for(int ipos=OrdersTotal();ipos>=0;ipos--){
if(OrderSelect(ipos,SELECT_BY_POS) && OrderSymbol() == Symbol() &&
OrderMagicNumber() == BE_Magic){
if(OrderType() == OP_BUY){
if(BE_ToCloseOpenOrder)OrderClose(OrderTicket(),OrderLots(),Bid,5);
}else
if(OrderType() == OP_SELL){
if(BE_ToCloseOpenOrder)OrderClose(OrderTicket(),OrderLots(),Ask,5);
}else{
OrderDelete(OrderTicket());
}
}
}
ispendorder1 = false;
ispendorder2 = false;
ispendorder3 = false;
}

}
bool toSetOrder(MqlDateTime &mdt,int bytime,int byPeriod,double byEarn){
if(mdt.hour==bytime){
double beHi = High[iHighest(NULL,0,MODE_HIGH,byPeriod,1)];
double beLo = Low[iLowest(NULL,0,MODE_LOW,byPeriod,1)];

MakeOrder(OP_BUYSTOP,BE_Lots,(beHi+BE_Gap*Point),(beLo),(beHi*2-beLo+(beHi-
beLo)*byEarn),clrBlue);
MakeOrder(OP_SELLSTOP,BE_Lots,(beLo-BE_Gap*Point),(beHi),(beLo*2-beHi-(beHi-
beLo)*byEarn),clrRed);
return true;
}
return false;
}
//+------------------------------------------------------------------+
int MakeOrder(int cmd,double lots,double price,double sl,double tl,color clr){
int ticket;
ticket =
OrderSend(NULL,cmd,lots,fixprice(price),5,fixprice(sl),fixprice(tl),"",BE_Magic,0,c
lr);
return ticket;
}
double fixprice(double price){
return NormalizeDouble(price,Digits);
}
////////////////////////////////////////////////
// show info
///////////////////////////////////////////////
void ShowTradeResultInfo() {
double ld_0 = GetDailyResult(0);
string APName="BE_BE";
string name_8 = APName + "1";
if (ObjectFind(name_8) == -1) {
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
ObjectSet(name_8, OBJPROP_YDISTANCE, 15);
}
ObjectSetText(name_8, "Day1 pips: " + DoubleToStr(ld_0, 2), 14, "Courier New",
Gold);
ld_0 = GetDailyResult(1);
name_8 = APName + "2";
if (ObjectFind(name_8) == -1) {
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
ObjectSet(name_8, OBJPROP_YDISTANCE, 33);
}
ObjectSetText(name_8, "Day2 pips: " + DoubleToStr(ld_0, 2), 14, "Courier New",
Gold);
ld_0 = GetDailyResult(2);
name_8 = APName + "3";
if (ObjectFind(name_8) == -1) {
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
ObjectSet(name_8, OBJPROP_YDISTANCE, 51);
}
ObjectSetText(name_8, "Day3 pips: " + DoubleToStr(ld_0, 2), 14, "Courier New",
Gold);
name_8 = APName + "4";
if (ObjectFind(name_8) == -1) {
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
ObjectSet(name_8, OBJPROP_YDISTANCE, 76);
}
ObjectSetText(name_8, "Balance: " + DoubleToStr(AccountBalance(), 2), 14,
"Courier New", Gold);
name_8 = APName + "5";
if (ObjectFind(name_8) == -1) {
ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0);
ObjectSet(name_8, OBJPROP_CORNER, 1);
ObjectSet(name_8, OBJPROP_XDISTANCE, 10);
ObjectSet(name_8, OBJPROP_YDISTANCE, 90);
}
ObjectSetText(name_8, "Balance: " + DoubleToStr(AccountEquity(), 2), 14,
"Courier New", Gold);
}

double GetDailyResult(int shift) {


double ld_ret_4 = 0;
for (int pos_12 = 0; pos_12 < OrdersHistoryTotal(); pos_12++) {
if (!(OrderSelect(pos_12, SELECT_BY_POS, MODE_HISTORY))) break;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == BE_Magic)
if (OrderCloseTime() >= iTime(Symbol(), PERIOD_D1, shift) &&
OrderCloseTime() < iTime(Symbol(), PERIOD_D1, shift) + 86400)
ld_ret_4 = ld_ret_4 + OrderProfit() + OrderCommission() +
OrderSwap();
}
return (ld_ret_4);
}

string fixprice2(double price){


return DoubleToStr(price, 2);
}
void ShowTradeComment() {
double ld_0 = GetDailyResult(0);
double ld_1 = GetDailyResult(1);
double ld_2 = GetDailyResult(2);
Comment(" BE Vxx.xx Only Use H1",
"\n", " AccountBalance: ", fixprice2(AccountBalance()),
"\n", " AccountEquity: ", fixprice2(AccountEquity()),
"\n", " Lots: ", BE_Lots,
"\n", " day2: ", fixprice2(ld_2),
"\n", " day1: ", fixprice2(ld_1),
"\n", " day0: ", fixprice2(ld_0),
"\n");
}

You might also like