Нема описа

BOS_CHOCH.mq5 55KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700
  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 in downtrend buy trade : ",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 in uptrend sell trade : ",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,"bos");
  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,"bos");
  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. //print("time of the candle ", time_of_candle);
  770. int current_time_frame = Period();
  771. string current_time_frame_string;
  772. switch(current_time_frame)
  773. {
  774. case PERIOD_M1:
  775. current_time_frame_string = "1 minute";
  776. break;
  777. case PERIOD_M5:
  778. current_time_frame_string = "5 minutes";
  779. break;
  780. case PERIOD_M15:
  781. current_time_frame_string = "15 minutes";
  782. break;
  783. case PERIOD_M30:
  784. current_time_frame_string = "30 minutes";
  785. break;
  786. case PERIOD_H1:
  787. current_time_frame_string = "1 hour";
  788. if(TimeToStruct(time_of_candle,edate))
  789. {
  790. edate.hour = edate.hour + 2;
  791. edate.min = 0;
  792. edate.sec = 0;
  793. }
  794. // print("hour of the candle is ",structtotime(edate));
  795. time_to_place_trade = StructToTime(edate);
  796. store_value_in_structure(i,ind,signal,time_of_candle,time_to_place_trade);
  797. for(int m=0; m < orderNum; m++)
  798. {
  799. if(od_1[m].choch_index != -1)
  800. {
  801. //Print(" time to match the condition : ",TimeCurrent());
  802. if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  803. {
  804. //Print("time to match the condition : ",TimeCurrent());
  805. 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))
  806. {
  807. ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0));
  808. //Print("trade placed buy at index ",0);
  809. od_1[m].choch_index = -1;
  810. }
  811. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  812. }
  813. if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  814. {
  815. 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))
  816. {
  817. ObjectCreate(0,"sell trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iLow(Symbol(),PERIOD_CURRENT,0));
  818. //Print("trade placed sell at index ",0);
  819. od_1[m].choch_index = -1;
  820. }
  821. //Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  822. // Print(TimeCurrent());
  823. //
  824. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  825. od_1[m].choch_index = -1;
  826. }
  827. }
  828. }
  829. // for(int m=0; m < orderNum; m++)
  830. // {
  831. // if(od_1[m].choch_index != -1)
  832. // {
  833. // Print(" time to match the condition : ",TimeCurrent());
  834. //
  835. // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  836. // {
  837. // Print("time to match the condition : ",TimeCurrent());
  838. //
  839. // //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))
  840. // {
  841. // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
  842. // Print("trade placed buy at index ",0);
  843. // od_1[m].choch_index = -1;
  844. //
  845. // }
  846. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  847. //
  848. //
  849. // }
  850. //
  851. // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  852. // {
  853. // Print(TimeCurrent());
  854. // //
  855. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  856. // od_1[m].choch_index = -1;
  857. //
  858. // }
  859. // }
  860. // }
  861. // if(timecurrent() >= time_to_place_trade)
  862. // {
  863. // print("hi");
  864. // if(signal == "buy")
  865. // {
  866. // int index = ibarshift(symbol(), period_current, time_of_candle, false);
  867. // print("index of the 2 hour plus index is ",index);
  868. //
  869. // print("choch index ", i);
  870. // print("reversal index ",ind);
  871. // print("value to be check index ",i-3);
  872. //
  873. // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2))
  874. // // {
  875. // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3));
  876. // // print("trade placed buy at index ",i-3);
  877. // // }
  878. // print(time_to_place_trade);
  879. //
  880. // }
  881. // if(signal == "sell")
  882. // {
  883. // print("trade placed ");
  884. // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3));
  885. //
  886. // print(ind);
  887. // print(time_to_place_trade);
  888. // }
  889. // }
  890. //else
  891. // {
  892. // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  893. // }
  894. break;
  895. default:
  896. current_time_frame_string = "unknown";
  897. break;
  898. }
  899. //print("current timeframe: ", current_time_frame_string);
  900. signal = "";
  901. }
  902. }
  903. }
  904. //+------------------------------------------------------------------+
  905. //| |
  906. //+------------------------------------------------------------------+
  907. void foo1(int value)
  908. {
  909. for(int i=value; i > 0; i--)
  910. {
  911. //Print("hi");
  912. //if(l < 2)
  913. //Bos(i);
  914. //choch(i);
  915. //third_Condition(i);
  916. // if(signal == "buy" || signal == "sell")
  917. // {
  918. // MqlDateTime edate;
  919. // time_to_place_trade = 0.0;
  920. //
  921. // //print("time of the candle ", time_of_candle);
  922. //
  923. // int current_time_frame = Period();
  924. //
  925. // string current_time_frame_string;
  926. //
  927. // switch(current_time_frame)
  928. // {
  929. //
  930. // case PERIOD_M1:
  931. // current_time_frame_string = "1 minute";
  932. // break;
  933. // case PERIOD_M5:
  934. // current_time_frame_string = "5 minutes";
  935. // break;
  936. // case PERIOD_M15:
  937. // current_time_frame_string = "15 minutes";
  938. // break;
  939. // case PERIOD_M30:
  940. // current_time_frame_string = "30 minutes";
  941. // break;
  942. // case PERIOD_H1:
  943. // current_time_frame_string = "1 hour";
  944. //
  945. //
  946. // if(TimeToStruct(time_of_candle,edate))
  947. // {
  948. // edate.hour = edate.hour + 2;
  949. // edate.min = 0;
  950. // edate.sec = 0;
  951. // }
  952. //
  953. //
  954. // // print("hour of the candle is ",structtotime(edate));
  955. // time_to_place_trade = StructToTime(edate);
  956. // store_value_in_structure(1,ind,signal,time_of_candle,time_to_place_trade);
  957. //
  958. //
  959. // // for(int m=0; m < orderNum; m++)
  960. // // {
  961. // // if(od_1[m].choch_index != -1)
  962. // // {
  963. // // Print(" time to match the condition : ",TimeCurrent());
  964. // //
  965. // // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  966. // // {
  967. // // Print("time to match the condition : ",TimeCurrent());
  968. // //
  969. // // //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))
  970. // // {
  971. // // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0));
  972. // // Print("trade placed buy at index ",0);
  973. // // od_1[m].choch_index = -1;
  974. // //
  975. // // }
  976. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  977. // //
  978. // //
  979. // // }
  980. // //
  981. // // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  982. // // {
  983. // // Print(TimeCurrent());
  984. // // //
  985. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  986. // // od_1[m].choch_index = -1;
  987. // //
  988. // // }
  989. // // }
  990. // // }
  991. //
  992. //
  993. //
  994. // // if(timecurrent() >= time_to_place_trade)
  995. // // {
  996. // // print("hi");
  997. // // if(signal == "buy")
  998. // // {
  999. // // int index = ibarshift(symbol(), period_current, time_of_candle, false);
  1000. // // print("index of the 2 hour plus index is ",index);
  1001. // //
  1002. // // print("choch index ", i);
  1003. // // print("reversal index ",ind);
  1004. // // print("value to be check index ",i-3);
  1005. // //
  1006. // // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2))
  1007. // // // {
  1008. // // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3));
  1009. // // // print("trade placed buy at index ",i-3);
  1010. // // // }
  1011. // // print(time_to_place_trade);
  1012. // //
  1013. // // }
  1014. // // if(signal == "sell")
  1015. // // {
  1016. // // print("trade placed ");
  1017. // // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3));
  1018. // //
  1019. // // print(ind);
  1020. // // print(time_to_place_trade);
  1021. // // }
  1022. // // }
  1023. // //else
  1024. // // {
  1025. // // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i);
  1026. // // }
  1027. //
  1028. // break;
  1029. //
  1030. // default:
  1031. // current_time_frame_string = "unknown";
  1032. // break;
  1033. // }
  1034. //
  1035. // //print("current timeframe: ", current_time_frame_string);
  1036. //
  1037. //
  1038. // signal = "";
  1039. // }
  1040. }
  1041. }
  1042. //+------------------------------------------------------------------+
  1043. //| |
  1044. //+------------------------------------------------------------------+
  1045. int OnInit()
  1046. {
  1047. int idx = 0;
  1048. int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT,inpTime, false);
  1049. if(ObjectCreate(0,"line",OBJ_VLINE,0,inpTime,iLow(Symbol(),PERIOD_CURRENT,user_input_index)))
  1050. {
  1051. Print("vertical line created on chart : ");
  1052. }
  1053. else
  1054. {
  1055. Print("error in creating line : ");
  1056. }
  1057. //int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT, D'2022.09.01 15:30:27', false);
  1058. //if(ObjectCreate(0,"line",OBJ_VLINE,0,D'2022.09.01 15:30:27',iLow(Symbol(),PERIOD_CURRENT,user_input_index)))
  1059. // {
  1060. // Print("object created on chart : ");
  1061. // }
  1062. //else
  1063. // {
  1064. // Print("object not created : ");
  1065. // }
  1066. object_find(object_name);
  1067. if(object_find(object_name) == true)
  1068. {
  1069. Print("object found");
  1070. // datetime time_of_candle1 = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
  1071. //
  1072. // index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle1, false);
  1073. // Print("candle is ",checkCandle(user_input_index));
  1074. if(checkCandle(user_input_index) == "Bullish")
  1075. {
  1076. trend = "uptrend";
  1077. high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index);
  1078. high_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index); // ambiguity
  1079. high_index = user_input_index;
  1080. for(int j=user_input_index; j < 1000; j++)
  1081. {
  1082. if(checkCandle(j) == "Bearish")
  1083. {
  1084. low = iLow(Symbol(),PERIOD_CURRENT,j);
  1085. idx = j;
  1086. break;
  1087. }
  1088. }
  1089. idx = iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,idx,user_input_index+1);
  1090. low = iLow(Symbol(),PERIOD_CURRENT,idx);
  1091. low_index_time = iTime(Symbol(),PERIOD_CURRENT,idx);
  1092. low_index = idx;
  1093. }
  1094. if(checkCandle(user_input_index) == "Bearish")
  1095. {
  1096. trend = "downtrend";
  1097. low = iLow(Symbol(),PERIOD_CURRENT,user_input_index);
  1098. low_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index);
  1099. low_index = user_input_index;
  1100. for(int j=user_input_index; j < 1000; j++)
  1101. {
  1102. if(checkCandle(j) == "Bullish")
  1103. {
  1104. // Print("bullish found ",iTime(Symbol(),PERIOD_CURRENT,j));
  1105. high = iHigh(Symbol(),PERIOD_CURRENT,j);
  1106. idx = j;
  1107. break;
  1108. }
  1109. }
  1110. for(int k=idx; k<user_input_index; k++)
  1111. {
  1112. double highh = iHigh(Symbol(),PERIOD_CURRENT,k);
  1113. if(highh > high)
  1114. {
  1115. high = highh;
  1116. high_index_time = iTime(Symbol(),PERIOD_CURRENT,k);
  1117. high_index = k;
  1118. }
  1119. }
  1120. }
  1121. //high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index);
  1122. //low = iLow(Symbol(),PERIOD_CURRENT,user_input_index);
  1123. // Print(high);
  1124. // Print(low);
  1125. //high_index = user_input_index;
  1126. //low_index = user_input_index;
  1127. foo(user_input_index);
  1128. }
  1129. else
  1130. {
  1131. Print("Object Not Found");
  1132. }
  1133. return(INIT_SUCCEEDED);
  1134. }
  1135. //+------------------------------------------------------------------+
  1136. //| Expert deinitialization function |
  1137. //+------------------------------------------------------------------+
  1138. void OnDeinit(const int reason)
  1139. {
  1140. //---
  1141. }
  1142. //+------------------------------------------------------------------+
  1143. //| Expert tick function |
  1144. //+------------------------------------------------------------------+
  1145. void OnTick()
  1146. {
  1147. foo(1);
  1148. // for(int m=0; m < orderNum; m++)
  1149. // {
  1150. // if(od_1[m].choch_index != -1)
  1151. // {
  1152. // //Print(" time to match the condition : ",TimeCurrent());
  1153. //
  1154. // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy")
  1155. // {
  1156. // //Print("time to match the condition : ",TimeCurrent());
  1157. //
  1158. // 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))
  1159. // {
  1160. // ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0));
  1161. // Print("trade placed buy at index ",0);
  1162. // od_1[m].choch_index = -1;
  1163. //
  1164. // }
  1165. // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  1166. //
  1167. //
  1168. // }
  1169. //
  1170. // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell")
  1171. // {
  1172. // Print(TimeCurrent());
  1173. // //
  1174. // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade);
  1175. // od_1[m].choch_index = -1;
  1176. //
  1177. // }
  1178. // }
  1179. // }
  1180. }
  1181. //+------------------------------------------------------------------+
  1182. //| |
  1183. //+------------------------------------------------------------------+
  1184. bool NewBar()
  1185. {
  1186. static datetime Last_bar ;
  1187. datetime Current_bar = iTime(Symbol(), PERIOD_CURRENT,0);
  1188. if(Current_bar != Last_bar)
  1189. {
  1190. Last_bar = Current_bar;
  1191. return (true);
  1192. }
  1193. else
  1194. {
  1195. return (false);
  1196. }
  1197. }
  1198. //+------------------------------------------------------------------+
  1199. //| |
  1200. //+------------------------------------------------------------------+
  1201. bool object_find(string obj) // to find object placed by user in the chart
  1202. {
  1203. if(ObjectFind(0,obj) >= 0)
  1204. {
  1205. return true;
  1206. }
  1207. return false;
  1208. }
  1209. //+------------------------------------------------------------------+
  1210. //| |
  1211. //+------------------------------------------------------------------+
  1212. string checkCandle(int v) // to check the candle is bullish or bearish
  1213. {
  1214. double close = iClose(Symbol(),PERIOD_CURRENT,v);
  1215. double open = iOpen(Symbol(),PERIOD_CURRENT,v);
  1216. if(close > open)
  1217. {
  1218. return "Bullish";
  1219. }
  1220. else
  1221. if(close < open)
  1222. {
  1223. return "Bearish";
  1224. }
  1225. return "empty";
  1226. }
  1227. //+------------------------------------------------------------------+
  1228. //+------------------------------------------------------------------+