1 //+------------------------------------------------------------------+
\r
2 //| Close_on_Profit.mq4 |
\r
3 //| Copyright © 2010, Dennis Hamilton |
\r
4 //| ramble_32@yahoo.com |
\r
5 //+------------------------------------------------------------------+
\r
6 #property copyright "Copyright © 2010, Dennis Hamilton"
\r
7 #property link "ramble_32@yahoo.com"
\r
9 extern double p_target=10.0;
\r
10 extern double targ_base=0;
\r
11 extern bool recurring=true;
\r
12 extern bool use_magic=true;
\r
13 extern int magic=123;
\r
14 extern bool closeall=false;
\r
17 int magic2, t_cnt, oneshot;
\r
20 //+------------------------------------------------------------------+
\r
21 //| expert initialization function |
\r
22 //+------------------------------------------------------------------+
\r
29 GlobalVariableSet("inhibit",0);
\r
30 if(!GlobalVariableGet("targ_base") && targ_base==0) GlobalVariableSet("targ_base",AE);
\r
31 if(targ_base>0) GlobalVariableSet("targ_base",targ_base);
\r
35 //+------------------------------------------------------------------+
\r
36 //| expert start function |
\r
37 //+------------------------------------------------------------------+
\r
42 targ_base=GlobalVariableGet("targ_base");
\r
43 if(AE>=targ_base+p_target || closeall){
\r
44 get_time=TimeCurrent(); GlobalVariableSet("targ_base",AE); t_cnt++; }
\r
45 if(!recurring){ oneshot=t_cnt; GlobalVariableSet("inhibit",t_cnt); }
\r
46 if(!use_magic){ magic=0; magic2=0; }
\r
49 if(recurring || oneshot==1)
\r
51 for(int i=OrdersTotal()-1; i>=0; i--)
\r
53 if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
\r
55 if(use_magic) magic2=OrderMagicNumber();
\r
56 if(OrderOpenTime()<get_time && magic2==magic)
\r
58 if(OrderType()>1) OrderDelete(OrderTicket());
\r
59 if(OrderType()<2) OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,CLR_NONE);
\r
66 for(i=0; i<OrdersTotal(); i++)
\r
68 if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
\r
70 if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=magic) continue;
\r
71 if(OrderOpenTime()<get_time && magic2==magic) gt_cnt++;
\r
75 Comment("Equity = "+DoubleToStr(AE,2)+" | Target = "+DoubleToStr(targ_base+p_target,2)+" | Magic = "+magic+" | Close Time = "+get_time+" | Orders = "+gt_cnt);
\r
79 //+------------------------------------------------------------------+