No Description

valFvgMt5.mq5 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. //+------------------------------------------------------------------+
  2. //| valFvgMt5.mq5 |
  3. //| Copyright 2025, MQL Development |
  4. //| https://www.mqldevelopment.com/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "Copyright 2025, MQL Development"
  7. #property link "https://www.mqldevelopment.com/"
  8. #property version "1.2"
  9. #include <Trade\Trade.mqh>
  10. CTrade trade;
  11. #resource "\\Indicators\\SequentialVolumeProfileWithFVG.ex5"
  12. #define previousBullish "previousBullish"
  13. #define previousBearish "previousBearish"
  14. #define buy "buy"
  15. #define sell "sell"
  16. //+------------------------------------------------------------------+
  17. //| Expert initialization function |
  18. //+------------------------------------------------------------------+
  19. enum lotcalculator
  20. {
  21. fix, //Fixed Lot Size
  22. rsk, //Risk Percentage
  23. };
  24. enum tp_options
  25. {
  26. zone_based, // Zone Based Tp
  27. risk_reward_based, // Risk to Reward
  28. };
  29. enum sl_options
  30. {
  31. zone_based_sl, // Zone Based Sl
  32. fvg_third, // FVG third candle high and low + buffer
  33. };
  34. enum max_trades_option
  35. {
  36. one_trade, // One Trade
  37. one_buy_sell, // One Buy One Sell
  38. };
  39. enum abs_high_low_touch
  40. {
  41. disable_abs, // Trade Normally
  42. single_touch_abs, // Disable Same Side Trading
  43. both_touch_abs, // Disable Both Side Trading
  44. };
  45. sinput string string_0 = "<><><><><><> General SETTINGS <><><><><><>"; //__
  46. input int magic_no = 333; // Magic no
  47. input tp_options select_tp = zone_based; // Select Tp
  48. input sl_options select_sl = zone_based_sl; // Select Sl
  49. input double stoploss = 4; // FVG Third High/Low Stop Loss in Buffer
  50. input double tpMultiplier = 2; // Take Profit Multiplier Risk to Reward
  51. input max_trades_option selectTradeCountOption = one_trade; // Select Max Trades at a Time
  52. input abs_high_low_touch selectAbsTouch = single_touch_abs;// Action on Absolute Touch
  53. input string string_0_3 = "<><><><><><> Lot Management<><><><><><>"; //__
  54. input double lot_size = 0.1; // Lot Size
  55. input lotcalculator lot_calculator = fix; // Lot Size Calculator
  56. input double risk = 0.1; // Risk in Percentage %
  57. input string time_setting = "<><><><><> Time Filter Settings <><><><><>"; //_
  58. input bool EnableTimeFilter = false; // Enable Time Filter
  59. input string startTime = "03:00"; // Start Time Session
  60. input string endTime = "09:00"; // End Time Session
  61. input string fvg_setting = "<><><><><> FVG Color Setting <><><><><>"; //_
  62. input color bullish_color = clrAqua; // Bullish FVG Color
  63. input color bearish_color = clrYellow; // Bearish FVG Color
  64. sinput string string_1 = "<><><><><><> Sequential Volume Indicator SETTINGS <><><><><><>"; //__
  65. input int BinsCount = 100; // Number of price bins
  66. input double ValueAreaPercent = 70; // Value Area percentage (70% default)
  67. input color VALColor = clrYellow; // Value Area Low color
  68. input color VAHColor = clrYellow; // Value Area High color
  69. input color AbsLowColor = clrDarkOrange; // Absolute Low color
  70. input color AbsHighColor = clrDarkOrange; // Absolute High color
  71. input color TimeLineColor = clrRed; // Time marker line color
  72. input int LineWidth = 2; // Line width for all value lines
  73. input int TimeLineWidth = 2; // Line width for time marker lines
  74. input int MaxDaysBack = 30; // Maximum number of trading days to look back
  75. input ENUM_LINE_STYLE VALStyle = STYLE_SOLID; // Value Area Low line style
  76. input ENUM_LINE_STYLE VAHStyle = STYLE_SOLID; // Value Area High line style
  77. input ENUM_LINE_STYLE AbsLowStyle = STYLE_SOLID; // Absolute Low line style
  78. input ENUM_LINE_STYLE AbsHighStyle = STYLE_SOLID; // Absolute High line style
  79. input bool ShowLabels = true; // Show price labels
  80. input bool ShowComment = true; // Show comment with most recent levels
  81. input bool ShowFVG = false; // Enable Fair Value Gap detection
  82. input color BullishFVGColor = clrLime; // Bullish FVG color
  83. input color BearishFVGColor = clrDeepPink; // Bearish FVG color
  84. input double MinFVGSize = 0.0; // Minimum FVG size in points (0 = any size)
  85. input int MaxBarsBack = 300; // How many bars to look back for FVG
  86. // Global Variables
  87. int sequential_handler;
  88. datetime startTradingTime = 0, endTradingTime = 0;
  89. string sep = ":"; // A separator as a character
  90. ushort u_sep; // The code of the separator character
  91. string result1[];
  92. //+------------------------------------------------------------------+
  93. //| |
  94. //+------------------------------------------------------------------+
  95. int OnInit()
  96. {
  97. //---
  98. trade.SetExpertMagicNumber(magic_no);
  99. trade.SetDeviationInPoints(10);
  100. trade.SetTypeFilling(ORDER_FILLING_IOC);
  101. trade.LogLevel(LOG_LEVEL_ALL);
  102. trade.SetAsyncMode(false);
  103. sequential_handler = iCustom(Symbol(), PERIOD_CURRENT, "::Indicators\\SequentialVolumeProfileWithFVG.ex5",
  104. BinsCount,
  105. ValueAreaPercent,
  106. VALColor,
  107. VAHColor,
  108. AbsLowColor,
  109. AbsHighColor,
  110. TimeLineColor,
  111. LineWidth,
  112. TimeLineWidth,
  113. MaxDaysBack,
  114. VALStyle,
  115. VAHStyle,
  116. AbsLowStyle,
  117. AbsHighStyle,
  118. ShowLabels,
  119. ShowComment,
  120. ShowFVG,
  121. BullishFVGColor,
  122. BearishFVGColor,
  123. MinFVGSize,
  124. MaxBarsBack);
  125. //---
  126. return(INIT_SUCCEEDED);
  127. }
  128. //+------------------------------------------------------------------+
  129. //| Expert deinitialization function |
  130. //+------------------------------------------------------------------+
  131. void OnDeinit(const int reason)
  132. {
  133. //---
  134. Print(" DeInIt ");
  135. ObjectsDeleteAll(0, 0, OBJ_RECTANGLE);
  136. }
  137. //+------------------------------------------------------------------+
  138. //| Expert tick function |
  139. //+------------------------------------------------------------------+
  140. void OnTick()
  141. {
  142. //---
  143. // double values[];
  144. // CopyBuffer(sequential_handler,0,0,3,values);
  145. // Print("Val: ", val, " Vah: ", vah, " AbsHigh: ", absHigh, " AbsLow: ", absLow);
  146. // double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  147. // double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  148. if(newBar())
  149. {
  150. timeConversion();
  151. if((EnableTimeFilter && TimeCurrent() >= startTradingTime && TimeCurrent() < endTradingTime) || !EnableTimeFilter)
  152. {
  153. double val = lines("VAL");
  154. double vah = lines("VAH");
  155. double absHigh = lines("AbsHigh");
  156. double absLow = lines("AbsLow");
  157. string gapCreated = fvg_gap();
  158. if((selectTradeCountOption == one_buy_sell && todayTradesCount(DEAL_TYPE_BUY) == 0) || (selectTradeCountOption == one_trade && todayTradesCount(DEAL_TYPE_BUY) == 0 && todayTradesCount(DEAL_TYPE_SELL) == 0))
  159. {
  160. if(gapCreated == previousBullish)
  161. {
  162. double open_2 = iOpen(Symbol(), PERIOD_CURRENT, 2);
  163. double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
  164. double upper_price = MathMax(open_2, close_2);
  165. double lower_price = MathMin(open_2, close_2);
  166. if(((upper_price > absLow) && (lower_price > absLow)))
  167. if(((upper_price > val) && (lower_price < val)) || ((upper_price < val) && (lower_price < val)))
  168. {
  169. if((selectAbsTouch == single_touch_abs && candleNotTouchingHigh(absLow, buy)) || (selectAbsTouch == both_touch_abs && candleNotTouchingHigh(absLow, buy) && candleNotTouchingHigh(absHigh, sell)) || (selectAbsTouch == disable_abs))
  170. {
  171. Print("Buy Trade. Val: ", val, " Vah: ", vah, " AbsHigh: ", absHigh, " AbsLow: ", absLow);
  172. placeBuyTrade();
  173. }
  174. }
  175. }
  176. }
  177. if((selectTradeCountOption == one_buy_sell && todayTradesCount(DEAL_TYPE_SELL) == 0) || (selectTradeCountOption == one_trade && todayTradesCount(DEAL_TYPE_BUY) == 0 && todayTradesCount(DEAL_TYPE_SELL) == 0))
  178. {
  179. if(gapCreated == previousBearish)
  180. {
  181. double open_2 = iOpen(Symbol(), PERIOD_CURRENT, 2);
  182. double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
  183. double upper_price = MathMax(open_2, close_2);
  184. double lower_price = MathMin(open_2, close_2);
  185. if(((upper_price < absHigh) && (lower_price < absHigh)))
  186. if(((upper_price > vah) && (lower_price < vah)) || ((upper_price > vah) && (lower_price > vah)))
  187. {
  188. if((selectAbsTouch == single_touch_abs && candleNotTouchingHigh(absHigh, sell)) || (selectAbsTouch == both_touch_abs && candleNotTouchingHigh(absLow, buy) && candleNotTouchingHigh(absHigh, sell)) || (selectAbsTouch == disable_abs))
  189. {
  190. Print("Sell Trade. Val: ", val, " Vah: ", vah, " AbsHigh: ", absHigh, " AbsLow: ", absLow);
  191. placeSellTrade();
  192. }
  193. }
  194. }
  195. }
  196. }
  197. }
  198. }
  199. //+------------------------------------------------------------------+
  200. //| |
  201. //+------------------------------------------------------------------+
  202. void timeConversion()
  203. {
  204. MqlDateTime date, date1;
  205. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date);
  206. u_sep=StringGetCharacter(sep,0);
  207. StringSplit(startTime,u_sep,result1);
  208. date.hour = (int)StringToInteger(result1[0]);
  209. date.min = (int)StringToInteger(result1[1]);
  210. startTradingTime = StructToTime(date);
  211. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date1);
  212. StringSplit(endTime,u_sep,result1);
  213. date.hour = (int)StringToInteger(result1[0]);
  214. date.min = (int)StringToInteger(result1[1]);
  215. endTradingTime = StructToTime(date);
  216. }
  217. //+------------------------------------------------------------------+
  218. //| |
  219. //+------------------------------------------------------------------+
  220. double lines(string name)
  221. {
  222. datetime todayStart = iTime(Symbol(), PERIOD_D1, 0);
  223. datetime nextDayStart = todayStart + 86400;
  224. datetime latestObjectTime = 0;
  225. for(int i = 0; i < ObjectsTotal(0, 0, OBJ_TREND); i++)
  226. {
  227. string object_name = ObjectName(0, i, 0, OBJ_TREND);
  228. datetime object_time = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 1);
  229. if(object_time > todayStart && object_time < nextDayStart)
  230. {
  231. // Print(" Object Name: ", object_name, " Day Start Time: ", todayStart, " Next Day Time: ", nextDayStart);
  232. if((StringFind(object_name, name) != -1))
  233. {
  234. double objectPrice = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 0);
  235. return objectPrice;
  236. }
  237. }
  238. }
  239. return 0;
  240. }
  241. //+------------------------------------------------------------------+
  242. //| |
  243. //+------------------------------------------------------------------+
  244. bool fvgOverLap(string name, double price_overlap)
  245. {
  246. datetime todayStart = iTime(Symbol(), PERIOD_D1, 0);
  247. datetime nextDayStart = todayStart + 86400;
  248. for(int i = 0; i < ObjectsTotal(0, 0, OBJ_RECTANGLE); i++)
  249. {
  250. string object_name = ObjectName(0, i, 0, OBJ_RECTANGLE);
  251. datetime object_time1 = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 1);
  252. datetime object_time0 = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 0);
  253. double object_price0 = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 0);
  254. double object_price1 = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 1);
  255. if(object_time1 > todayStart && object_time1 < nextDayStart)
  256. {
  257. if((StringFind(object_name, name) != -1))
  258. {
  259. double fvg_top = MathMax(object_price0, object_price1);
  260. double fvg_bottom = MathMin(object_price0, object_price1);
  261. if(fvg_top > price_overlap && fvg_bottom < price_overlap)
  262. {
  263. Print(" Called By: (", name, ") Object Name: ", object_name,
  264. " | Time 0: ", TimeToString(object_time0), " | Price 0: ", object_price0,
  265. " | Time 1: ", TimeToString(object_time1), " | Price 0: ", object_price0, " | Price 1: ", object_price1, " | \n FVG Top: ", fvg_top, " | FVG Bottom: ", fvg_bottom);
  266. return true;
  267. }
  268. }
  269. }
  270. }
  271. return false;
  272. }
  273. //+------------------------------------------------------------------+
  274. //| |
  275. //+------------------------------------------------------------------+
  276. int todayTradesCount(ENUM_DEAL_TYPE dealType)
  277. {
  278. int count = 0;
  279. ulong ticket_deal_Out=0, ticket_deal_In = 0;
  280. if(HistorySelect(iTime(Symbol(),PERIOD_D1,0), TimeCurrent()))
  281. {
  282. int total = HistoryDealsTotal();
  283. for(int i = total-1; i >= 0 ; i--)
  284. {
  285. ticket_deal_In = HistoryDealGetTicket(i);
  286. if((HistoryDealGetInteger(ticket_deal_In,DEAL_MAGIC) == magic_no) && HistoryDealGetInteger(ticket_deal_In,DEAL_ENTRY) == DEAL_ENTRY_IN
  287. && HistoryDealGetString(ticket_deal_In,DEAL_SYMBOL) == Symbol()) // here is the problem solved after break
  288. {
  289. if(HistoryDealGetInteger(ticket_deal_In, DEAL_TYPE) == dealType)
  290. {
  291. count++;
  292. }
  293. }
  294. }
  295. }
  296. return count;
  297. }
  298. //+------------------------------------------------------------------+
  299. //| |
  300. //+------------------------------------------------------------------+
  301. void placeBuyTrade()
  302. {
  303. double buySL = 0, buyTp=0;
  304. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  305. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  306. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  307. //if(stoploss != 0)
  308. // {
  309. // buySL = Ask - (stoploss * 10 * Point());
  310. // }
  311. if(select_sl == zone_based_sl)
  312. {
  313. buySL = lines("AbsLow");
  314. }
  315. if(select_sl == fvg_third)
  316. {
  317. //if(stoploss != 0)
  318. {
  319. buySL = iLow(Symbol(), PERIOD_CURRENT, 3) - (stoploss * 10 * Point());
  320. }
  321. }
  322. if(select_tp == zone_based)
  323. {
  324. buyTp = lines("VAH");
  325. }
  326. if(select_tp == risk_reward_based)
  327. {
  328. double distance = MathAbs((Ask - buySL) / Point());
  329. distance = (distance * tpMultiplier);
  330. buyTp = Ask + (distance * Point());
  331. }
  332. //if(takeprofit != 0)
  333. // {
  334. // buyTp = Ask + (takeprofit * 10 * Point());
  335. // }
  336. double distance_sl = MathAbs((Ask - buySL) / Point());
  337. if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getlot(distance_sl),Ask,buySL,buyTp,"Buy Trade Placed"))
  338. {
  339. Print("Buy Trade Placed: ",trade.ResultOrder());
  340. }
  341. else
  342. {
  343. Print("Error in placing Buy: "+Symbol()+" ",GetLastError());
  344. }
  345. }
  346. //+------------------------------------------------------------------+
  347. //| |
  348. //+------------------------------------------------------------------+
  349. void placeSellTrade()
  350. {
  351. double sellSL = 0, sellTp = 0;
  352. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  353. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  354. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  355. //if(stoploss != 0)
  356. // {
  357. // sellSL = Bid + (stoploss * 10 * Point());
  358. // }
  359. if(select_sl == zone_based_sl)
  360. {
  361. sellSL = lines("AbsHigh");
  362. }
  363. if(select_sl == fvg_third)
  364. {
  365. //if(stoploss != 0)
  366. {
  367. sellSL = iHigh(Symbol(), PERIOD_CURRENT, 3) + (stoploss * 10 * Point());
  368. }
  369. }
  370. //if(takeprofit != 0)
  371. // {
  372. // sellTp = Bid - (takeprofit * 10 * Point());
  373. // }
  374. if(select_tp == zone_based)
  375. {
  376. sellTp = lines("VAL");
  377. }
  378. if(select_tp == risk_reward_based)
  379. {
  380. double distance = MathAbs((Bid - sellSL) / Point());
  381. distance = (distance * tpMultiplier);
  382. sellTp = Bid - (distance * Point());
  383. }
  384. double distance_sl = MathAbs((Bid - sellSL) / Point());
  385. if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getlot(distance_sl),Bid,sellSL,sellTp,"Sell Trade Placed"))
  386. {
  387. Print("Sell Trade PLaced: ",trade.ResultOrder());
  388. }
  389. else
  390. {
  391. Print("Error in placing Sell: "+Symbol()+" ",GetLastError());
  392. }
  393. }
  394. //+------------------------------------------------------------------+
  395. //| |
  396. //+------------------------------------------------------------------+
  397. double getlot(double stop_loss)
  398. {
  399. Print("Tick Value: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
  400. Print("Tick Size: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE));
  401. double modeTickV=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)
  402. ,modeTickS=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
  403. // Print("Pip value: ", NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point))*10),2));
  404. double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
  405. // pipvalue=NormalizeDouble((modeTickV/modeTickS/Point()),)
  406. // pipvalue=
  407. pipvalue = pipvalue / 10;
  408. double lotSize = lot_size;
  409. if(lot_calculator==rsk) //calculating risk
  410. {
  411. double riskamount=(risk/100)*AccountInfoDouble(ACCOUNT_BALANCE);
  412. double pipvalue_required=riskamount/stop_loss;
  413. lotSize = pipvalue_required/pipvalue;
  414. //sl=riskamount/pipValuelot
  415. int roundDigit=0;
  416. double step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
  417. while(step<1)
  418. {
  419. roundDigit++;
  420. step=step*10;
  421. }
  422. Print("Round Digits:",roundDigit);
  423. lotSize = NormalizeDouble(lotSize,roundDigit);
  424. //
  425. }
  426. Print("Lot Size: ",lotSize);
  427. if(lotSize > SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX))
  428. {
  429. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
  430. }
  431. else
  432. if(lotSize<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
  433. {
  434. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  435. }
  436. //---
  437. return lotSize;
  438. }
  439. //+------------------------------------------------------------------+
  440. //| |
  441. //+------------------------------------------------------------------+
  442. string check_bearish_bullish()
  443. {
  444. int bullishCount = 0;
  445. int bearishCount = 0;
  446. for(int i = 1; i <= 3; i++)
  447. {
  448. double open = iOpen(Symbol(), PERIOD_CURRENT, i);
  449. double close = iClose(Symbol(), PERIOD_CURRENT, i);
  450. if(close > open)
  451. {
  452. bullishCount++;
  453. }
  454. else
  455. if(close < open)
  456. {
  457. bearishCount++;
  458. }
  459. }
  460. // Output the result
  461. if(bullishCount > bearishCount)
  462. {
  463. return previousBullish;
  464. }
  465. else
  466. if(bearishCount > bullishCount)
  467. {
  468. return previousBearish;
  469. }
  470. else
  471. {
  472. return NULL;
  473. }
  474. }
  475. //+------------------------------------------------------------------+
  476. //| |
  477. //+------------------------------------------------------------------+
  478. string fvg_gap()
  479. {
  480. //Print("Imbalance: ");
  481. // if(check_bearish_bullish() == previousBullish)
  482. {
  483. if(iLow(Symbol(), PERIOD_CURRENT, 1) > iHigh(Symbol(), PERIOD_CURRENT, 3))
  484. {
  485. //double fvg_body = imbalance_gap * 10; // FVG Body
  486. double fvg_size = MathAbs((iLow(Symbol(), PERIOD_CURRENT, 1) - iHigh(Symbol(), PERIOD_CURRENT, 3))/Point());
  487. //fvg_size = fvg_size * 10 * Point();
  488. //if(fvg_size > fvg_body)
  489. {
  490. if(!ObjectCreate(0, "Buy" + (string) TimeCurrent(), OBJ_RECTANGLE, 0, iTime(Symbol(), PERIOD_CURRENT, 3), iHigh(Symbol(), PERIOD_CURRENT, 3), iTime(Symbol(), PERIOD_CURRENT, 1), iLow(Symbol(), PERIOD_CURRENT, 1)))
  491. {
  492. Print(" Error in Drawing Buy Rectangle : "," rectangle "+(string)iTime(Symbol(),PERIOD_CURRENT,1)," ",GetLastError());
  493. }
  494. else
  495. {
  496. ObjectSetInteger(0, "Buy"+ (string) TimeCurrent(), OBJPROP_COLOR, bullish_color);
  497. ObjectSetInteger(0,"Buy"+ (string) TimeCurrent(), OBJPROP_FILL, true);
  498. //ObjectSetInteger(0,"Range",OBJPROP_BACK,false);
  499. Print("Bullish Fvg Body Size: ", fvg_size, " Name: ", "Buy" + (string) TimeCurrent());
  500. return previousBullish;
  501. }
  502. }
  503. }
  504. }
  505. // if(check_bearish_bullish() == previousBearish)
  506. {
  507. if(iLow(Symbol(), PERIOD_CURRENT, 3) > iHigh(Symbol(), PERIOD_CURRENT, 1))
  508. {
  509. //double fvg_body = imbalance_gap * 10; // FVG Body
  510. double fvg_size = MathAbs((iLow(Symbol(), PERIOD_CURRENT, 3) - iHigh(Symbol(), PERIOD_CURRENT, 1))/Point());
  511. //fvg_size = fvg_size * 10 * Point();
  512. //if(fvg_size > fvg_body)
  513. {
  514. if(!ObjectCreate(0, "Sell" + (string) TimeCurrent(), OBJ_RECTANGLE, 0, iTime(Symbol(), PERIOD_CURRENT, 3), iLow(Symbol(), PERIOD_CURRENT, 3), iTime(Symbol(), PERIOD_CURRENT, 1), iHigh(Symbol(), PERIOD_CURRENT, 1)))
  515. {
  516. Print(" Error in Drawing Sell Rectangle : "," rectangle "+(string)iTime(Symbol(),PERIOD_CURRENT,1)," ",GetLastError());
  517. }
  518. else
  519. {
  520. ObjectSetInteger(0, "Sell"+ (string) TimeCurrent(), OBJPROP_COLOR, bearish_color);
  521. ObjectSetInteger(0,"Sell"+ (string) TimeCurrent(), OBJPROP_FILL, true);
  522. //ObjectSetInteger(0,"Range",OBJPROP_BACK,false);
  523. Print("Bearish Fvg Body Size: ", fvg_size, " Name: ", "Buy" + (string) TimeCurrent());
  524. return previousBearish;
  525. }
  526. }
  527. }
  528. }
  529. return NULL;
  530. }
  531. //+------------------------------------------------------------------+
  532. //| |
  533. //+------------------------------------------------------------------+
  534. bool newBar()
  535. {
  536. static datetime lastbar;
  537. datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
  538. if(lastbar != curbar)
  539. {
  540. lastbar = curbar;
  541. Print("<<<<<<<<>>>>>>>>>>>>New Bar Time V1.1. ", curbar, "<<<<<<<<>>>>>>>>>>>>");
  542. return (true);
  543. }
  544. else
  545. {
  546. return (false);
  547. }
  548. }
  549. //+------------------------------------------------------------------+
  550. //| |
  551. //+------------------------------------------------------------------+
  552. bool candleNotTouchingHigh(double priceToBreak, string calledBy)
  553. {
  554. int index = iBarShift(Symbol(), PERIOD_CURRENT, iTime(Symbol(), PERIOD_D1, 0), false);
  555. for(int i = 0; i <= index; i++)
  556. {
  557. if(calledBy == "buy")
  558. {
  559. double low = iLow(Symbol(), PERIOD_CURRENT, i);
  560. if(low < priceToBreak)
  561. return false;
  562. }
  563. else
  564. if(calledBy == "sell")
  565. {
  566. double high = iHigh(Symbol(), PERIOD_CURRENT, i);
  567. if(high > priceToBreak)
  568. return false;
  569. }
  570. }
  571. return true;
  572. }
  573. //+------------------------------------------------------------------+
  574. //| |
  575. //+------------------------------------------------------------------+
  576. //+------------------------------------------------------------------+