//+------------------------------------------------------------------+ //| 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 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 = 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) { 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); 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") { 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) { 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); //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") { 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 : ",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 : ",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) { 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); //Print("last bos index is ",Store_bos_last_index); // int diff1 = Store_bos_last_index - (i); // store_last_bos_index_time // Print("last boss index is ",Store_bos_last_index); // // 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); Print("low update due to choch : ", low); trend = "downtrend"; Print("choch at uptrend index --- ", iTime(Symbol(),PERIOD_CURRENT,i)); } } if(trend == "downtrend") { double close = iClose(Symbol(),PERIOD_CURRENT,i); if(close > high) { 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); // int diff = Store_bos_last_index - (i); // Print("last boss index ia ",Store_bos_last_index); // // 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)); } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void third_Condition(int i) { if(trend == "uptrend") { low2 = iLow(Symbol(),PERIOD_CURRENT,i); high2 = iHigh(Symbol(),PERIOD_CURRENT,i); if(low2 < low) { //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) { //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) { //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) { //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--) { //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); // 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 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 12:30:27', false); //if(ObjectCreate(0,"line",OBJ_VLINE,0,D'2022.09.01 12: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"; } if(checkCandle(user_input_index) == "Bearish") { trend = "downtrend"; } 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; Print("index is : ",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() { foo1(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"; } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+