| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608 |
- //+------------------------------------------------------------------+
- //| 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)
- {
- int save_bullish_index = 0;
- int save_bearish_index = 0;
- if(trend == "uptrend")
- {
- high1 = iHigh(Symbol(),PERIOD_CURRENT,i);
- double close = iClose(Symbol(),PERIOD_CURRENT,i);
- if(close > high)
- {
- high_index = iBarShift(Symbol(), PERIOD_CURRENT, high_index_time, false);
- for(int j=high_index-1; j > i; j--)
- {
- if(checkCandle(j) == "Bearish")
- {
- save_bullish_index = j;
- if(object_find("high") > 0)
- {
- ObjectDelete(0,"high");
- }
- high = high1;
- 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);
- Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
- low = iLow(Symbol(),PERIOD_CURRENT,j);
- bearish_found = true;
- index_of_low_time = iTime(Symbol(),PERIOD_CURRENT,j);
- break;
- }
- }
- if(bearish_found == true)
- {
- for(int k=save_bullish_index; k > i ; k--)
- {
- low1 = iLow(Symbol(),PERIOD_CURRENT,k);
- if(low1 < low)
- {
- low = low1;
- index_of_low_time = iTime(Symbol(),PERIOD_CURRENT,k);
- 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);
- }
- high_index_time = iTime(Symbol(),PERIOD_CURRENT,i);
- }
- }
- if(trend == "downtrend")
- {
- low1 = iLow(Symbol(),PERIOD_CURRENT,i);
- double close1 = iClose(Symbol(),PERIOD_CURRENT,i);
- if(close1 < low)
- {
- low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
- for(int j=low_index - 1; j > i; j--)
- {
- if(checkCandle(j) == "Bullish")
- {
- save_bullish_index = j;
- 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);
- Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
- low_index = iBarShift(Symbol(), PERIOD_CURRENT, low_index_time, false);
- high = iHigh(Symbol(),PERIOD_CURRENT,j);
- bullish_found = true;
- index_of_high_time = iTime(Symbol(),PERIOD_CURRENT,j);
- break;
- }
- }
- if(bullish_found == true)
- {
- for(int k=save_bullish_index; k > i ; k--)
- {
- high1 = iHigh(Symbol(),PERIOD_CURRENT,k);
- if(high1 > high)
- {
- high = high1;
- index_of_high_time = iTime(Symbol(),PERIOD_CURRENT,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;
- }
- 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;
- int save_bullish_index = 0;
- int save_bearish_index = 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")
- {
- save_bullish_index = m;
- candle_bullish = true;
- break;
- }
- }
- find_high = iHigh(Symbol(),PERIOD_CURRENT,save_bullish_index);
- for(int m=save_bullish_index; m>i; m--)
- {
- double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,m);
- find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
- if(find_high < find_high1)
- {
- find_high = find_high1;
- find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
- }
- }
- for(int j=choch_index; j>=i; 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")
- {
- save_bullish_index = m;
- candle_bullish = true;
- break;
- }
- }
- find_high = iHigh(Symbol(),PERIOD_CURRENT,save_bullish_index);
- for(int m=save_bullish_index; m>i; m--)
- {
- double find_high1 = iHigh(Symbol(),PERIOD_CURRENT,m);
- find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
- if(find_high < find_high1)
- {
- find_high = find_high1;
- find_high_time = iTime(Symbol(),PERIOD_CURRENT,m);
- }
- }
- for(int j=Store_bos_last_index; j>=i; 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);
- Print("time is ----------------------",find_high_time);
- 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;
- save_bearish_index = m;
- break;
- }
- }
- find_low = iLow(Symbol(),PERIOD_CURRENT,save_bearish_index);
- for(int m=save_bearish_index; m>i; m--)
- {
- double find_low1 = iLow(Symbol(),PERIOD_CURRENT,m);
- find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
- if(find_low > find_low1)
- {
- find_low = find_low1;
- find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
- }
- }
- for(int j=Store_bos_last_index; j>=i; 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;
- save_bearish_index = m;
- break;
- }
- }
- find_low = iLow(Symbol(),PERIOD_CURRENT,save_bearish_index);
- for(int m=save_bearish_index; m>i; m--)
- {
- double find_low1 = iLow(Symbol(),PERIOD_CURRENT,m);
- find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
- if(find_low > find_low1)
- {
- find_low = find_low1;
- find_low_time = iTime(Symbol(),PERIOD_CURRENT,m);
- }
- }
- for(int j=choch_index; j>=i; 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<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";
- }
- //+------------------------------------------------------------------+
- //+------------------------------------------------------------------+
|