Navigation:Home > Content >

harmonicEA.mq4

Time: 2017-03-11 | Download file:harmonicEA.mq4

//+------------------------------------------------------------------+
//|                                                Order[иб]Line.mq4 |
//|                            Copyright © 2011, hmaryawan@gmail.com |
//|                                           http://athisa.blog.com |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, hmaryawan@gmail.com"
#property link      "http://athisa.blog.com"

extern double Lots = 0.1;
extern int StopLoss = 0;
extern int TakeProfit = 0;
extern bool UseMoneyManagement = true;
extern int TradeSizePercent = 2;
extern string ___Gartley___= "Parameter for Gartley Pattern";
extern bool AutoGartley = true;
extern bool PendingOrder = true;
extern int MaxOrder=1;
extern double TakeProfitAtRetracement = 0.618;

int FREE_MARGIN = 1;
int EQUITY = 2;
int BALANCE = 3;

string s_new_prefix = "#";
string s_order_prefix = "$";
string s_tp_prefix = "@";
string s_sl_prefix = "!";
bool hide_sl = true;
string s_symbol, s_cmt;
int i_cmd, i_slipage, i_magic;
double d_lot, d_price, d_sl, d_tp;
datetime dt_exp;
color cl_order=CornflowerBlue, cl_tp=DarkSeaGreen, cl_sl=DarkSalmon;
int l_style=4;

int i_spread = 0;
int i_stop_level=0;

string s_tf[]    = {"M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1", "MN"};
int    i_tf[]    = {1, 5, 15, 30, 60, 240, 1440, 10080, 43200};
string a_cmd[] = {"buy","sell","buylimit","selllimit","buystop","sellstop"};

// gartley
string s_last_sign, s_sign;

int init()  {
   s_symbol = Symbol();
   i_spread = MarketInfo(s_symbol, MODE_SPREAD);
   i_stop_level = MarketInfo(s_symbol, MODE_STOPLEVEL);
   i_slipage = 2;
   i_magic = GetMagic();
   //i_cur_tf = ArrayBsearch(i_tf, Period());
   
   RestoreLine();
   
   
   
   return(0);
}

int deleteObject(string name) {
   for(int k=ObjectsTotal()-1; k>=0; k--)     {
      string o_name=ObjectName(k);
      if (StringFind(o_name, name) != -1) {
         //Print(o_name +" "+StringFind(o_name, name));
         ObjectDelete(o_name);
      }
   }
   
   return(0);
}

int deinit()  {
   deleteObject(s_new_prefix);
   deleteObject(s_order_prefix);
   deleteObject(s_tp_prefix);
   deleteObject(s_sl_prefix);
   
   return(0);
}

int start()  {
   
   RemoveLineOrder();
   
   for(int k=ObjectsTotal()-1; k>=0; k--)     {
      string o_name=ObjectName(k);
      string s_prefix = StringSubstr(o_name,0,1);
      if (ObjectType(o_name)==OBJ_HLINE) {
         if (s_prefix==s_new_prefix) {
            Print("New order line found!");
            GetLineProp(o_name); 
            OpenOrder(o_name);
            continue;
         } else if (s_prefix==s_order_prefix) {
            ModifyOrderPrice(o_name); continue;
         } else if (s_prefix==s_tp_prefix) {
            ModifyOrderTP(o_name); continue;
         } else if (s_prefix==s_sl_prefix) {
            ModifyOrderSL(o_name); continue;
         }
      }
   }
   
   SyncingLine();
   
   if (AutoGartley) FindGartley();
   
   //ClearHistoryOrder();
   //RestoreLine();
   
   return(0);
}

int RemoveLineOrder() {
   for(int k=ObjectsTotal()-1; k>=0; k--)     {
      string o_name=ObjectName(k);
      string s_prefix = StringSubstr(o_name,0,1);
      if (ObjectType(o_name)==OBJ_HLINE) {
         if (s_prefix==s_order_prefix || s_prefix==s_tp_prefix || s_prefix==s_sl_prefix) {
            int i_ticket = StrToInteger(StringSubstr(o_name,1));
            if (!FindOrder(i_ticket)) ObjectDelete(o_name);
         }
      }
   }
}

bool FindOrder(int i_ticket) {
   for (int i=0; i=0; k--) {
      string sname=ObjectName(k);
      if (ObjectType(sname)==OBJ_TRIANGLE && StringFind(sname, "Triangle2")!=-1 && (StringFind(sname, "Bearish")!=-1 || StringFind(sname, "Bullish")!=-1)) {
         sbearbull = StringFind(sname, "Bearish");
         if (sbearbull==-1) spattern = StringSubstr(sname, StringFind(sname, "Bullish"));
         else               spattern = StringSubstr(sname, StringFind(sname, "Bearish"));
         
         s_sign = spattern +" @ "+ Symbol() +"-"+ sPeriod;
         _cmt   = spattern +" @ "+ Symbol() +"-"+ sPeriod;
         if (s_sign != s_last_sign) {
            s_last_sign=s_sign;
            //deleteObject("$"); // when signal changed, close previous order
            if (FindOrderByComment(_cmt)        

Recommend