Aucune description

BOS_CHOCH.mq5 51KB

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