Geen omschrijving

valFvgMt5.mq5 24KB

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