//+------------------------------------------------------------------+ //| 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" #define orderNum 200 struct tradeOrder { int choch_index; int reversal_index; string Signal; datetime Time_OF_Candle; datetime Time_of_candle_For_trade; tradeOrder() { choch_index = -1; Signal = ""; reversal_index = 0; Time_OF_Candle = 0.0; Time_of_candle_For_trade = 0.0; } }; tradeOrder od_1[orderNum]; sinput string str = "<><><><><><> Set Object Name <><><><><><>"; input string object_name = "line"; sinput string str1 = "<><><><><><> Set time of vertical line <><><><><><>"; input datetime inpTime = 0;//First Line Draw time datetime choch_index_time ; int choch_index = 0; int reversal_candle_index = 0; int ind = 0; string trend = " "; bool bearish_found = false; bool bullish_found = false; int index_of_last_high = 0; int index_of_last_low = 0; double hi; double lo; int index_of_low = 0; datetime index_of_low_time; int index_of_high = 0; datetime index_of_high_time; int high_index=0; datetime high_index_time; int low_index =0; datetime low_index_time; double high,low,low1,high1,low2,high2; int Store_bos_last_index = 0; datetime store_last_bos_index_time; //int ind = 0; bool choch_at_index = false; int index = 0; string signal = ""; datetime time_of_candle = 0.0; datetime time_to_place_trade = 0.0; //double close1 = 0.0; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ void Bos(int i) { //Print("in boss"); //Print("trend is ",trend); if(trend == "uptrend") { //high = iHigh(Symbol(),PERIOD_CURRENT,high_index); high1 = iHigh(Symbol(),PERIOD_CURRENT,i); double close = iClose(Symbol(),PERIOD_CURRENT,i); //Print("high is ",high); //Print("close is ", close,"time is ",iTime(Symbol(),PERIOD_CURRENT,i)); if(close > high) { //-------------- // ObjectCreate(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),high); // ObjectSetString(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos"); // // store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i); // Print(store_last_bos_index_time); // // Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // // // Print("last bos index is ",Store_bos_last_index); //------------------ high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false); // Print("high index ",high_index); int count = (high_index-1) - i; // Print("count is ",count); for(int j=count; j >= 1; j--) { if(checkCandle(high_index-j) == "Bearish") { if(object_find("high") > 0) { ObjectDelete(0,"high"); } high = high1; // Print(" high is updated : ",high); ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high); ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue); ObjectCreate(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),high); ObjectSetString(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos"); store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i); //Print(store_last_bos_index_time); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // Print("last bos index is ",Store_bos_last_index); // Print("bearish candle found and its low is ",low); low = iLow(Symbol(),PERIOD_CURRENT,high_index-j); // Print("bearish candle found and its low is ",low); bearish_found = true; count = high_index-j; index_of_low_time = iTime(Symbol(),PERIOD_CURRENT,high_index-j); break; } } if(bearish_found == true) { for(int k=count-1; k > Store_bos_last_index ; k--) { low1 = iLow(Symbol(),PERIOD_CURRENT,k); if(low1 < low) { low = low1; index_of_low_time = iTime(Symbol(),PERIOD_CURRENT,k); //index_of_low = high_index- k; // Print(" ------------------index of low ",index_of_low); bearish_found = false; } } if(object_find("low") > 0) { if(ObjectDelete(0,"low")) { Print("object deleted :"); } } index_of_low = iBarShift(Symbol(), PERIOD_CURRENT, index_of_low_time, false); ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_low),low,iTime(Symbol(),PERIOD_CURRENT,0),low); ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"low",OBJPROP_RAY_LEFT,false); ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed); } // Print("high of uptrend is ", high); // Print("low of uptrend is ", low); high_index_time = iTime(Symbol(),PERIOD_CURRENT,i); } } if(trend == "downtrend") { //low = iLow(Symbol(),PERIOD_CURRENT,low_index); low1 = iLow(Symbol(),PERIOD_CURRENT,i); double close1 = iClose(Symbol(),PERIOD_CURRENT,i); if(close1 < low) { // here the update // ObjectCreate(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),low); // ObjectSetString(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos"); // // // store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i); // Print(store_last_bos_index_time); // // Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // // // Print("last bos index is ",Store_bos_last_index); // to this //Store_bos_last_index = i; low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); // Print("low index ",low_index); int count = (low_index-1) - i; // Print("count is ",count); for(int j=count; j >= 1; j--) { if(checkCandle(low_index-j) == "Bullish") { if(object_find("low") > 0) { ObjectDelete(0,"low"); } low = low1; ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low); ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed); // ----- ObjectCreate(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),low); ObjectSetString(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos"); store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i); // Print(store_last_bos_index_time); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // Print("last bos index is ",Store_bos_last_index); //------ low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); // Print("low index ",low_index); // Print("bullish candle found and its high is ",high); high = iHigh(Symbol(),PERIOD_CURRENT,low_index-j); // Print("bullish candle found and its high is ",high); bullish_found = true; count = low_index-j; index_of_high_time = iTime(Symbol(),PERIOD_CURRENT,low_index-j); break; } } if(bullish_found == true) { for(int k=count-1; k > Store_bos_last_index ; k--) { high1 = iHigh(Symbol(),PERIOD_CURRENT,k); if(high1 > high) { high = high1; index_of_high_time = iTime(Symbol(),PERIOD_CURRENT,k); //index_of_low = high_index- k; bullish_found = false; } } if(object_find("high") > 0) { ObjectDelete(0,"high"); } index_of_high = iBarShift(Symbol(), PERIOD_CURRENT, index_of_high_time, false); ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_high),high,iTime(Symbol(),PERIOD_CURRENT,0),high); ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue); bullish_found = false; } // Print("high is ", high); // Print("low is ", low); low_index_time = iTime(Symbol(),PERIOD_CURRENT,i); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Entry_Action_1_down(int Store_bos_last_index, int i,int diff) { // i is the index of the choch for(int j=Store_bos_last_index+1; j < iBars(Symbol(),PERIOD_CURRENT); j++) { diff++; if(checkCandle(j) == "Bullish") { //Print("bullish found at index ",j); ind = j; // reversal candle index bullish_found = true; break; } } Print("condition satisfied in downtrend buy trade : ",check_values_less_than_choch_high(diff,i)); // Print("choch candle open is ",iOpen(Symbol(),PERIOD_CURRENT,i)); // Print("reversal candle open is ",iOpen(Symbol(),PERIOD_CURRENT,ind)); if(check_values_less_than_choch_high(diff,i) == true) { if(iOpen(Symbol(),PERIOD_CURRENT,ind) > iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) < iClose(Symbol(),PERIOD_CURRENT,i)) { signal = "buy"; time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i); Print("Place buy order -----------------------------------------------------------------------: "); } } //Print(diff); if(bullish_found == true) { 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)); 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)); ObjectSetInteger(0,"line14"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue); ObjectSetInteger(0,"line15"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue); 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)); 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)); ObjectSetInteger(0,"line16"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT); ObjectSetInteger(0,"line17"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT); diff = 0; bullish_found = false; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void Entry_Action_1_up(int Store_bos_last_index, int i,int diff) { for(int j=Store_bos_last_index+1; j < iBars(Symbol(),PERIOD_CURRENT); j++) { diff++; if(checkCandle(j) == "Bearish") { ind = j; // reversal candle index bearish_found = true; break; } } //Print("diff is ", diff); Print("condition satisfied in uptrend sell trade : ",check_values_less_than_choch_low(diff,i)); // Print("choch candle open is ",iOpen(Symbol(),PERIOD_CURRENT,i)); // Print("reversal candle open is ",iOpen(Symbol(),PERIOD_CURRENT,ind)); if(check_values_less_than_choch_low(diff,i) == true) { if(iOpen(Symbol(),PERIOD_CURRENT,ind) < iOpen(Symbol(),PERIOD_CURRENT,i) && iClose(Symbol(),PERIOD_CURRENT,ind) > iClose(Symbol(),PERIOD_CURRENT,i)) { signal = "sell"; time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i); Print("Place sell order -----------------------------------------------------------------------: "); } } if(bearish_found == true) { 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)); 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)); ObjectSetInteger(0,"line10"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue); ObjectSetInteger(0,"line11"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_COLOR,clrBlue); 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)); 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)); ObjectSetInteger(0,"line12"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT); ObjectSetInteger(0,"line13"+iTime(Symbol(),PERIOD_CURRENT,ind),OBJPROP_STYLE,STYLE_DOT); bearish_found = false; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool check_values_less_than_choch_high(int diff,int i) // downtrend { bool found = false; int value = (diff + i) - 1; for(int k=value; k>i; k--) { //Print("high values ",iHigh(Symbol(),PERIOD_CURRENT,k)); //Print("close values ",iClose(Symbol(),PERIOD_CURRENT,i)); if(iHigh(Symbol(),PERIOD_CURRENT,k) > iClose(Symbol(),PERIOD_CURRENT,i)) { found = true; } } if(found == true) { return false; } return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool check_values_less_than_choch_low(int diff,int i) // uptrend { bool found = false; int value = (diff + i) - 1; // from which it start to check value is less in index //Print("value to be start is ",value); for(int k=value; k>i; k--) { if(iLow(Symbol(),PERIOD_CURRENT,k) < iClose(Symbol(),PERIOD_CURRENT,i)) { found = true; } } if(found == true) { return false; } return true; } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void choch(int i) { if(trend == "uptrend") { double close = iClose(Symbol(),PERIOD_CURRENT,i); if(close < low) { choch_at_index = true; ObjectCreate(0,"line3"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i)); ObjectSetString(0,"line3"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"choch"); ObjectCreate(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_ARROW_DOWN,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i)+100*Point()); ObjectSetInteger(0,"line8"+iTime(Symbol(),PERIOD_CURRENT,i),OBJPROP_COLOR,clrRed); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // Print("last bos index is ",Store_bos_last_index); int diff1 = Store_bos_last_index - (i); // Print("diff between bos and last choch is ",diff1); Entry_Action_1_up(Store_bos_last_index,i,diff1); low = iLow(Symbol(),PERIOD_CURRENT,i); low_index_time = iTime(Symbol(),PERIOD_CURRENT,i); low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); low_index = i; if(object_find("low") > 0) { ObjectDelete(0,"low"); } ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low); ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed); //Entry_Action_1_up(Store_bos_last_index,i,di); // Print("low update due to choch : ", low); trend = "downtrend"; // Print("choch at uptrend index --- ", iTime(Symbol(),PERIOD_CURRENT,i)); choch_index_time = iTime(Symbol(),PERIOD_CURRENT,i); } } if(trend == "downtrend") { double close = iClose(Symbol(),PERIOD_CURRENT,i); if(close > high) { choch_at_index = true; ObjectCreate(0,"line4"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i)); ObjectSetString(0,"line4"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"choch"); ObjectCreate(0,"line7"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_ARROW_UP,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i)-100*Point()); ObjectSetInteger(0,"line7"+iTime(Symbol(),PERIOD_CURRENT,i),OBJPROP_COLOR,clrGreen); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // Print("last bos index is ",Store_bos_last_index); int diff = Store_bos_last_index - (i); Entry_Action_1_down(Store_bos_last_index,i,diff); high = iHigh(Symbol(),PERIOD_CURRENT,i); high_index_time = iTime(Symbol(),PERIOD_CURRENT,i); high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false); high_index = i; if(object_find("high") > 0) { ObjectDelete(0,"high"); } ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high); ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue); trend = "uptrend"; // Print("high is update due to choch : ", high); // Print("choch at downtrend index ---- ", iTime(Symbol(),PERIOD_CURRENT,i)); choch_index_time = iTime(Symbol(),PERIOD_CURRENT,i); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void bos2(int i) { bool cnd; bool candle_bullish = false; bool candle_bearish = false; double find_high = 0.0; datetime find_high_time = 0.0; double find_low = 0.0; datetime find_low_time = 0.0; if(trend == "downtrend") { choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); if(i+1 == choch_index || i+1 == Store_bos_last_index || i == choch_index || i == Store_bos_last_index) { cnd = false; } else { cnd = true; } if(choch_index_time > store_last_bos_index_time) { for(int m=choch_index; m>i; m--) { if(checkCandle(m) == "Bullish") { candle_bullish = true; } } choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false); find_high = iHigh(Symbol(),PERIOD_CURRENT,choch_index); for(int j=choch_index; j>=i; j--) { double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,j); if(find_high < find_high1) { find_high = find_high1; find_high_time = iTime(Symbol(),PERIOD_CURRENT,j); } if(iClose(Symbol(),PERIOD_CURRENT,j) < iClose(Symbol(),PERIOD_CURRENT,i) || iLow(Symbol(),PERIOD_CURRENT,j) < iLow(Symbol(),PERIOD_CURRENT,i)) { cnd = false; } } } if(choch_index_time < store_last_bos_index_time) { for(int m=Store_bos_last_index; m>i; m--) { if(checkCandle(m) == "Bullish") { candle_bullish = true; } } Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); find_high = iHigh(Symbol(),PERIOD_CURRENT,Store_bos_last_index); for(int j=Store_bos_last_index; j>=i; j--) { double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,j); if(find_high < find_high1) { find_high = find_high1; find_high_time = iTime(Symbol(),PERIOD_CURRENT,j); } if(iClose(Symbol(),PERIOD_CURRENT,j) < iClose(Symbol(),PERIOD_CURRENT,i) || iLow(Symbol(),PERIOD_CURRENT,j) < iLow(Symbol(),PERIOD_CURRENT,i)) { cnd = false; } } } if(cnd == true && candle_bullish == true) { // Print("high is --------------",find_high); // Print("high time is --------------",find_high_time); if(object_find("high") > 0) { ObjectDelete(0,"high"); } high = find_high; index_of_high = iBarShift(Symbol(), PERIOD_CURRENT, find_high_time, false); ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_high),high,iTime(Symbol(),PERIOD_CURRENT,0),high); ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue); if(object_find("low") > 0) { ObjectDelete(0,"low"); } low = iLow(Symbol(),PERIOD_CURRENT,i); ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low); ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed); ObjectCreate(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),low); ObjectSetString(0,"line2"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos"); store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i); // Print(store_last_bos_index_time); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // Print("last bos index is ",Store_bos_last_index); // Print("low is ", low); low_index_time = iTime(Symbol(),PERIOD_CURRENT,i); low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); // Print("low index ",low_index); cnd = false; candle_bullish = false; } } //------- if(trend == "uptrend") { choch_index = iBarShift(Symbol(), PERIOD_CURRENT, choch_index_time, false); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); if(i+1 == choch_index || i+1 == Store_bos_last_index || i == choch_index || i == Store_bos_last_index) { cnd = false; } else { cnd = true; } if(choch_index_time < store_last_bos_index_time) { for(int m=Store_bos_last_index; m>i; m--) { if(checkCandle(m) == "Bearish") { // Print("found bearish at index ",iTime(Symbol(),PERIOD_CURRENT,m)); candle_bearish = true; } } find_low = iLow(Symbol(),PERIOD_CURRENT,Store_bos_last_index); for(int j=Store_bos_last_index; j>=i; j--) { double find_low1 = iLow(Symbol(),PERIOD_CURRENT,j); if(find_low > find_low1) { find_low = find_low1; find_low_time = iTime(Symbol(),PERIOD_CURRENT,j); } if(iClose(Symbol(),PERIOD_CURRENT,j) > iClose(Symbol(),PERIOD_CURRENT,i) || iHigh(Symbol(),PERIOD_CURRENT,j) > iHigh(Symbol(),PERIOD_CURRENT,i)) { cnd = false; } } } if(choch_index_time > store_last_bos_index_time) { for(int m=choch_index; m>i; m--) { if(checkCandle(m) == "Bearish") { // Print("found bearish at index ",iTime(Symbol(),PERIOD_CURRENT,m)); candle_bearish = true; } } find_low = iLow(Symbol(),PERIOD_CURRENT,choch_index); for(int j=choch_index; j>=i; j--) { double find_low1 = iLow(Symbol(),PERIOD_CURRENT,j); if(find_low > find_low1) { find_low = find_low1; find_low_time = iTime(Symbol(),PERIOD_CURRENT,j); } if(iClose(Symbol(),PERIOD_CURRENT,j) > iClose(Symbol(),PERIOD_CURRENT,i) || iHigh(Symbol(),PERIOD_CURRENT,j) > iHigh(Symbol(),PERIOD_CURRENT,i)) { cnd = false; } } } if(cnd == true && candle_bearish == true) { // Print("low is --------------",find_low); // Print("low time is --------------",find_low_time); if(object_find("low") > 0) { ObjectDelete(0,"low"); } low = find_low; index_of_low = iBarShift(Symbol(), PERIOD_CURRENT, find_low_time, false); ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,index_of_low),low,iTime(Symbol(),PERIOD_CURRENT,0),low); ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed); if(object_find("high") > 0) { ObjectDelete(0,"high"); } high = iHigh(Symbol(),PERIOD_CURRENT,i); // Print(" high is updated : ",high); ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high); ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue); ObjectCreate(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),high); ObjectSetString(0,"line1"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"bos"); store_last_bos_index_time = iTime(Symbol(),PERIOD_CURRENT,i); // Print(store_last_bos_index_time); Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false); // Print("last bos index is ",Store_bos_last_index); // Print("high is ", high); high_index_time = iTime(Symbol(),PERIOD_CURRENT,i); high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false); // Print("low index ",high_index); cnd = false; candle_bearish = false; } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool third_condition_met = false; void third_Condition(int i) { if(trend == "uptrend") { low2 = iLow(Symbol(),PERIOD_CURRENT,i); high2 = iHigh(Symbol(),PERIOD_CURRENT,i); if(low2 < low) { third_condition_met = true; // ObjectCreate(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i)); // ObjectSetString(0,"line5"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C"); low = low2; low_index_time = iTime(Symbol(),PERIOD_CURRENT,i); low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); low_index = i; // addtion to be minus if(object_find("low") > 0) { ObjectDelete(0,"low"); } ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low); ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed); // Print("low update due to third condition",low," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i)); } if(high2 > high) { //third_condition_met = true; // ObjectCreate(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i)); // ObjectSetString(0,"line51"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C"); high = high2; high_index_time = iTime(Symbol(),PERIOD_CURRENT,i); high_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); high_index = i; // addtion to be minus if(object_find("high") > 0) { ObjectDelete(0,"high"); } ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high); ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue); // Print("high update due to third condition",high," time of the candle is ",iTime(Symbol(),PERIOD_CURRENT,i)); } } if(trend == "downtrend") { high2 = iHigh(Symbol(),PERIOD_CURRENT,i); low2 = iLow(Symbol(),PERIOD_CURRENT,i); if(high2 > high) { //third_condition_met = true; // ObjectCreate(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iHigh(Symbol(),PERIOD_CURRENT,i)); // ObjectSetString(0,"line6"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C"); high = high2; high_index_time = iTime(Symbol(),PERIOD_CURRENT,i); high_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); high_index = i; // addtion to be minus if(object_find("high") > 0) { ObjectDelete(0,"high"); } ObjectCreate(0,"high",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),high,iTime(Symbol(),PERIOD_CURRENT,0),high); ObjectSetInteger(0,"high",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"high",OBJPROP_COLOR,clrBlue); // Print("high update due to third condition",high); } if(low2 < low) { third_condition_met = true; // ObjectCreate(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i),OBJ_TEXT,0,iTime(Symbol(),PERIOD_CURRENT,i),iLow(Symbol(),PERIOD_CURRENT,i)); // ObjectSetString(0,"line61"+iTime(Symbol(),PERIOD_CURRENT,i), OBJPROP_TEXT,"3_C"); low = low2; low_index_time = iTime(Symbol(),PERIOD_CURRENT,i); low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false); low_index = i; // addtion to be minus if(object_find("low") > 0) { ObjectDelete(0,"low"); } // Print("low value is ", low); ObjectCreate(0,"low",OBJ_TREND,0,iTime(Symbol(),PERIOD_CURRENT,i),low,iTime(Symbol(),PERIOD_CURRENT,0),low); ObjectSetInteger(0,"low",OBJPROP_RAY_RIGHT,true); ObjectSetInteger(0,"low",OBJPROP_COLOR,clrRed); // Print("low update due to third condition",low); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void store_value_in_structure(int i,int ind,string signal,datetime time_of_candle,datetime time_to_place_trade) { for(int l=0; l<200; l++) { if(od_1[l].choch_index == -1) { od_1[l].choch_index = i; od_1[l].reversal_index = ind; od_1[l].Signal = signal; od_1[l].Time_OF_Candle = time_of_candle; Print("saved time in the structure ",time_of_candle); od_1[l].Time_of_candle_For_trade = time_to_place_trade; Print("saved time in the structure ",time_to_place_trade); break; } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void foo(int value) { for(int i=value; i > 0; i--) { Bos(i); bos2(i); choch(i); third_Condition(i); if(signal == "buy" || signal == "sell") { MqlDateTime edate; time_to_place_trade = 0.0; //print("time of the candle ", time_of_candle); int current_time_frame = Period(); string current_time_frame_string; switch(current_time_frame) { case PERIOD_M1: current_time_frame_string = "1 minute"; break; case PERIOD_M5: current_time_frame_string = "5 minutes"; break; case PERIOD_M15: current_time_frame_string = "15 minutes"; break; case PERIOD_M30: current_time_frame_string = "30 minutes"; break; case PERIOD_H1: current_time_frame_string = "1 hour"; if(TimeToStruct(time_of_candle,edate)) { edate.hour = edate.hour + 2; edate.min = 0; edate.sec = 0; } // print("hour of the candle is ",structtotime(edate)); time_to_place_trade = StructToTime(edate); store_value_in_structure(i,ind,signal,time_of_candle,time_to_place_trade); for(int m=0; m < orderNum; m++) { if(od_1[m].choch_index != -1) { //Print(" time to match the condition : ",TimeCurrent()); if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy") { //Print("time to match the condition : ",TimeCurrent()); 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)) { ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0)); //Print("trade placed buy at index ",0); od_1[m].choch_index = -1; } // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); } if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell") { 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)) { ObjectCreate(0,"sell trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iLow(Symbol(),PERIOD_CURRENT,0)); //Print("trade placed sell at index ",0); od_1[m].choch_index = -1; } //Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); // Print(TimeCurrent()); // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); od_1[m].choch_index = -1; } } } // for(int m=0; m < orderNum; m++) // { // if(od_1[m].choch_index != -1) // { // Print(" time to match the condition : ",TimeCurrent()); // // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy") // { // Print("time to match the condition : ",TimeCurrent()); // // //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)) // { // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0)); // Print("trade placed buy at index ",0); // od_1[m].choch_index = -1; // // } // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); // // // } // // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell") // { // Print(TimeCurrent()); // // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); // od_1[m].choch_index = -1; // // } // } // } // if(timecurrent() >= time_to_place_trade) // { // print("hi"); // if(signal == "buy") // { // int index = ibarshift(symbol(), period_current, time_of_candle, false); // print("index of the 2 hour plus index is ",index); // // print("choch index ", i); // print("reversal index ",ind); // print("value to be check index ",i-3); // // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2)) // // { // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3)); // // print("trade placed buy at index ",i-3); // // } // print(time_to_place_trade); // // } // if(signal == "sell") // { // print("trade placed "); // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3)); // // print(ind); // print(time_to_place_trade); // } // } //else // { // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i); // } break; default: current_time_frame_string = "unknown"; break; } //print("current timeframe: ", current_time_frame_string); signal = ""; } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void foo1(int value) { for(int i=value; i > 0; i--) { //Print("hi"); //if(l < 2) //Bos(i); //choch(i); //third_Condition(i); // if(signal == "buy" || signal == "sell") // { // MqlDateTime edate; // time_to_place_trade = 0.0; // // //print("time of the candle ", time_of_candle); // // int current_time_frame = Period(); // // string current_time_frame_string; // // switch(current_time_frame) // { // // case PERIOD_M1: // current_time_frame_string = "1 minute"; // break; // case PERIOD_M5: // current_time_frame_string = "5 minutes"; // break; // case PERIOD_M15: // current_time_frame_string = "15 minutes"; // break; // case PERIOD_M30: // current_time_frame_string = "30 minutes"; // break; // case PERIOD_H1: // current_time_frame_string = "1 hour"; // // // if(TimeToStruct(time_of_candle,edate)) // { // edate.hour = edate.hour + 2; // edate.min = 0; // edate.sec = 0; // } // // // // print("hour of the candle is ",structtotime(edate)); // time_to_place_trade = StructToTime(edate); // store_value_in_structure(1,ind,signal,time_of_candle,time_to_place_trade); // // // // for(int m=0; m < orderNum; m++) // // { // // if(od_1[m].choch_index != -1) // // { // // Print(" time to match the condition : ",TimeCurrent()); // // // // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy") // // { // // Print("time to match the condition : ",TimeCurrent()); // // // // //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)) // // { // // ObjectCreate(0,"buy trade"+time_to_place_trade,OBJ_ARROW_BUY,0,time_to_place_trade,iHigh(Symbol(),PERIOD_CURRENT,0)); // // Print("trade placed buy at index ",0); // // od_1[m].choch_index = -1; // // // // } // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); // // // // // // } // // // // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell") // // { // // Print(TimeCurrent()); // // // // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); // // od_1[m].choch_index = -1; // // // // } // // } // // } // // // // // if(timecurrent() >= time_to_place_trade) // // { // // print("hi"); // // if(signal == "buy") // // { // // int index = ibarshift(symbol(), period_current, time_of_candle, false); // // print("index of the 2 hour plus index is ",index); // // // // print("choch index ", i); // // print("reversal index ",ind); // // print("value to be check index ",i-3); // // // // //if(ihigh(symbol(),period_current,ind) > ilow(symbol(),period_current,i-2) && iclose(symbol(),period_current,i) < iclose(symbol(),period_current,i-2)) // // // { // // // objectcreate(0,"buy trade"+time_to_place_trade,obj_arrow_buy,0,time_to_place_trade,ihigh(symbol(),period_current,i-3)); // // // print("trade placed buy at index ",i-3); // // // } // // print(time_to_place_trade); // // // // } // // if(signal == "sell") // // { // // print("trade placed "); // // objectcreate(0,"sell trade"+time_to_place_trade,obj_arrow_sell,0,time_to_place_trade,ilow(symbol(),period_current,i-3)); // // // // print(ind); // // print(time_to_place_trade); // // } // // } // //else // // { // // time_of_candle = iTime(Symbol(),PERIOD_CURRENT,i); // // } // // break; // // default: // current_time_frame_string = "unknown"; // break; // } // // //print("current timeframe: ", current_time_frame_string); // // // signal = ""; // } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { int idx = 0; int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT,inpTime, false); if(ObjectCreate(0,"line",OBJ_VLINE,0,inpTime,iLow(Symbol(),PERIOD_CURRENT,user_input_index))) { Print("vertical line created on chart : "); } else { Print("error in creating line : "); } //int user_input_index = iBarShift(Symbol(), PERIOD_CURRENT, D'2022.09.01 15:30:27', false); //if(ObjectCreate(0,"line",OBJ_VLINE,0,D'2022.09.01 15:30:27',iLow(Symbol(),PERIOD_CURRENT,user_input_index))) // { // Print("object created on chart : "); // } //else // { // Print("object not created : "); // } object_find(object_name); if(object_find(object_name) == true) { Print("object found"); // datetime time_of_candle1 = (datetime)ObjectGetInteger(0,"line",OBJPROP_TIME,0); // // index = iBarShift(Symbol(), PERIOD_CURRENT, time_of_candle1, false); // Print("candle is ",checkCandle(user_input_index)); if(checkCandle(user_input_index) == "Bullish") { trend = "uptrend"; high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index); high_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index); // ambiguity high_index = user_input_index; for(int j=user_input_index; j < 1000; j++) { if(checkCandle(j) == "Bearish") { low = iLow(Symbol(),PERIOD_CURRENT,j); idx = j; break; } } idx = iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,idx,user_input_index+1); low = iLow(Symbol(),PERIOD_CURRENT,idx); low_index_time = iTime(Symbol(),PERIOD_CURRENT,idx); low_index = idx; } if(checkCandle(user_input_index) == "Bearish") { trend = "downtrend"; low = iLow(Symbol(),PERIOD_CURRENT,user_input_index); low_index_time = iTime(Symbol(),PERIOD_CURRENT,user_input_index); low_index = user_input_index; for(int j=user_input_index; j < 1000; j++) { if(checkCandle(j) == "Bullish") { // Print("bullish found ",iTime(Symbol(),PERIOD_CURRENT,j)); high = iHigh(Symbol(),PERIOD_CURRENT,j); idx = j; break; } } for(int k=idx; k high) { high = highh; high_index_time = iTime(Symbol(),PERIOD_CURRENT,k); high_index = k; } } } //high = iHigh(Symbol(),PERIOD_CURRENT,user_input_index); //low = iLow(Symbol(),PERIOD_CURRENT,user_input_index); // Print(high); // Print(low); //high_index = user_input_index; //low_index = user_input_index; foo(user_input_index); } else { Print("Object Not Found"); } return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { foo(1); // for(int m=0; m < orderNum; m++) // { // if(od_1[m].choch_index != -1) // { // //Print(" time to match the condition : ",TimeCurrent()); // // if(TimeCurrent() > od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "buy") // { // //Print("time to match the condition : ",TimeCurrent()); // // 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)) // { // ObjectCreate(0,"buy trade"+TimeCurrent(),OBJ_ARROW_BUY,0,TimeCurrent(),iHigh(Symbol(),PERIOD_CURRENT,0)); // Print("trade placed buy at index ",0); // od_1[m].choch_index = -1; // // } // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); // // // } // // if(TimeCurrent() >= od_1[m].Time_of_candle_For_trade && od_1[m].Signal == "sell") // { // Print(TimeCurrent()); // // // // Print(" time to take trade is ",od_1[m].Time_of_candle_For_trade); // od_1[m].choch_index = -1; // // } // } // } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool NewBar() { static datetime Last_bar ; datetime Current_bar = iTime(Symbol(), PERIOD_CURRENT,0); if(Current_bar != Last_bar) { Last_bar = Current_bar; return (true); } else { return (false); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ 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 v) // to check the candle is bullish or bearish { double close = iClose(Symbol(),PERIOD_CURRENT,v); double open = iOpen(Symbol(),PERIOD_CURRENT,v); if(close > open) { return "Bullish"; } else if(close < open) { return "Bearish"; } return "empty"; } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+