| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- //+------------------------------------------------------------------+
- //| MK_BOS_CHOCH.mq5 |
- //| Copyright 2023, MetaQuotes Ltd. |
- //| https://www.mql5.com |
- //+------------------------------------------------------------------+
- #property copyright "Copyright 2023, MetaQuotes Ltd."
- #property link "https://www.mql5.com"
- #property version "1.00"
- sinput string str = "<><><><><><> Object Name <><><><><><>";
- input string object_name = "line";
- string trend;
- bool bearish_found = false;
- bool bullish_found = false;
- //+------------------------------------------------------------------+
- //| Expert initialization function |
- //+------------------------------------------------------------------+
- void foo(int index)
- {
- if(checkCandle(index) == "Bullish")
- {
- trend = "uptrend";
- double high,low = 0.0;
- // to store high and low of the value after the object
- high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
- //low = iLow(Symbol(),PERIOD_CURRENT,index-1);
- for(int i=index - 2 ; i > 0; i--)
- {
- double high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
- //double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
- if(high1 > high)
- {
- high = high1;
- int count = (index-1) - i;
- Print("count",count);
- for(int j=1; j < count; j++)
- {
- if(checkCandle(index-j) == "Bearish")
- {
- low = iLow(Symbol(),PERIOD_CURRENT,index-1);
- bearish_found = true;
- }
- }
- if(bearish_found == true)
- {
- double low1;
- for(int k=1; k <= count; k++)
- {
- low1 = iLow(Symbol(),PERIOD_CURRENT,index - k);
- if(low1 < low)
- {
- low = low1;
- }
- }
- bearish_found = false;
- }
- }
- }
- Print(" high price is ", high);
- Print("low price is ", low);
- }
- if(checkCandle(index) == "Bearish")
- {
- trend = "downtrend";
- double high,low = 0.0;
- // to store high and low of the value after the object
- low = iLow(Symbol(),PERIOD_CURRENT,index-1);
- //low = iLow(Symbol(),PERIOD_CURRENT,index-1);
- for(int i=index - 2 ; i > 0; i--)
- {
- double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
- //double low1 = iLow(Symbol(),PERIOD_CURRENT,i);
- if(low1 < low)
- {
- low = low1;
- int count = (index-1) - i;
- Print("count",count);
- for(int j=1; j < count; j++)
- {
- if(checkCandle(index-j) == "Bullish")
- {
- high = iHigh(Symbol(),PERIOD_CURRENT,index-1);
- bullish_found = true;
- }
- }
- if(bullish_found == true)
- {
- double high1;
- for(int k=1; k <= count; k++)
- {
- high1 = iHigh(Symbol(),PERIOD_CURRENT,index - k);
- if(high1 > high)
- {
- high = high1;
- }
- }
- bullish_found = false;
- }
- }
- }
- Print(" high price is ", high);
- Print("low price is ", low);
- }
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- int OnInit()
- {
- //ObjectCreate(0,"line",OBJ_VLINE,0,D'2023.08.01 10:00:27',0);
- object_find(object_name);
- //Print(ObjectFind(0,"line")); // to find the object drawn on the chart
- if(object_find(object_name) == true)
- {
- datetime time_of_candle = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0);
- Print("time is " , time_of_candle);
- int index = iBarShift(0, PERIOD_CURRENT,time_of_candle, true);
- Print("index is " , index);
- foo(index);
- }
- else
- {
- Print("Object Not Found");
- }
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Expert deinitialization function |
- //+------------------------------------------------------------------+
- void OnDeinit(const int reason)
- {
- //---
- }
- //+------------------------------------------------------------------+
- //| Expert tick function |
- //+------------------------------------------------------------------+
- void OnTick()
- {
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- bool object_find(string obj) // to find object placed by user in the chart
- {
- if(ObjectFind(0,obj) >= 0)
- {
- return true;
- }
- return false;
- }
- //+------------------------------------------------------------------+
- //| |
- //+------------------------------------------------------------------+
- string checkCandle(int i) // to check the candle is bullish or bearish
- {
- double close = iClose(Symbol(),PERIOD_CURRENT,i);
- double open = iOpen(Symbol(),PERIOD_CURRENT,i);
- if(close > open)
- {
- return "Bullish";
- }
- else
- if(close < open)
- {
- return "Bearish";
- }
- return "empty";
- }
- //+------------------------------------------------------------------+
|