| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585 |
- //+------------------------------------------------------------------+
- //| 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;
- 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);
- 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")
- {
- candle_bullish = true;
- }
- }
- Store_bos_last_index = iBarShift(Symbol(), PERIOD_CURRENT, store_last_bos_index_time, false);
- 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)
- {
- 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;
- }
- }
- 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;
- }
- }
- 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)
- {
- 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);
- //
- //
- //
- // // 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";
- }
- //+------------------------------------------------------------------+
- //+------------------------------------------------------------------+
|