暂无描述

MK_BOS_CHOCH.mq5 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. sinput string str = "<><><><><><> Object Name <><><><><><>";
  10. input string object_name = "line";
  11. string trend;
  12. bool bearish_found = false;
  13. bool bullish_found = false;
  14. //+------------------------------------------------------------------+
  15. //| Expert initialization function |
  16. //+------------------------------------------------------------------+
  17. void foo(int index)
  18. {
  19. if(checkCandle(index) == "Bullish")
  20. {
  21. trend = "uptrend";
  22. double high,low = 0.0;
  23. // to store high and low of the value after the object
  24. high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
  25. //low = iLow(Symbol(),PERIOD_CURRENT,index-1);
  26. for(int i=index - 2 ; i > 0; i--)
  27. {
  28. double high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
  29. //double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
  30. if(high1 > high)
  31. {
  32. high = high1;
  33. int count = (index-1) - i;
  34. Print("count",count);
  35. for(int j=1; j < count; j++)
  36. {
  37. if(checkCandle(index-j) == "Bearish")
  38. {
  39. low = iLow(Symbol(),PERIOD_CURRENT,index-1);
  40. bearish_found = true;
  41. }
  42. }
  43. if(bearish_found == true)
  44. {
  45. double low1;
  46. for(int k=1; k <= count; k++)
  47. {
  48. low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
  49. if(low1 < low)
  50. {
  51. low = low1;
  52. }
  53. }
  54. bearish_found = false;
  55. }
  56. }
  57. }
  58. Print(" high price is ", high);
  59. Print("low price is ", low);
  60. }
  61. if(checkCandle(index) == "Bearish")
  62. {
  63. trend = "downtrend";
  64. double high,low = 0.0;
  65. // to store high and low of the value after the object
  66. low = iLow(Symbol(),PERIOD_CURRENT,index-1);
  67. //low = iLow(Symbol(),PERIOD_CURRENT,index-1);
  68. for(int i=index - 2 ; i > 0; i--)
  69. {
  70. double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
  71. //double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
  72. if(low1 < low)
  73. {
  74. low = low1;
  75. int count = (index-1) - i;
  76. Print("count",count);
  77. for(int j=1; j < count; j++)
  78. {
  79. if(checkCandle(index-j) == "Bullish")
  80. {
  81. high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
  82. bullish_found = true;
  83. }
  84. }
  85. if(bullish_found == true)
  86. {
  87. double high1;
  88. for(int k=1; k <= count; k++)
  89. {
  90. high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
  91. if(high1 > high)
  92. {
  93. high = high1;
  94. }
  95. }
  96. bullish_found = false;
  97. }
  98. }
  99. }
  100. Print(" high price is ", high);
  101. Print("low price is ", low);
  102. }
  103. }
  104. //+------------------------------------------------------------------+
  105. //| |
  106. //+------------------------------------------------------------------+
  107. int OnInit()
  108. {
  109. //ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.08.01 10:00:27',0);
  110. object_find(object_name);
  111. //Print(ObjectFind(0,"line")); // to find the object drawn on the chart
  112. if(object_find(object_name) == true)
  113. {
  114. datetime time_of_candle = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
  115. Print("time is " , time_of_candle);
  116. int index = iBarShift(0, PERIOD_CURRENT,time_of_candle, true);
  117. Print("index is " , index);
  118. foo(index);
  119. }
  120. else
  121. {
  122. Print("Object Not Found");
  123. }
  124. return(INIT_SUCCEEDED);
  125. }
  126. //+------------------------------------------------------------------+
  127. //| Expert deinitialization function |
  128. //+------------------------------------------------------------------+
  129. void OnDeinit(const int reason)
  130. {
  131. //---
  132. }
  133. //+------------------------------------------------------------------+
  134. //| Expert tick function |
  135. //+------------------------------------------------------------------+
  136. void OnTick()
  137. {
  138. }
  139. //+------------------------------------------------------------------+
  140. //| |
  141. //+------------------------------------------------------------------+
  142. bool object_find(string obj) // to find object placed by user in the chart
  143. {
  144. if(ObjectFind(0,obj) >= 0)
  145. {
  146. return true;
  147. }
  148. return false;
  149. }
  150. //+------------------------------------------------------------------+
  151. //| |
  152. //+------------------------------------------------------------------+
  153. string checkCandle(int i) // to check the candle is bullish or bearish
  154. {
  155. double close = iClose(Symbol(),PERIOD_CURRENT,i);
  156. double open = iOpen(Symbol(),PERIOD_CURRENT,i);
  157. if(close > open)
  158. {
  159. return "Bullish";
  160. }
  161. else
  162. if(close < open)
  163. {
  164. return "Bearish";
  165. }
  166. return "empty";
  167. }
  168. //+------------------------------------------------------------------+