| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658 |
- //+------------------------------------------------------------------+
- //| 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 : ",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)
- {
- 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,"bos2");
- 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,"bos2");
- 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);
- //
- //
- //
- // // 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<user_input_index; k++)
- {
- double highh = iHigh(Symbol(),PERIOD_CURRENT,k);
- if(highh > 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";
- }
- //+------------------------------------------------------------------+
- //+------------------------------------------------------------------+
|