bleh
[mqlkit.git] / Godbot.mq4
blobcff9d36fcad0ca1d351b9018e814aadce1522ed5
1 /*=============================================================\r
2  Info:    Godbot EA   //  Timeframe M5 EURUSD\r
3  Name:    Godbot.mq4\r
4  Author:  Erich Pribitzer\r
5  Version: 1.1\r
6  Update:  2011-03-28 \r
7  Notes:   Mulit Order added\r
8  Version: 1.0\r
9  Update:  2010-09-12 \r
10  Notes:   ---\r
11   \r
12  Copyright (C) 2011 Erich Pribitzer \r
13  Email: seizu@gmx.at\r
14 =============================================================*/\r
16 #property copyright "Copyright © 2011, Erich Pribitzer"\r
17 #property link      "http://www.wartris.com"\r
20 #include <BasicH.mqh>\r
21 #include <OrderLibE.mqh>\r
22 #include <OrderLibH.mqh>\r
25 // Godbot EA timeframe M5\r
27 extern string  GB_SETTINGS      = "==== GODBOT EA V1.1/M5 SETTINGS ====";      //\r
28 extern int     GB_BANDS_PERIOD  = 23;\r
29 extern int     GB_BANDS_DEVIA   = 2;\r
30 extern int     GB_BANDS_SHIFT   = 0;\r
31 extern int     GB_MA            = 178;\r
32 extern int     GB_BANDS_TF      = PERIOD_M30;\r
34 extern int     GB_DEMA_PERIOD   = 56;\r
35 extern int     GB_DEMA_TF       = PERIOD_D1;\r
36 // extern bool    GB_TIMEFILTER    = true;\r
37 int            GB_oldBar        = 0;\r
38 double         GB_dema[];\r
42 int init()\r
43   {\r
45    BA_Init();\r
46    OL_Init(OL_ALLOW_ORDER,OL_RISK_PERC,OL_RISK_PIPS,OL_PROFIT_PIPS,OL_TRAILING_STOP,OL_LOT_SIZE,OL_INITIAL_LOT,OL_CUSTOM_TICKVALUE,OL_SLIP_PAGE,OL_STOPSBYMODIFY,OL_MAX_LOT,OL_MAX_ORDERS,OL_MAGIC,OL_ORDER_DUPCHECK,OL_OPPOSITE_CLOSE, OL_ORDER_COLOR, OL_MYSQL_LOG);   \r
47    ArrayResize(GB_dema,BA_INIT_BARS);   \r
48    return(0);\r
49   }\r
51 int deinit()\r
52   {\r
53    OL_Deinit();  \r
54    return(0);\r
55   }\r
57 int start()\r
58   {\r
59   \r
60    OL_ReadBuffer();\r
61      \r
62 //----\r
63    if(GB_oldBar!=Bars) //\r
64    {\r
65       GB_oldBar=Bars; //\r
67    \r
68       if(GB_oldBar<BA_INIT_BARS) return;\r
69    \r
70       double bandHi=iBands(NULL,GB_BANDS_TF,GB_BANDS_PERIOD, GB_BANDS_DEVIA,GB_BANDS_SHIFT,PRICE_CLOSE,1,1);\r
71       double bandLow=iBands(NULL,GB_BANDS_TF,GB_BANDS_PERIOD, GB_BANDS_DEVIA,GB_BANDS_SHIFT,PRICE_CLOSE,2,1);\r
72       GB_DEMA(Symbol(),GB_DEMA_TF,GB_DEMA_PERIOD,PRICE_CLOSE,GB_dema);\r
73    \r
74       double open=iOpen(NULL,GB_BANDS_TF,1);\r
75       double close=iClose(NULL,GB_BANDS_TF,1);\r
76       double ma1 = iMA(NULL,GB_BANDS_TF,GB_MA,0,MODE_EMA,PRICE_CLOSE,1);\r
77       double ma2 = iMA(NULL,GB_BANDS_TF,GB_MA,0,MODE_EMA,PRICE_CLOSE,2);\r
78       \r
79    \r
80       bool buyClose=(close < bandHi && open > bandHi);\r
81       bool sellClose=(close > bandLow && open < bandLow); \r
82       bool buy =(close > bandLow && open < bandLow && GB_dema[0] > GB_dema[1] && GB_dema[1] > GB_dema[2] && ma2  < ma1);\r
83       bool sell = (close < bandHi && open > bandHi && GB_dema[0] < GB_dema[1] && GB_dema[1] < GB_dema[2] && ma2  > ma1);\r
84    \r
85       OL_SyncBuffer();   \r
86    \r
87       // close sell\r
88       int binx=0;\r
89       if(sellClose )\r
90       { \r
92          while (true)\r
93          {   \r
94             binx=OL_enumOrderList(binx,OP_SELL);\r
95             if(binx<0) break;\r
96             OL_setOrderProperty(binx,OL_FLAG,OL_FL_CLOSE);\r
97             Print("CLOSE....SELL"); \r
98             binx++;\r
99          }\r
100       }\r
102       // close buy\r
103       binx=0;\r
104       if(buyClose)\r
105       {      \r
106     \r
107          while (true)\r
108          {   \r
109             binx=OL_enumOrderList(binx,OP_BUY);\r
110             if(binx<0) break;\r
111             OL_setOrderProperty(binx,OL_FLAG,OL_FL_CLOSE);  \r
112             Print("CLOSE....BUY");  \r
113             binx++;\r
114          }\r
115       }\r
119       if(buy)\r
120       {\r
121          Print("ORDER....BUY");\r
122          OL_addOrderProperty(OL_TYPE,OP_BUY);\r
123          //OL_addOrderProperty(OL_OPRICE,Ask);\r
124          OL_addOrderProperty(OL_RISKPERC,0);\r
125          OL_addOrderDescription(OP_BUY);\r
126          if(OL_registerOrder()==-1)\r
127             Print("OL_registerOrder failed!!!");                   \r
128       }\r
129    \r
131       if(sell)\r
132       {\r
133          Print("ORDER....SELL");\r
134          OL_addOrderProperty(OL_TYPE,OP_SELL);\r
135          //OL_addOrderProperty(OL_OPRICE,Bid);\r
136          OL_addOrderProperty(OL_RISKPERC,0);\r
137          OL_addOrderDescription(OP_SELL);\r
138          if(OL_registerOrder()==-1)\r
139             Print("OL_registerOrder failed!!!"); \r
140       }   \r
141    }\r
143    OL_processOrder();         // Close/Modify or Open order(s) \r
144    OL_WriteBuffer();  \r
146 //----\r
147    return(0);\r
148   }\r
150 void GB_DEMA(string symbol, int timeframe, int dema_period, int applied_price,double &buffer[])\r
152       static double lastEMA, lastEMA_of_EMA;\r
153       double weight=2.0/(1.0+dema_period);\r
154       double ret=0;\r
155       int limit=BA_INIT_BARS;\r
156       \r
157       \r
158       lastEMA          = iClose(symbol, timeframe, limit);\r
159       lastEMA_of_EMA   = iClose(symbol, timeframe, limit);\r
160       \r
161       limit--;\r
162       \r
163       for(int i=limit; i >= 0; i--)\r
164       {\r
165          lastEMA        =weight*iClose(symbol, timeframe,i)   + (1.0-weight)*lastEMA;\r
166          lastEMA_of_EMA  =weight*lastEMA   + (1.0-weight)*lastEMA_of_EMA;        \r
167          buffer[i]=(2.0*lastEMA - lastEMA_of_EMA);\r
168       } \r
169 }