Ingen beskrivning

BOS_CHOCH.mq5 53KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. //+------------------------------------------------------------------+
  2. //| MK_BOS_CHOCH.mq5 |
  3. //| Copyright 2023, MetaQuotes Ltd. |
  4. //| https://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2023, MetaQuotes Ltd."
  7. #property link "https://www.mql5.com"
  8. #property version "1.00"
  9. #define orderNum 200
  10. struct tradeOrder
  11. {
  12. int choch_index;
  13. int reversal_index;
  14. string Signal;
  15. datetime Time_OF_Candle;
  16. datetime Time_of_candle_For_trade;
  17. tradeOrder()
  18. {
  19. choch_index = -1;
  20. Signal = "";
  21. reversal_index = 0;
  22. Time_OF_Candle = 0.0;
  23. Time_of_candle_For_trade = 0.0;
  24. }
  25. };
  26. tradeOrder od_1[orderNum];
  27. sinput string str = "<><><><><><> Set Object Name <><><><><><>";
  28. input string object_name = "line";
  29. sinput string str1 = "<><><><><><> Set time of vertical line <><><><><><>";
  30. input datetime inpTime = 0;//First Line Draw time
  31. datetime choch_index_time ;
  32. int choch_index = 0;
  33. int reversal_candle_index = 0;
  34. int ind = 0;
  35. string trend = " ";
  36. bool bearish_found = false;
  37. bool bullish_found = false;
  38. int index_of_last_high = 0;
  39. int index_of_last_low = 0;
  40. double hi;
  41. double lo;
  42. int index_of_low = 0;
  43. datetime index_of_low_time;
  44. int index_of_high = 0;
  45. datetime index_of_high_time;
  46. int high_index=0;
  47. datetime high_index_time;
  48. int low_index =0;
  49. datetime low_index_time;
  50. double high,low,low1,high1,low2,high2;
  51. int Store_bos_last_index = 0;
  52. datetime store_last_bos_index_time;
  53. //int ind = 0;
  54. bool choch_at_index = false;
  55. int index = 0;
  56. string signal = "";
  57. datetime time_of_candle = 0.0;
  58. datetime time_to_place_trade = 0.0;
  59. //double close1 = 0.0;
  60. //+------------------------------------------------------------------+
  61. //| Expert initialization function |
  62. //+------------------------------------------------------------------+
  63. void Bos(int i)
  64. {
  65. int save_bullish_index = 0;
  66. int save_bearish_index = 0;
  67. if(trend == "uptrend")
  68. {
  69. high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
  70. double close = iClose(Symbol(),PERIOD_CURRENT,i);
  71. if(close > high)
  72. {
  73. high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false);
  74. for(int j=high_index-1; j > i; j--)
  75. {
  76. if(checkCandle(j) == "Bearish")
  77. {
  78. save_bullish_index = j;
  79. if(object_find("high") > 0)
  80. {
  81. ObjectDelete(0,"high");
  82. }
  83. high = high1;
  84. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  85. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  86. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  87. ObjectCreate(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),high);
  88. ObjectSetString(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos");
  89. store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  90. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  91. low = iLow(Symbol(),PERIOD_CURRENT,j);
  92. bearish_found = true;
  93. index_of_low_time = iTime(Symbol(),PERIOD_CURRENT,j);
  94. break;
  95. }
  96. }
  97. if(bearish_found == true)
  98. {
  99. for(int k=save_bullish_index; k > i ; k--)
  100. {
  101. low1 = iLow(Symbol(),PERIOD_CURRENT,k);
  102. if(low1 < low)
  103. {
  104. low = low1;
  105. index_of_low_time = iTime(Symbol(),PERIOD_CURRENT,k);
  106. bearish_found = false;
  107. }
  108. }
  109. if(object_find("low") > 0)
  110. {
  111. if(ObjectDelete(0,"low"))
  112. {
  113. //Print("object deleted :");
  114. }
  115. }
  116. index_of_low = iBarShift(Symbol(), PERIOD_CURRENT, index_of_low_time, false);
  117. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_low),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  118. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  119. ObjectSetInteger(0,"low",OBJPROP_RAY_LEFT,false);
  120. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  121. }
  122. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  123. }
  124. }
  125. if(trend == "downtrend")
  126. {
  127. low1 = iLow(Symbol(),PERIOD_CURRENT,i);
  128. double close1 = iClose(Symbol(),PERIOD_CURRENT,i);
  129. if(close1 < low)
  130. {
  131. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  132. for(int j=low_index - 1; j > i; j--)
  133. {
  134. if(checkCandle(j) == "Bullish")
  135. {
  136. save_bullish_index = j;
  137. if(object_find("low") > 0)
  138. {
  139. ObjectDelete(0,"low");
  140. }
  141. low = low1;
  142. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  143. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  144. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  145. ObjectCreate(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),low);
  146. ObjectSetString(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos");
  147. store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  148. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  149. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  150. high = iHigh(Symbol(),PERIOD_CURRENT,j);
  151. bullish_found = true;
  152. index_of_high_time = iTime(Symbol(),PERIOD_CURRENT,j);
  153. break;
  154. }
  155. }
  156. if(bullish_found == true)
  157. {
  158. for(int k=save_bullish_index; k > i ; k--)
  159. {
  160. high1 = iHigh(Symbol(),PERIOD_CURRENT,k);
  161. if(high1 > high)
  162. {
  163. high = high1;
  164. index_of_high_time = iTime(Symbol(),PERIOD_CURRENT,k);
  165. bullish_found = false;
  166. }
  167. }
  168. if(object_find("high") > 0)
  169. {
  170. ObjectDelete(0,"high");
  171. }
  172. index_of_high = iBarShift(Symbol(), PERIOD_CURRENT, index_of_high_time, false);
  173. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_high),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  174. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  175. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  176. bullish_found = false;
  177. }
  178. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  179. }
  180. }
  181. }
  182. //+------------------------------------------------------------------+
  183. //| |
  184. //+------------------------------------------------------------------+
  185. void Entry_Action_1_down(int Store_bos_last_index, int i,int diff)
  186. {
  187. // i is the index of the choch
  188. for(int j=Store_bos_last_index+1; j < iBars(Symbol(),PERIOD_CURRENT); j++)
  189. {
  190. diff++;
  191. if(checkCandle(j) == "Bullish")
  192. {
  193. //Print("bullish found at index ",j);
  194. ind = j; // reversal candle index
  195. bullish_found = true;
  196. break;
  197. }
  198. }
  199. Print("condition satisfied in downtrend buy trade : ",check_values_less_than_choch_high(diff,i));
  200. // Print("choch candle open is ",iOpen(Symbol(),PERIOD_CURRENT,i));
  201. // Print("reversal candle open is ",iOpen(Symbol(),PERIOD_CURRENT,ind));
  202. if(check_values_less_than_choch_high(diff,i) == true)
  203. {
  204. if(iOpen(Symbol(),PERIOD_CURRENT,ind) > iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) < iClose(Symbol(),PERIOD_CURRENT,i))
  205. {
  206. signal = "buy";
  207. time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  208. Print("Place buy order -----------------------------------------------------------------------: ");
  209. }
  210. }
  211. //Print(diff);
  212. if(bullish_found == true)
  213. {
  214. ObjectCreate(0,"line14"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iHigh(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,ind));
  215. ObjectCreate(0,"line15"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iLow(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,ind));
  216. ObjectSetInteger(0,"line14"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue);
  217. ObjectSetInteger(0,"line15"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue);
  218. ObjectCreate(0,"line16"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iClose(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iClose(Symbol(),PERIOD_CURRENT,ind));
  219. ObjectCreate(0,"line17"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iOpen(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iOpen(Symbol(),PERIOD_CURRENT,ind));
  220. ObjectSetInteger(0,"line16"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT);
  221. ObjectSetInteger(0,"line17"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT);
  222. diff = 0;
  223. bullish_found = false;
  224. }
  225. }
  226. //+------------------------------------------------------------------+
  227. //| |
  228. //+------------------------------------------------------------------+
  229. void Entry_Action_1_up(int Store_bos_last_index, int i,int diff)
  230. {
  231. for(int j=Store_bos_last_index+1; j < iBars(Symbol(),PERIOD_CURRENT); j++)
  232. {
  233. diff++;
  234. if(checkCandle(j) == "Bearish")
  235. {
  236. ind = j; // reversal candle index
  237. bearish_found = true;
  238. break;
  239. }
  240. }
  241. //Print("diff is ", diff);
  242. Print("condition satisfied in uptrend sell trade : ",check_values_less_than_choch_low(diff,i));
  243. // Print("choch candle open is ",iOpen(Symbol(),PERIOD_CURRENT,i));
  244. // Print("reversal candle open is ",iOpen(Symbol(),PERIOD_CURRENT,ind));
  245. if(check_values_less_than_choch_low(diff,i) == true)
  246. {
  247. if(iOpen(Symbol(),PERIOD_CURRENT,ind) < iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) > iClose(Symbol(),PERIOD_CURRENT,i))
  248. {
  249. signal = "sell";
  250. time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  251. Print("Place sell order -----------------------------------------------------------------------: ");
  252. }
  253. }
  254. if(bearish_found == true)
  255. {
  256. ObjectCreate(0,"line10"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iHigh(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,ind));
  257. ObjectCreate(0,"line11"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iLow(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,ind));
  258. ObjectSetInteger(0,"line10"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue);
  259. ObjectSetInteger(0,"line11"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue);
  260. ObjectCreate(0,"line12"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iClose(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iClose(Symbol(),PERIOD_CURRENT,ind));
  261. ObjectCreate(0,"line13"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,ind),iOpen(Symbol(),PERIOD_CURRENT,ind),iTime(Symbol(),PERIOD_CURRENT,i),iOpen(Symbol(),PERIOD_CURRENT,ind));
  262. ObjectSetInteger(0,"line12"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT);
  263. ObjectSetInteger(0,"line13"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT);
  264. bearish_found = false;
  265. }
  266. }
  267. //+------------------------------------------------------------------+
  268. //| |
  269. //+------------------------------------------------------------------+
  270. bool check_values_less_than_choch_high(int diff,int i) // downtrend
  271. {
  272. bool found = false;
  273. int value = (diff + i) - 1;
  274. for(int k=value; k>i; k--)
  275. {
  276. //Print("high values ",iHigh(Symbol(),PERIOD_CURRENT,k));
  277. //Print("close values ",iClose(Symbol(),PERIOD_CURRENT,i));
  278. if(iHigh(Symbol(),PERIOD_CURRENT,k) > iClose(Symbol(),PERIOD_CURRENT,i))
  279. {
  280. found = true;
  281. }
  282. }
  283. if(found == true)
  284. {
  285. return false;
  286. }
  287. return true;
  288. }
  289. //+------------------------------------------------------------------+
  290. //| |
  291. //+------------------------------------------------------------------+
  292. bool check_values_less_than_choch_low(int diff,int i) // uptrend
  293. {
  294. bool found = false;
  295. int value = (diff + i) - 1; // from which it start to check value is less in index
  296. //Print("value to be start is ",value);
  297. for(int k=value; k>i; k--)
  298. {
  299. if(iLow(Symbol(),PERIOD_CURRENT,k) < iClose(Symbol(),PERIOD_CURRENT,i))
  300. {
  301. found = true;
  302. }
  303. }
  304. if(found == true)
  305. {
  306. return false;
  307. }
  308. return true;
  309. }
  310. //+------------------------------------------------------------------+
  311. //| |
  312. //+------------------------------------------------------------------+
  313. void choch(int i)
  314. {
  315. if(trend == "uptrend")
  316. {
  317. double close = iClose(Symbol(),PERIOD_CURRENT,i);
  318. if(close < low)
  319. {
  320. choch_at_index = true;
  321. ObjectCreate(0,"line3"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
  322. ObjectSetString(0,"line3"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"choch");
  323. ObjectCreate(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_ARROW_DOWN,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i)+100*Point());
  324. ObjectSetInteger(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJPROP_COLOR,clrRed);
  325. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  326. // Print("last bos index is ",Store_bos_last_index);
  327. int diff1 = Store_bos_last_index - (i);
  328. // Print("diff between bos and last choch is ",diff1);
  329. Entry_Action_1_up(Store_bos_last_index,i,diff1);
  330. low = iLow(Symbol(),PERIOD_CURRENT,i);
  331. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  332. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  333. low_index = i;
  334. if(object_find("low") > 0)
  335. {
  336. ObjectDelete(0,"low");
  337. }
  338. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  339. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  340. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  341. //Entry_Action_1_up(Store_bos_last_index,i,di);
  342. // Print("low update due to choch : ", low);
  343. trend = "downtrend";
  344. // Print("choch at uptrend index --- ", iTime(Symbol(),PERIOD_CURRENT,i));
  345. choch_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  346. }
  347. }
  348. if(trend == "downtrend")
  349. {
  350. double close = iClose(Symbol(),PERIOD_CURRENT,i);
  351. if(close > high)
  352. {
  353. choch_at_index = true;
  354. ObjectCreate(0,"line4"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
  355. ObjectSetString(0,"line4"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"choch");
  356. ObjectCreate(0,"line7"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_ARROW_UP,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i)-100*Point());
  357. ObjectSetInteger(0,"line7"+iTime(Symbol(),PERIOD_CURRENT,i),OBJPROP_COLOR,clrGreen);
  358. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  359. // Print("last bos index is ",Store_bos_last_index);
  360. int diff = Store_bos_last_index - (i);
  361. Entry_Action_1_down(Store_bos_last_index,i,diff);
  362. high = iHigh(Symbol(),PERIOD_CURRENT,i);
  363. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  364. high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false);
  365. high_index = i;
  366. if(object_find("high") > 0)
  367. {
  368. ObjectDelete(0,"high");
  369. }
  370. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  371. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  372. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  373. trend = "uptrend";
  374. // Print("high is update due to choch : ", high);
  375. // Print("choch at downtrend index ---- ", iTime(Symbol(),PERIOD_CURRENT,i));
  376. choch_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  377. }
  378. }
  379. }
  380. //+------------------------------------------------------------------+
  381. //| |
  382. //+------------------------------------------------------------------+
  383. void bos2(int i)
  384. {
  385. bool cnd;
  386. bool candle_bullish = false;
  387. bool candle_bearish = false;
  388. double find_high = 0.0;
  389. datetime find_high_time = 0.0;
  390. int save_bullish_index = 0;
  391. int save_bearish_index = 0;
  392. double find_low = 0.0;
  393. datetime find_low_time = 0.0;
  394. if(trend == "downtrend")
  395. {
  396. choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false);
  397. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  398. if(i+1 == choch_index || i+1 == Store_bos_last_index || i == choch_index || i == Store_bos_last_index)
  399. {
  400. cnd = false;
  401. }
  402. else
  403. {
  404. cnd = true;
  405. }
  406. if(choch_index_time > store_last_bos_index_time)
  407. {
  408. for(int m=choch_index; m>i; m--)
  409. {
  410. if(checkCandle(m) == "Bullish")
  411. {
  412. save_bullish_index = m;
  413. candle_bullish = true;
  414. break;
  415. }
  416. }
  417. find_high = iHigh(Symbol(),PERIOD_CURRENT,save_bullish_index);
  418. for(int m=save_bullish_index; m>i; m--)
  419. {
  420. double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,m);
  421. find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
  422. if(find_high < find_high1)
  423. {
  424. find_high = find_high1;
  425. find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
  426. }
  427. }
  428. for(int j=choch_index; j>=i; j--)
  429. {
  430. if(iClose(Symbol(),PERIOD_CURRENT,j) < iClose(Symbol(),PERIOD_CURRENT,i) || iLow(Symbol(),PERIOD_CURRENT,j) < iLow(Symbol(),PERIOD_CURRENT,i))
  431. {
  432. cnd = false;
  433. }
  434. }
  435. }
  436. if(choch_index_time < store_last_bos_index_time)
  437. {
  438. for(int m=Store_bos_last_index; m>i; m--)
  439. {
  440. if(checkCandle(m) == "Bullish")
  441. {
  442. save_bullish_index = m;
  443. candle_bullish = true;
  444. break;
  445. }
  446. }
  447. find_high = iHigh(Symbol(),PERIOD_CURRENT,save_bullish_index);
  448. for(int m=save_bullish_index; m>i; m--)
  449. {
  450. double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,m);
  451. find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
  452. if(find_high < find_high1)
  453. {
  454. find_high = find_high1;
  455. find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
  456. }
  457. }
  458. for(int j=Store_bos_last_index; j>=i; j--)
  459. {
  460. if(iClose(Symbol(),PERIOD_CURRENT,j) < iClose(Symbol(),PERIOD_CURRENT,i) || iLow(Symbol(),PERIOD_CURRENT,j) < iLow(Symbol(),PERIOD_CURRENT,i))
  461. {
  462. cnd = false;
  463. }
  464. }
  465. }
  466. if(cnd == true && candle_bullish == true)
  467. {
  468. // Print("high is --------------",find_high);
  469. // Print("high time is --------------",find_high_time);
  470. if(object_find("high") > 0)
  471. {
  472. ObjectDelete(0,"high");
  473. }
  474. high = find_high;
  475. index_of_high = iBarShift(Symbol(), PERIOD_CURRENT, find_high_time, false);
  476. Print("time is ----------------------",find_high_time);
  477. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_high),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  478. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  479. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  480. if(object_find("low") > 0)
  481. {
  482. ObjectDelete(0,"low");
  483. }
  484. low = iLow(Symbol(),PERIOD_CURRENT,i);
  485. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  486. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  487. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  488. ObjectCreate(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),low);
  489. ObjectSetString(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos");
  490. store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  491. // Print(store_last_bos_index_time);
  492. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  493. // Print("last bos index is ",Store_bos_last_index);
  494. // Print("low is ", low);
  495. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  496. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  497. // Print("low index ",low_index);
  498. cnd = false;
  499. candle_bullish = false;
  500. }
  501. }
  502. //-------
  503. if(trend == "uptrend")
  504. {
  505. choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false);
  506. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  507. if(i+1 == choch_index || i+1 == Store_bos_last_index || i == choch_index || i == Store_bos_last_index)
  508. {
  509. cnd = false;
  510. }
  511. else
  512. {
  513. cnd = true;
  514. }
  515. if(choch_index_time < store_last_bos_index_time)
  516. {
  517. for(int m=Store_bos_last_index; m>i; m--)
  518. {
  519. if(checkCandle(m) == "Bearish")
  520. {
  521. // Print("found bearish at index ",iTime(Symbol(),PERIOD_CURRENT,m));
  522. candle_bearish = true;
  523. save_bearish_index = m;
  524. break;
  525. }
  526. }
  527. find_low = iLow(Symbol(),PERIOD_CURRENT,save_bearish_index);
  528. for(int m=save_bearish_index; m>i; m--)
  529. {
  530. double find_low1 = iLow(Symbol(),PERIOD_CURRENT,m);
  531. find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
  532. if(find_low > find_low1)
  533. {
  534. find_low = find_low1;
  535. find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
  536. }
  537. }
  538. for(int j=Store_bos_last_index; j>=i; j--)
  539. {
  540. if(iClose(Symbol(),PERIOD_CURRENT,j) > iClose(Symbol(),PERIOD_CURRENT,i) || iHigh(Symbol(),PERIOD_CURRENT,j) > iHigh(Symbol(),PERIOD_CURRENT,i))
  541. {
  542. cnd = false;
  543. }
  544. }
  545. }
  546. if(choch_index_time > store_last_bos_index_time)
  547. {
  548. for(int m=choch_index; m>i; m--)
  549. {
  550. if(checkCandle(m) == "Bearish")
  551. {
  552. // Print("found bearish at index ",iTime(Symbol(),PERIOD_CURRENT,m));
  553. candle_bearish = true;
  554. save_bearish_index = m;
  555. break;
  556. }
  557. }
  558. find_low = iLow(Symbol(),PERIOD_CURRENT,save_bearish_index);
  559. for(int m=save_bearish_index; m>i; m--)
  560. {
  561. double find_low1 = iLow(Symbol(),PERIOD_CURRENT,m);
  562. find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
  563. if(find_low > find_low1)
  564. {
  565. find_low = find_low1;
  566. find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
  567. }
  568. }
  569. for(int j=choch_index; j>=i; j--)
  570. {
  571. if(iClose(Symbol(),PERIOD_CURRENT,j) > iClose(Symbol(),PERIOD_CURRENT,i) || iHigh(Symbol(),PERIOD_CURRENT,j) > iHigh(Symbol(),PERIOD_CURRENT,i))
  572. {
  573. cnd = false;
  574. }
  575. }
  576. }
  577. if(cnd == true && candle_bearish == true)
  578. {
  579. // Print("low is --------------",find_low);
  580. // Print("low time is --------------",find_low_time);
  581. if(object_find("low") > 0)
  582. {
  583. ObjectDelete(0,"low");
  584. }
  585. low = find_low;
  586. index_of_low = iBarShift(Symbol(), PERIOD_CURRENT, find_low_time, false);
  587. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_low),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  588. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  589. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  590. if(object_find("high") > 0)
  591. {
  592. ObjectDelete(0,"high");
  593. }
  594. high = iHigh(Symbol(),PERIOD_CURRENT,i);
  595. // Print(" high is updated : ",high);
  596. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  597. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  598. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  599. ObjectCreate(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),high);
  600. ObjectSetString(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos");
  601. store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  602. // Print(store_last_bos_index_time);
  603. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  604. // Print("last bos index is ",Store_bos_last_index);
  605. // Print("high is ", high);
  606. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  607. high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false);
  608. // Print("low index ",high_index);
  609. cnd = false;
  610. candle_bearish = false;
  611. }
  612. }
  613. }
  614. //+------------------------------------------------------------------+
  615. //| |
  616. //+------------------------------------------------------------------+
  617. bool third_condition_met = false;
  618. void third_Condition(int i)
  619. {
  620. if(trend == "uptrend")
  621. {
  622. low2 = iLow(Symbol(),PERIOD_CURRENT,i);
  623. high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
  624. if(low2 < low)
  625. {
  626. third_condition_met = true;
  627. // ObjectCreate(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
  628. // ObjectSetString(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  629. low = low2;
  630. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  631. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  632. low_index = i; // addtion to be minus
  633. if(object_find("low") > 0)
  634. {
  635. ObjectDelete(0,"low");
  636. }
  637. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  638. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  639. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  640. // Print("low update due to third condition",low," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
  641. }
  642. if(high2 > high)
  643. {
  644. //third_condition_met = true;
  645. // ObjectCreate(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
  646. // ObjectSetString(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  647. high = high2;
  648. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  649. high_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  650. high_index = i; // addtion to be minus
  651. if(object_find("high") > 0)
  652. {
  653. ObjectDelete(0,"high");
  654. }
  655. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  656. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  657. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  658. // Print("high update due to third condition",high," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
  659. }
  660. }
  661. if(trend == "downtrend")
  662. {
  663. high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
  664. low2 = iLow(Symbol(),PERIOD_CURRENT,i);
  665. if(high2 > high)
  666. {
  667. //third_condition_met = true;
  668. // ObjectCreate(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
  669. // ObjectSetString(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  670. high = high2;
  671. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  672. high_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  673. high_index = i; // addtion to be minus
  674. if(object_find("high") > 0)
  675. {
  676. ObjectDelete(0,"high");
  677. }
  678. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  679. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  680. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  681. // Print("high update due to third condition",high);
  682. }
  683. if(low2 < low)
  684. {
  685. third_condition_met = true;
  686. // ObjectCreate(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
  687. // ObjectSetString(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  688. low = low2;
  689. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  690. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  691. low_index = i; // addtion to be minus
  692. if(object_find("low") > 0)
  693. {
  694. ObjectDelete(0,"low");
  695. }
  696. // Print("low value is ", low);
  697. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  698. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  699. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  700. // Print("low update due to third condition",low);
  701. }
  702. }
  703. }
  704. //+------------------------------------------------------------------+
  705. //| |
  706. //+------------------------------------------------------------------+
  707. void store_value_in_structure(int i,int ind,string signal,datetime time_of_candle,datetime time_to_place_trade)
  708. {
  709. for(int l=0; l<200; l++)
  710. {
  711. if(od_1[l].choch_index == -1)
  712. {
  713. od_1[l].choch_index = i;
  714. od_1[l].reversal_index = ind;
  715. od_1[l].Signal = signal;
  716. od_1[l].Time_OF_Candle = time_of_candle;
  717. Print("saved time in the structure ",time_of_candle);
  718. od_1[l].Time_of_candle_For_trade = time_to_place_trade;
  719. Print("saved time in the structure ",time_to_place_trade);
  720. break;
  721. }
  722. }
  723. }
  724. //+------------------------------------------------------------------+
  725. //| |
  726. //+------------------------------------------------------------------+
  727. void foo(int value)
  728. {
  729. for(int i=value; i > 0; i--)
  730. {
  731. Bos(i);
  732. bos2(i);
  733. choch(i);
  734. third_Condition(i);
  735. if(signal == "buy" || signal == "sell")
  736. {
  737. MqlDateTime edate;
  738. time_to_place_trade = 0.0;
  739. //print("time of the candle ", time_of_candle);
  740. int current_time_frame = Period();
  741. string current_time_frame_string;
  742. switch(current_time_frame)
  743. {
  744. case PERIOD_M1:
  745. current_time_frame_string = "1 minute";
  746. break;
  747. case PERIOD_M5:
  748. current_time_frame_string = "5 minutes";
  749. break;
  750. case PERIOD_M15:
  751. current_time_frame_string = "15 minutes";
  752. break;
  753. case PERIOD_M30:
  754. current_time_frame_string = "30 minutes";
  755. break;
  756. case PERIOD_H1:
  757. current_time_frame_string = "1 hour";
  758. if(TimeToStruct(time_of_candle,edate))
  759. {
  760. edate.hour = edate.hour + 2;
  761. edate.min = 0;
  762. edate.sec = 0;
  763. }
  764. // print("hour of the candle is ",structtotime(edate));
  765. time_to_place_trade = StructToTime(edate);
  766. store_value_in_structure(i,ind,signal,time_of_candle,time_to_place_trade);
  767. for(int m=0; m < orderNum; m++)
  768. {
  769. if(od_1[m].choch_index != -1)
  770. {
  771. //Print(" time to match the condition : ",TimeCurrent());
  772. if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  773. {
  774. //Print("time to match the condition : ",TimeCurrent());
  775. if(iHigh(Symbol(),PERIOD_CURRENT,od_1[m].reversal_index) > iLow(Symbol(),PERIOD_CURRENT,0) && iClose(Symbol(),PERIOD_CURRENT,od_1[m].choch_index) < iClose(Symbol(),PERIOD_CURRENT,0))
  776. {
  777. ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0));
  778. //Print("trade placed buy at index ",0);
  779. od_1[m].choch_index = -1;
  780. }
  781. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  782. }
  783. if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  784. {
  785. if(iHigh(Symbol(),PERIOD_CURRENT,od_1[m].reversal_index) < iLow(Symbol(),PERIOD_CURRENT,0) && iClose(Symbol(),PERIOD_CURRENT,od_1[m].choch_index) > iClose(Symbol(),PERIOD_CURRENT,0))
  786. {
  787. ObjectCreate(0,"sell trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iLow(Symbol(),PERIOD_CURRENT,0));
  788. //Print("trade placed sell at index ",0);
  789. od_1[m].choch_index = -1;
  790. }
  791. //Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  792. // Print(TimeCurrent());
  793. //
  794. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  795. od_1[m].choch_index = -1;
  796. }
  797. }
  798. }
  799. // for(int m=0; m < orderNum; m++)
  800. // {
  801. // if(od_1[m].choch_index != -1)
  802. // {
  803. // Print(" time to match the condition : ",TimeCurrent());
  804. //
  805. // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  806. // {
  807. // Print("time to match the condition : ",TimeCurrent());
  808. //
  809. // //if(ihigh(symbol(),period_current,od_1[m].reversal_index) > ilow(symbol(),period_current,0) && iclose(symbol(),period_current,od_1[m].choch_index) < iclose(symbol(),period_current,0))
  810. // {
  811. // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
  812. // Print("trade placed buy at index ",0);
  813. // od_1[m].choch_index = -1;
  814. //
  815. // }
  816. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  817. //
  818. //
  819. // }
  820. //
  821. // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  822. // {
  823. // Print(TimeCurrent());
  824. // //
  825. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  826. // od_1[m].choch_index = -1;
  827. //
  828. // }
  829. // }
  830. // }
  831. // if(timecurrent() >= time_to_place_trade)
  832. // {
  833. // print("hi");
  834. // if(signal == "buy")
  835. // {
  836. // int index = ibarshift(symbol(), period_current, time_of_candle, false);
  837. // print("index of the 2 hour plus index is ",index);
  838. //
  839. // print("choch index ", i);
  840. // print("reversal index ",ind);
  841. // print("value to be check index ",i-3);
  842. //
  843. // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2))
  844. // // {
  845. // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3));
  846. // // print("trade placed buy at index ",i-3);
  847. // // }
  848. // print(time_to_place_trade);
  849. //
  850. // }
  851. // if(signal == "sell")
  852. // {
  853. // print("trade placed ");
  854. // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3));
  855. //
  856. // print(ind);
  857. // print(time_to_place_trade);
  858. // }
  859. // }
  860. //else
  861. // {
  862. // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  863. // }
  864. break;
  865. default:
  866. current_time_frame_string = "unknown";
  867. break;
  868. }
  869. //print("current timeframe: ", current_time_frame_string);
  870. signal = "";
  871. }
  872. }
  873. }
  874. //+------------------------------------------------------------------+
  875. //| |
  876. //+------------------------------------------------------------------+
  877. void foo1(int value)
  878. {
  879. for(int i=value; i > 0; i--)
  880. {
  881. //Print("hi");
  882. //if(l < 2)
  883. //Bos(i);
  884. //choch(i);
  885. //third_Condition(i);
  886. // if(signal == "buy" || signal == "sell")
  887. // {
  888. // MqlDateTime edate;
  889. // time_to_place_trade = 0.0;
  890. //
  891. // //print("time of the candle ", time_of_candle);
  892. //
  893. // int current_time_frame = Period();
  894. //
  895. // string current_time_frame_string;
  896. //
  897. // switch(current_time_frame)
  898. // {
  899. //
  900. // case PERIOD_M1:
  901. // current_time_frame_string = "1 minute";
  902. // break;
  903. // case PERIOD_M5:
  904. // current_time_frame_string = "5 minutes";
  905. // break;
  906. // case PERIOD_M15:
  907. // current_time_frame_string = "15 minutes";
  908. // break;
  909. // case PERIOD_M30:
  910. // current_time_frame_string = "30 minutes";
  911. // break;
  912. // case PERIOD_H1:
  913. // current_time_frame_string = "1 hour";
  914. //
  915. //
  916. // if(TimeToStruct(time_of_candle,edate))
  917. // {
  918. // edate.hour = edate.hour + 2;
  919. // edate.min = 0;
  920. // edate.sec = 0;
  921. // }
  922. //
  923. //
  924. // // print("hour of the candle is ",structtotime(edate));
  925. // time_to_place_trade = StructToTime(edate);
  926. // store_value_in_structure(1,ind,signal,time_of_candle,time_to_place_trade);
  927. //
  928. //
  929. // // for(int m=0; m < orderNum; m++)
  930. // // {
  931. // // if(od_1[m].choch_index != -1)
  932. // // {
  933. // // Print(" time to match the condition : ",TimeCurrent());
  934. // //
  935. // // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  936. // // {
  937. // // Print("time to match the condition : ",TimeCurrent());
  938. // //
  939. // // //if(ihigh(symbol(),period_current,od_1[m].reversal_index) > ilow(symbol(),period_current,0) && iclose(symbol(),period_current,od_1[m].choch_index) < iclose(symbol(),period_current,0))
  940. // // {
  941. // // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
  942. // // Print("trade placed buy at index ",0);
  943. // // od_1[m].choch_index = -1;
  944. // //
  945. // // }
  946. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  947. // //
  948. // //
  949. // // }
  950. // //
  951. // // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  952. // // {
  953. // // Print(TimeCurrent());
  954. // // //
  955. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  956. // // od_1[m].choch_index = -1;
  957. // //
  958. // // }
  959. // // }
  960. // // }
  961. //
  962. //
  963. //
  964. // // if(timecurrent() >= time_to_place_trade)
  965. // // {
  966. // // print("hi");
  967. // // if(signal == "buy")
  968. // // {
  969. // // int index = ibarshift(symbol(), period_current, time_of_candle, false);
  970. // // print("index of the 2 hour plus index is ",index);
  971. // //
  972. // // print("choch index ", i);
  973. // // print("reversal index ",ind);
  974. // // print("value to be check index ",i-3);
  975. // //
  976. // // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2))
  977. // // // {
  978. // // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3));
  979. // // // print("trade placed buy at index ",i-3);
  980. // // // }
  981. // // print(time_to_place_trade);
  982. // //
  983. // // }
  984. // // if(signal == "sell")
  985. // // {
  986. // // print("trade placed ");
  987. // // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3));
  988. // //
  989. // // print(ind);
  990. // // print(time_to_place_trade);
  991. // // }
  992. // // }
  993. // //else
  994. // // {
  995. // // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  996. // // }
  997. //
  998. // break;
  999. //
  1000. // default:
  1001. // current_time_frame_string = "unknown";
  1002. // break;
  1003. // }
  1004. //
  1005. // //print("current timeframe: ", current_time_frame_string);
  1006. //
  1007. //
  1008. // signal = "";
  1009. // }
  1010. }
  1011. }
  1012. //+------------------------------------------------------------------+
  1013. //| |
  1014. //+------------------------------------------------------------------+
  1015. int OnInit()
  1016. {
  1017. int idx = 0;
  1018. int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT,inpTime, false);
  1019. if(ObjectCreate(0,"line",OBJ_VLINE,0,inpTime,iLow(Symbol(),PERIOD_CURRENT,user_input_index)))
  1020. {
  1021. Print("vertical line created on chart : ");
  1022. }
  1023. else
  1024. {
  1025. Print("error in creating line : ");
  1026. }
  1027. //int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT, D'2022.09.01 15:30:27', false);
  1028. //if(ObjectCreate(0,"line",OBJ_VLINE,0,D'2022.09.01 15:30:27',iLow(Symbol(),PERIOD_CURRENT,user_input_index)))
  1029. // {
  1030. // Print("object created on chart : ");
  1031. // }
  1032. //else
  1033. // {
  1034. // Print("object not created : ");
  1035. // }
  1036. object_find(object_name);
  1037. if(object_find(object_name) == true)
  1038. {
  1039. Print("object found");
  1040. // datetime time_of_candle1 = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
  1041. //
  1042. // index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle1, false);
  1043. // Print("candle is ",checkCandle(user_input_index));
  1044. if(checkCandle(user_input_index) == "Bullish")
  1045. {
  1046. trend = "uptrend";
  1047. high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index);
  1048. high_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index); // ambiguity
  1049. high_index = user_input_index;
  1050. for(int j=user_input_index; j < 1000; j++)
  1051. {
  1052. if(checkCandle(j) == "Bearish")
  1053. {
  1054. low = iLow(Symbol(),PERIOD_CURRENT,j);
  1055. idx = j;
  1056. break;
  1057. }
  1058. }
  1059. idx = iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,idx,user_input_index+1);
  1060. low = iLow(Symbol(),PERIOD_CURRENT,idx);
  1061. low_index_time = iTime(Symbol(),PERIOD_CURRENT,idx);
  1062. low_index = idx;
  1063. }
  1064. if(checkCandle(user_input_index) == "Bearish")
  1065. {
  1066. trend = "downtrend";
  1067. low = iLow(Symbol(),PERIOD_CURRENT,user_input_index);
  1068. low_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index);
  1069. low_index = user_input_index;
  1070. for(int j=user_input_index; j < 1000; j++)
  1071. {
  1072. if(checkCandle(j) == "Bullish")
  1073. {
  1074. // Print("bullish found ",iTime(Symbol(),PERIOD_CURRENT,j));
  1075. high = iHigh(Symbol(),PERIOD_CURRENT,j);
  1076. idx = j;
  1077. break;
  1078. }
  1079. }
  1080. for(int k=idx; k<user_input_index; k++)
  1081. {
  1082. double highh = iHigh(Symbol(),PERIOD_CURRENT,k);
  1083. if(highh > high)
  1084. {
  1085. high = highh;
  1086. high_index_time = iTime(Symbol(),PERIOD_CURRENT,k);
  1087. high_index = k;
  1088. }
  1089. }
  1090. }
  1091. //high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index);
  1092. //low = iLow(Symbol(),PERIOD_CURRENT,user_input_index);
  1093. // Print(high);
  1094. // Print(low);
  1095. //high_index = user_input_index;
  1096. //low_index = user_input_index;
  1097. foo(user_input_index);
  1098. }
  1099. else
  1100. {
  1101. Print("Object Not Found");
  1102. }
  1103. return(INIT_SUCCEEDED);
  1104. }
  1105. //+------------------------------------------------------------------+
  1106. //| Expert deinitialization function |
  1107. //+------------------------------------------------------------------+
  1108. void OnDeinit(const int reason)
  1109. {
  1110. //---
  1111. }
  1112. //+------------------------------------------------------------------+
  1113. //| Expert tick function |
  1114. //+------------------------------------------------------------------+
  1115. void OnTick()
  1116. {
  1117. foo(1);
  1118. // for(int m=0; m < orderNum; m++)
  1119. // {
  1120. // if(od_1[m].choch_index != -1)
  1121. // {
  1122. // //Print(" time to match the condition : ",TimeCurrent());
  1123. //
  1124. // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  1125. // {
  1126. // //Print("time to match the condition : ",TimeCurrent());
  1127. //
  1128. // if(iHigh(Symbol(),PERIOD_CURRENT,od_1[m].reversal_index) > iLow(Symbol(),PERIOD_CURRENT,0) && iClose(Symbol(),PERIOD_CURRENT,od_1[m].choch_index) < iClose(Symbol(),PERIOD_CURRENT,0))
  1129. // {
  1130. // ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0));
  1131. // Print("trade placed buy at index ",0);
  1132. // od_1[m].choch_index = -1;
  1133. //
  1134. // }
  1135. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  1136. //
  1137. //
  1138. // }
  1139. //
  1140. // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  1141. // {
  1142. // Print(TimeCurrent());
  1143. // //
  1144. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  1145. // od_1[m].choch_index = -1;
  1146. //
  1147. // }
  1148. // }
  1149. // }
  1150. }
  1151. //+------------------------------------------------------------------+
  1152. //| |
  1153. //+------------------------------------------------------------------+
  1154. bool NewBar()
  1155. {
  1156. static datetime Last_bar ;
  1157. datetime Current_bar = iTime(Symbol(), PERIOD_CURRENT,0);
  1158. if(Current_bar != Last_bar)
  1159. {
  1160. Last_bar = Current_bar;
  1161. return (true);
  1162. }
  1163. else
  1164. {
  1165. return (false);
  1166. }
  1167. }
  1168. //+------------------------------------------------------------------+
  1169. //| |
  1170. //+------------------------------------------------------------------+
  1171. bool object_find(string obj) // to find object placed by user in the chart
  1172. {
  1173. if(ObjectFind(0,obj) >= 0)
  1174. {
  1175. return true;
  1176. }
  1177. return false;
  1178. }
  1179. //+------------------------------------------------------------------+
  1180. //| |
  1181. //+------------------------------------------------------------------+
  1182. string checkCandle(int v) // to check the candle is bullish or bearish
  1183. {
  1184. double close = iClose(Symbol(),PERIOD_CURRENT,v);
  1185. double open = iOpen(Symbol(),PERIOD_CURRENT,v);
  1186. if(close > open)
  1187. {
  1188. return "Bullish";
  1189. }
  1190. else
  1191. if(close < open)
  1192. {
  1193. return "Bearish";
  1194. }
  1195. return "empty";
  1196. }
  1197. //+------------------------------------------------------------------+
  1198. //+------------------------------------------------------------------+