暫無描述

BOS_CHOCH.mq5 54KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  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. double find_high = 0.0;
  444. datetime find_high_time = 0.0;
  445. double find_low = 0.0;
  446. datetime find_low_time = 0.0;
  447. if(trend == "downtrend")
  448. {
  449. choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false);
  450. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  451. if(i+1 == choch_index || i+1 == Store_bos_last_index || i == choch_index || i == Store_bos_last_index)
  452. {
  453. cnd = false;
  454. }
  455. else
  456. {
  457. cnd = true;
  458. }
  459. if(choch_index_time > store_last_bos_index_time)
  460. {
  461. for(int m=choch_index; m>i; m--)
  462. {
  463. if(checkCandle(m) == "Bullish")
  464. {
  465. candle_bullish = true;
  466. }
  467. }
  468. choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false);
  469. find_high = iHigh(Symbol(),PERIOD_CURRENT,choch_index);
  470. for(int j=choch_index; j>=i; j--)
  471. {
  472. double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,j);
  473. if(find_high < find_high1)
  474. {
  475. find_high = find_high1;
  476. find_high_time = iTime(Symbol(),PERIOD_CURRENT,j);
  477. }
  478. if(iClose(Symbol(),PERIOD_CURRENT,j) < iClose(Symbol(),PERIOD_CURRENT,i) || iLow(Symbol(),PERIOD_CURRENT,j) < iLow(Symbol(),PERIOD_CURRENT,i))
  479. {
  480. cnd = false;
  481. }
  482. }
  483. }
  484. if(choch_index_time < store_last_bos_index_time)
  485. {
  486. for(int m=Store_bos_last_index; m>i; m--)
  487. {
  488. if(checkCandle(m) == "Bullish")
  489. {
  490. candle_bullish = true;
  491. }
  492. }
  493. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  494. find_high = iHigh(Symbol(),PERIOD_CURRENT,Store_bos_last_index);
  495. for(int j=Store_bos_last_index; j>=i; j--)
  496. {
  497. double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,j);
  498. if(find_high < find_high1)
  499. {
  500. find_high = find_high1;
  501. find_high_time = iTime(Symbol(),PERIOD_CURRENT,j);
  502. }
  503. if(iClose(Symbol(),PERIOD_CURRENT,j) < iClose(Symbol(),PERIOD_CURRENT,i) || iLow(Symbol(),PERIOD_CURRENT,j) < iLow(Symbol(),PERIOD_CURRENT,i))
  504. {
  505. cnd = false;
  506. }
  507. }
  508. }
  509. if(cnd == true && candle_bullish == true)
  510. {
  511. Print("high is --------------",find_high);
  512. Print("high time is --------------",find_high_time);
  513. if(object_find("high") > 0)
  514. {
  515. ObjectDelete(0,"high");
  516. }
  517. high = find_high;
  518. index_of_high = iBarShift(Symbol(), PERIOD_CURRENT, find_high_time, false);
  519. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_high),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  520. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  521. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  522. if(object_find("low") > 0)
  523. {
  524. ObjectDelete(0,"low");
  525. }
  526. low = iLow(Symbol(),PERIOD_CURRENT,i);
  527. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  528. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  529. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  530. ObjectCreate(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),low);
  531. ObjectSetString(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos2");
  532. store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  533. // Print(store_last_bos_index_time);
  534. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  535. // Print("last bos index is ",Store_bos_last_index);
  536. // Print("low is ", low);
  537. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  538. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  539. // Print("low index ",low_index);
  540. cnd = false;
  541. candle_bullish = false;
  542. }
  543. }
  544. //-------
  545. if(trend == "uptrend")
  546. {
  547. choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false);
  548. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  549. if(i+1 == choch_index || i+1 == Store_bos_last_index || i == choch_index || i == Store_bos_last_index)
  550. {
  551. cnd = false;
  552. }
  553. else
  554. {
  555. cnd = true;
  556. }
  557. if(choch_index_time < store_last_bos_index_time)
  558. {
  559. for(int m=Store_bos_last_index; m>i; m--)
  560. {
  561. if(checkCandle(m) == "Bearish")
  562. {
  563. // Print("found bearish at index ",iTime(Symbol(),PERIOD_CURRENT,m));
  564. candle_bearish = true;
  565. }
  566. }
  567. find_low = iLow(Symbol(),PERIOD_CURRENT,Store_bos_last_index);
  568. for(int j=Store_bos_last_index; j>=i; j--)
  569. {
  570. double find_low1 = iLow(Symbol(),PERIOD_CURRENT,j);
  571. if(find_low > find_low1)
  572. {
  573. find_low = find_low1;
  574. find_low_time = iTime(Symbol(),PERIOD_CURRENT,j);
  575. }
  576. if(iClose(Symbol(),PERIOD_CURRENT,j) > iClose(Symbol(),PERIOD_CURRENT,i) || iHigh(Symbol(),PERIOD_CURRENT,j) > iHigh(Symbol(),PERIOD_CURRENT,i))
  577. {
  578. cnd = false;
  579. }
  580. }
  581. }
  582. if(choch_index_time > store_last_bos_index_time)
  583. {
  584. for(int m=choch_index; m>i; m--)
  585. {
  586. if(checkCandle(m) == "Bearish")
  587. {
  588. // Print("found bearish at index ",iTime(Symbol(),PERIOD_CURRENT,m));
  589. candle_bearish = true;
  590. }
  591. }
  592. find_low = iLow(Symbol(),PERIOD_CURRENT,choch_index);
  593. for(int j=choch_index; j>=i; j--)
  594. {
  595. double find_low1 = iLow(Symbol(),PERIOD_CURRENT,j);
  596. if(find_low > find_low1)
  597. {
  598. find_low = find_low1;
  599. find_low_time = iTime(Symbol(),PERIOD_CURRENT,j);
  600. }
  601. if(iClose(Symbol(),PERIOD_CURRENT,j) > iClose(Symbol(),PERIOD_CURRENT,i) || iHigh(Symbol(),PERIOD_CURRENT,j) > iHigh(Symbol(),PERIOD_CURRENT,i))
  602. {
  603. cnd = false;
  604. }
  605. }
  606. }
  607. if(cnd == true && candle_bearish == true)
  608. {
  609. Print("low is --------------",find_low);
  610. Print("low time is --------------",find_low_time);
  611. if(object_find("low") > 0)
  612. {
  613. ObjectDelete(0,"low");
  614. }
  615. low = find_low;
  616. index_of_low = iBarShift(Symbol(), PERIOD_CURRENT, find_low_time, false);
  617. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_low),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  618. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  619. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  620. if(object_find("high") > 0)
  621. {
  622. ObjectDelete(0,"high");
  623. }
  624. high = iHigh(Symbol(),PERIOD_CURRENT,i);
  625. // Print(" high is updated : ",high);
  626. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  627. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  628. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  629. ObjectCreate(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),high);
  630. ObjectSetString(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos2");
  631. store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  632. Print(store_last_bos_index_time);
  633. Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
  634. // Print("last bos index is ",Store_bos_last_index);
  635. // Print("high is ", high);
  636. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  637. high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false);
  638. // Print("low index ",high_index);
  639. cnd = false;
  640. candle_bearish = false;
  641. }
  642. }
  643. }
  644. //+------------------------------------------------------------------+
  645. //| |
  646. //+------------------------------------------------------------------+
  647. bool third_condition_met = false;
  648. void third_Condition(int i)
  649. {
  650. if(trend == "uptrend")
  651. {
  652. low2 = iLow(Symbol(),PERIOD_CURRENT,i);
  653. high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
  654. if(low2 < low)
  655. {
  656. third_condition_met = true;
  657. ObjectCreate(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
  658. ObjectSetString(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  659. low = low2;
  660. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  661. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  662. low_index = i; // addtion to be minus
  663. if(object_find("low") > 0)
  664. {
  665. ObjectDelete(0,"low");
  666. }
  667. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  668. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  669. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  670. // Print("low update due to third condition",low," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
  671. }
  672. if(high2 > high)
  673. {
  674. //third_condition_met = true;
  675. ObjectCreate(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
  676. ObjectSetString(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  677. high = high2;
  678. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  679. high_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  680. high_index = i; // addtion to be minus
  681. if(object_find("high") > 0)
  682. {
  683. ObjectDelete(0,"high");
  684. }
  685. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  686. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  687. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  688. // Print("high update due to third condition",high," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i));
  689. }
  690. }
  691. if(trend == "downtrend")
  692. {
  693. high2 = iHigh(Symbol(),PERIOD_CURRENT,i);
  694. low2 = iLow(Symbol(),PERIOD_CURRENT,i);
  695. if(high2 > high)
  696. {
  697. //third_condition_met = true;
  698. ObjectCreate(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i));
  699. ObjectSetString(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  700. high = high2;
  701. high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  702. high_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  703. high_index = i; // addtion to be minus
  704. if(object_find("high") > 0)
  705. {
  706. ObjectDelete(0,"high");
  707. }
  708. ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high);
  709. ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true);
  710. ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue);
  711. // Print("high update due to third condition",high);
  712. }
  713. if(low2 < low)
  714. {
  715. third_condition_met = true;
  716. ObjectCreate(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i));
  717. ObjectSetString(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C");
  718. low = low2;
  719. low_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
  720. low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
  721. low_index = i; // addtion to be minus
  722. if(object_find("low") > 0)
  723. {
  724. ObjectDelete(0,"low");
  725. }
  726. // Print("low value is ", low);
  727. ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low);
  728. ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true);
  729. ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed);
  730. // Print("low update due to third condition",low);
  731. }
  732. }
  733. }
  734. //+------------------------------------------------------------------+
  735. //| |
  736. //+------------------------------------------------------------------+
  737. void store_value_in_structure(int i,int ind,string signal,datetime time_of_candle,datetime time_to_place_trade)
  738. {
  739. for(int l=0; l<200; l++)
  740. {
  741. if(od_1[l].choch_index == -1)
  742. {
  743. od_1[l].choch_index = i;
  744. od_1[l].reversal_index = ind;
  745. od_1[l].Signal = signal;
  746. od_1[l].Time_OF_Candle = time_of_candle;
  747. Print("saved time in the structure ",time_of_candle);
  748. od_1[l].Time_of_candle_For_trade = time_to_place_trade;
  749. Print("saved time in the structure ",time_to_place_trade);
  750. break;
  751. }
  752. }
  753. }
  754. //+------------------------------------------------------------------+
  755. //| |
  756. //+------------------------------------------------------------------+
  757. void foo(int value)
  758. {
  759. for(int i=value; i > 0; i--)
  760. {
  761. Bos(i);
  762. bos2(i);
  763. choch(i);
  764. third_Condition(i);
  765. // if(signal == "buy" || signal == "sell")
  766. // {
  767. // MqlDateTime edate;
  768. // time_to_place_trade = 0.0;
  769. //
  770. // //print("time of the candle ", time_of_candle);
  771. //
  772. // int current_time_frame = Period();
  773. //
  774. // string current_time_frame_string;
  775. //
  776. // switch(current_time_frame)
  777. // {
  778. //
  779. // case PERIOD_M1:
  780. // current_time_frame_string = "1 minute";
  781. // break;
  782. // case PERIOD_M5:
  783. // current_time_frame_string = "5 minutes";
  784. // break;
  785. // case PERIOD_M15:
  786. // current_time_frame_string = "15 minutes";
  787. // break;
  788. // case PERIOD_M30:
  789. // current_time_frame_string = "30 minutes";
  790. // break;
  791. // case PERIOD_H1:
  792. // current_time_frame_string = "1 hour";
  793. //
  794. //
  795. // if(TimeToStruct(time_of_candle,edate))
  796. // {
  797. // edate.hour = edate.hour + 2;
  798. // edate.min = 0;
  799. // edate.sec = 0;
  800. // }
  801. //
  802. //
  803. // // print("hour of the candle is ",structtotime(edate));
  804. // time_to_place_trade = StructToTime(edate);
  805. //
  806. //
  807. //
  808. // // for(int m=0; m < orderNum; m++)
  809. // // {
  810. // // if(od_1[m].choch_index != -1)
  811. // // {
  812. // // Print(" time to match the condition : ",TimeCurrent());
  813. // //
  814. // // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  815. // // {
  816. // // Print("time to match the condition : ",TimeCurrent());
  817. // //
  818. // // //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))
  819. // // {
  820. // // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
  821. // // Print("trade placed buy at index ",0);
  822. // // od_1[m].choch_index = -1;
  823. // //
  824. // // }
  825. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  826. // //
  827. // //
  828. // // }
  829. // //
  830. // // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  831. // // {
  832. // // Print(TimeCurrent());
  833. // // //
  834. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  835. // // od_1[m].choch_index = -1;
  836. // //
  837. // // }
  838. // // }
  839. // // }
  840. //
  841. //
  842. //
  843. // // if(timecurrent() >= time_to_place_trade)
  844. // // {
  845. // // print("hi");
  846. // // if(signal == "buy")
  847. // // {
  848. // // int index = ibarshift(symbol(), period_current, time_of_candle, false);
  849. // // print("index of the 2 hour plus index is ",index);
  850. // //
  851. // // print("choch index ", i);
  852. // // print("reversal index ",ind);
  853. // // print("value to be check index ",i-3);
  854. // //
  855. // // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2))
  856. // // // {
  857. // // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3));
  858. // // // print("trade placed buy at index ",i-3);
  859. // // // }
  860. // // print(time_to_place_trade);
  861. // //
  862. // // }
  863. // // if(signal == "sell")
  864. // // {
  865. // // print("trade placed ");
  866. // // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3));
  867. // //
  868. // // print(ind);
  869. // // print(time_to_place_trade);
  870. // // }
  871. // // }
  872. // //else
  873. // // {
  874. // // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  875. // // }
  876. //
  877. // break;
  878. //
  879. // default:
  880. // current_time_frame_string = "unknown";
  881. // break;
  882. // }
  883. //
  884. // //print("current timeframe: ", current_time_frame_string);
  885. //
  886. //
  887. // signal = "";
  888. // }
  889. }
  890. }
  891. //+------------------------------------------------------------------+
  892. //| |
  893. //+------------------------------------------------------------------+
  894. void foo1(int value)
  895. {
  896. for(int i=value; i > 0; i--)
  897. {
  898. //Print("hi");
  899. //if(l < 2)
  900. //Bos(i);
  901. //choch(i);
  902. //third_Condition(i);
  903. // if(signal == "buy" || signal == "sell")
  904. // {
  905. // MqlDateTime edate;
  906. // time_to_place_trade = 0.0;
  907. //
  908. // //print("time of the candle ", time_of_candle);
  909. //
  910. // int current_time_frame = Period();
  911. //
  912. // string current_time_frame_string;
  913. //
  914. // switch(current_time_frame)
  915. // {
  916. //
  917. // case PERIOD_M1:
  918. // current_time_frame_string = "1 minute";
  919. // break;
  920. // case PERIOD_M5:
  921. // current_time_frame_string = "5 minutes";
  922. // break;
  923. // case PERIOD_M15:
  924. // current_time_frame_string = "15 minutes";
  925. // break;
  926. // case PERIOD_M30:
  927. // current_time_frame_string = "30 minutes";
  928. // break;
  929. // case PERIOD_H1:
  930. // current_time_frame_string = "1 hour";
  931. //
  932. //
  933. // if(TimeToStruct(time_of_candle,edate))
  934. // {
  935. // edate.hour = edate.hour + 2;
  936. // edate.min = 0;
  937. // edate.sec = 0;
  938. // }
  939. //
  940. //
  941. // // print("hour of the candle is ",structtotime(edate));
  942. // time_to_place_trade = StructToTime(edate);
  943. // store_value_in_structure(1,ind,signal,time_of_candle,time_to_place_trade);
  944. //
  945. //
  946. // // for(int m=0; m < orderNum; m++)
  947. // // {
  948. // // if(od_1[m].choch_index != -1)
  949. // // {
  950. // // Print(" time to match the condition : ",TimeCurrent());
  951. // //
  952. // // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  953. // // {
  954. // // Print("time to match the condition : ",TimeCurrent());
  955. // //
  956. // // //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))
  957. // // {
  958. // // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
  959. // // Print("trade placed buy at index ",0);
  960. // // od_1[m].choch_index = -1;
  961. // //
  962. // // }
  963. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  964. // //
  965. // //
  966. // // }
  967. // //
  968. // // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  969. // // {
  970. // // Print(TimeCurrent());
  971. // // //
  972. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  973. // // od_1[m].choch_index = -1;
  974. // //
  975. // // }
  976. // // }
  977. // // }
  978. //
  979. //
  980. //
  981. // // if(timecurrent() >= time_to_place_trade)
  982. // // {
  983. // // print("hi");
  984. // // if(signal == "buy")
  985. // // {
  986. // // int index = ibarshift(symbol(), period_current, time_of_candle, false);
  987. // // print("index of the 2 hour plus index is ",index);
  988. // //
  989. // // print("choch index ", i);
  990. // // print("reversal index ",ind);
  991. // // print("value to be check index ",i-3);
  992. // //
  993. // // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2))
  994. // // // {
  995. // // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3));
  996. // // // print("trade placed buy at index ",i-3);
  997. // // // }
  998. // // print(time_to_place_trade);
  999. // //
  1000. // // }
  1001. // // if(signal == "sell")
  1002. // // {
  1003. // // print("trade placed ");
  1004. // // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3));
  1005. // //
  1006. // // print(ind);
  1007. // // print(time_to_place_trade);
  1008. // // }
  1009. // // }
  1010. // //else
  1011. // // {
  1012. // // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  1013. // // }
  1014. //
  1015. // break;
  1016. //
  1017. // default:
  1018. // current_time_frame_string = "unknown";
  1019. // break;
  1020. // }
  1021. //
  1022. // //print("current timeframe: ", current_time_frame_string);
  1023. //
  1024. //
  1025. // signal = "";
  1026. // }
  1027. }
  1028. }
  1029. //+------------------------------------------------------------------+
  1030. //| |
  1031. //+------------------------------------------------------------------+
  1032. int OnInit()
  1033. {
  1034. int idx = 0;
  1035. //int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT,inpTime, false);
  1036. //if(ObjectCreate(0,"line",OBJ_VLINE,0,inpTime,iLow(Symbol(),PERIOD_CURRENT,user_input_index)))
  1037. // {
  1038. // Print("vertical line created on chart : ");
  1039. // }
  1040. //else
  1041. // {
  1042. // Print("error in creating line : ");
  1043. // }
  1044. int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT, D'2022.09.01 15:30:27', false);
  1045. if(ObjectCreate(0,"line",OBJ_VLINE,0,D'2022.09.01 15:30:27',iLow(Symbol(),PERIOD_CURRENT,user_input_index)))
  1046. {
  1047. Print("object created on chart : ");
  1048. }
  1049. else
  1050. {
  1051. Print("object not created : ");
  1052. }
  1053. object_find(object_name);
  1054. if(object_find(object_name) == true)
  1055. {
  1056. Print("object found");
  1057. // datetime time_of_candle1 = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
  1058. //
  1059. // index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle1, false);
  1060. // Print("candle is ",checkCandle(user_input_index));
  1061. if(checkCandle(user_input_index) == "Bullish")
  1062. {
  1063. trend = "uptrend";
  1064. high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index);
  1065. high_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index); // ambiguity
  1066. high_index = user_input_index;
  1067. for(int j=user_input_index; j < 1000; j++)
  1068. {
  1069. if(checkCandle(j) == "Bearish")
  1070. {
  1071. low = iLow(Symbol(),PERIOD_CURRENT,j);
  1072. idx = j;
  1073. break;
  1074. }
  1075. }
  1076. idx = iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,idx,user_input_index+1);
  1077. low = iLow(Symbol(),PERIOD_CURRENT,idx);
  1078. low_index_time = iTime(Symbol(),PERIOD_CURRENT,idx);
  1079. low_index = idx;
  1080. }
  1081. if(checkCandle(user_input_index) == "Bearish")
  1082. {
  1083. trend = "downtrend";
  1084. low = iLow(Symbol(),PERIOD_CURRENT,user_input_index);
  1085. low_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index);
  1086. low_index = user_input_index;
  1087. for(int j=user_input_index; j < 1000; j++)
  1088. {
  1089. if(checkCandle(j) == "Bullish")
  1090. {
  1091. // Print("bullish found ",iTime(Symbol(),PERIOD_CURRENT,j));
  1092. high = iHigh(Symbol(),PERIOD_CURRENT,j);
  1093. idx = j;
  1094. break;
  1095. }
  1096. }
  1097. for(int k=idx; k<user_input_index; k++)
  1098. {
  1099. double highh = iHigh(Symbol(),PERIOD_CURRENT,k);
  1100. if(highh > high)
  1101. {
  1102. high = highh;
  1103. high_index_time = iTime(Symbol(),PERIOD_CURRENT,k);
  1104. high_index = k;
  1105. }
  1106. }
  1107. }
  1108. //high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index);
  1109. //low = iLow(Symbol(),PERIOD_CURRENT,user_input_index);
  1110. // Print(high);
  1111. // Print(low);
  1112. //high_index = user_input_index;
  1113. //low_index = user_input_index;
  1114. foo(user_input_index);
  1115. }
  1116. else
  1117. {
  1118. Print("Object Not Found");
  1119. }
  1120. return(INIT_SUCCEEDED);
  1121. }
  1122. //+------------------------------------------------------------------+
  1123. //| Expert deinitialization function |
  1124. //+------------------------------------------------------------------+
  1125. void OnDeinit(const int reason)
  1126. {
  1127. //---
  1128. }
  1129. //+------------------------------------------------------------------+
  1130. //| Expert tick function |
  1131. //+------------------------------------------------------------------+
  1132. void OnTick()
  1133. {
  1134. foo(1);
  1135. for(int m=0; m < orderNum; m++)
  1136. {
  1137. if(od_1[m].choch_index != -1)
  1138. {
  1139. //Print(" time to match the condition : ",TimeCurrent());
  1140. if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  1141. {
  1142. //Print("time to match the condition : ",TimeCurrent());
  1143. 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))
  1144. {
  1145. ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0));
  1146. Print("trade placed buy at index ",0);
  1147. od_1[m].choch_index = -1;
  1148. }
  1149. Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  1150. }
  1151. if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  1152. {
  1153. Print(TimeCurrent());
  1154. //
  1155. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  1156. od_1[m].choch_index = -1;
  1157. }
  1158. }
  1159. }
  1160. }
  1161. //+------------------------------------------------------------------+
  1162. //| |
  1163. //+------------------------------------------------------------------+
  1164. bool NewBar()
  1165. {
  1166. static datetime Last_bar ;
  1167. datetime Current_bar = iTime(Symbol(), PERIOD_CURRENT,0);
  1168. if(Current_bar != Last_bar)
  1169. {
  1170. Last_bar = Current_bar;
  1171. return (true);
  1172. }
  1173. else
  1174. {
  1175. return (false);
  1176. }
  1177. }
  1178. //+------------------------------------------------------------------+
  1179. //| |
  1180. //+------------------------------------------------------------------+
  1181. bool object_find(string obj) // to find object placed by user in the chart
  1182. {
  1183. if(ObjectFind(0,obj) >= 0)
  1184. {
  1185. return true;
  1186. }
  1187. return false;
  1188. }
  1189. //+------------------------------------------------------------------+
  1190. //| |
  1191. //+------------------------------------------------------------------+
  1192. string checkCandle(int v) // to check the candle is bullish or bearish
  1193. {
  1194. double close = iClose(Symbol(),PERIOD_CURRENT,v);
  1195. double open = iOpen(Symbol(),PERIOD_CURRENT,v);
  1196. if(close > open)
  1197. {
  1198. return "Bullish";
  1199. }
  1200. else
  1201. if(close < open)
  1202. {
  1203. return "Bearish";
  1204. }
  1205. return "empty";
  1206. }
  1207. //+------------------------------------------------------------------+
  1208. //+------------------------------------------------------------------+