暫無描述

valFvgMt5.mq5 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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.1"
  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. input string startHour = "23"; // Start Hour
  87. input string startMin = "59"; // Start Minutes
  88. input string endHour = "00"; // End Hour
  89. input string endMin = "05"; // End Minutes
  90. // Global Variables
  91. int sequential_handler;
  92. datetime startTradingTime = 0, endTradingTime = 0;
  93. string sep = ":"; // A separator as a character
  94. ushort u_sep; // The code of the separator character
  95. string result1[];
  96. //+------------------------------------------------------------------+
  97. //| |
  98. //+------------------------------------------------------------------+
  99. int OnInit()
  100. {
  101. //---
  102. trade.SetExpertMagicNumber(magic_no);
  103. trade.SetDeviationInPoints(10);
  104. trade.SetTypeFilling(ORDER_FILLING_IOC);
  105. trade.LogLevel(LOG_LEVEL_ALL);
  106. trade.SetAsyncMode(false);
  107. sequential_handler = iCustom(Symbol(), PERIOD_CURRENT, "::Indicators\\SequentialVolumeProfileWithFVG.ex5",
  108. BinsCount,
  109. ValueAreaPercent,
  110. VALColor,
  111. VAHColor,
  112. AbsLowColor,
  113. AbsHighColor,
  114. TimeLineColor,
  115. LineWidth,
  116. TimeLineWidth,
  117. MaxDaysBack,
  118. VALStyle,
  119. VAHStyle,
  120. AbsLowStyle,
  121. AbsHighStyle,
  122. ShowLabels,
  123. ShowComment,
  124. ShowFVG,
  125. BullishFVGColor,
  126. BearishFVGColor,
  127. MinFVGSize,
  128. MaxBarsBack,
  129. startHour,
  130. startMin,
  131. endHour,
  132. endMin);
  133. //---
  134. return(INIT_SUCCEEDED);
  135. }
  136. //+------------------------------------------------------------------+
  137. //| Expert deinitialization function |
  138. //+------------------------------------------------------------------+
  139. void OnDeinit(const int reason)
  140. {
  141. //---
  142. Print(" DeInIt ");
  143. ObjectsDeleteAll(0, 0, OBJ_RECTANGLE);
  144. }
  145. //+------------------------------------------------------------------+
  146. //| Expert tick function |
  147. //+------------------------------------------------------------------+
  148. void OnTick()
  149. {
  150. //---
  151. // double values[];
  152. // CopyBuffer(sequential_handler,0,0,3,values);
  153. // Print("Val: ", val, " Vah: ", vah, " AbsHigh: ", absHigh, " AbsLow: ", absLow);
  154. // double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  155. // double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  156. if(newBar())
  157. {
  158. timeConversion();
  159. if((EnableTimeFilter && TimeCurrent() >= startTradingTime && TimeCurrent() < endTradingTime) || !EnableTimeFilter)
  160. {
  161. double val = lines("VAL");
  162. double vah = lines("VAH");
  163. double absHigh = lines("AbsHigh");
  164. double absLow = lines("AbsLow");
  165. string gapCreated = fvg_gap();
  166. if((selectTradeCountOption == one_buy_sell && todayTradesCount(DEAL_TYPE_BUY) == 0) || (selectTradeCountOption == one_trade && todayTradesCount(DEAL_TYPE_BUY) == 0 && todayTradesCount(DEAL_TYPE_SELL) == 0))
  167. {
  168. if(gapCreated == previousBullish)
  169. {
  170. double open_2 = iOpen(Symbol(), PERIOD_CURRENT, 2);
  171. double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
  172. double upper_price = MathMax(open_2, close_2);
  173. double lower_price = MathMin(open_2, close_2);
  174. if(((upper_price > absLow) && (lower_price > absLow)))
  175. if(((upper_price > val) && (lower_price < val)) || ((upper_price < val) && (lower_price < val)))
  176. {
  177. if((selectAbsTouch == single_touch_abs && candleNotTouchingHigh(absLow, buy)) || (selectAbsTouch == both_touch_abs && candleNotTouchingHigh(absLow, buy) && candleNotTouchingHigh(absHigh, sell)) || (selectAbsTouch == disable_abs))
  178. {
  179. Print("Buy Trade. Val: ", val, " Vah: ", vah, " AbsHigh: ", absHigh, " AbsLow: ", absLow);
  180. placeBuyTrade();
  181. }
  182. }
  183. }
  184. }
  185. if((selectTradeCountOption == one_buy_sell && todayTradesCount(DEAL_TYPE_SELL) == 0) || (selectTradeCountOption == one_trade && todayTradesCount(DEAL_TYPE_BUY) == 0 && todayTradesCount(DEAL_TYPE_SELL) == 0))
  186. {
  187. if(gapCreated == previousBearish)
  188. {
  189. double open_2 = iOpen(Symbol(), PERIOD_CURRENT, 2);
  190. double close_2 = iClose(Symbol(), PERIOD_CURRENT, 2);
  191. double upper_price = MathMax(open_2, close_2);
  192. double lower_price = MathMin(open_2, close_2);
  193. if(((upper_price < absHigh) && (lower_price < absHigh)))
  194. if(((upper_price > vah) && (lower_price < vah)) || ((upper_price > vah) && (lower_price > vah)))
  195. {
  196. if((selectAbsTouch == single_touch_abs && candleNotTouchingHigh(absHigh, sell)) || (selectAbsTouch == both_touch_abs && candleNotTouchingHigh(absLow, buy) && candleNotTouchingHigh(absHigh, sell)) || (selectAbsTouch == disable_abs))
  197. {
  198. Print("Sell Trade. Val: ", val, " Vah: ", vah, " AbsHigh: ", absHigh, " AbsLow: ", absLow);
  199. placeSellTrade();
  200. }
  201. }
  202. }
  203. }
  204. }
  205. }
  206. }
  207. //+------------------------------------------------------------------+
  208. //| |
  209. //+------------------------------------------------------------------+
  210. void timeConversion()
  211. {
  212. MqlDateTime date, date1;
  213. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date);
  214. u_sep=StringGetCharacter(sep,0);
  215. StringSplit(startTime,u_sep,result1);
  216. date.hour = (int)StringToInteger(result1[0]);
  217. date.min = (int)StringToInteger(result1[1]);
  218. startTradingTime = StructToTime(date);
  219. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date1);
  220. StringSplit(endTime,u_sep,result1);
  221. date.hour = (int)StringToInteger(result1[0]);
  222. date.min = (int)StringToInteger(result1[1]);
  223. endTradingTime = StructToTime(date);
  224. }
  225. //+------------------------------------------------------------------+
  226. //| |
  227. //+------------------------------------------------------------------+
  228. double lines(string name)
  229. {
  230. datetime todayStart = iTime(Symbol(), PERIOD_D1, 0);
  231. datetime nextDayStart = todayStart + 86400;
  232. datetime latestObjectTime = 0;
  233. for(int i = 0; i < ObjectsTotal(0, 0, OBJ_TREND); i++)
  234. {
  235. string object_name = ObjectName(0, i, 0, OBJ_TREND);
  236. datetime object_time = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 1);
  237. if(object_time > todayStart && object_time < nextDayStart)
  238. {
  239. // Print(" Object Name: ", object_name, " Day Start Time: ", todayStart, " Next Day Time: ", nextDayStart);
  240. if((StringFind(object_name, name) != -1))
  241. {
  242. double objectPrice = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 0);
  243. return objectPrice;
  244. }
  245. }
  246. }
  247. return 0;
  248. }
  249. //+------------------------------------------------------------------+
  250. //| |
  251. //+------------------------------------------------------------------+
  252. bool fvgOverLap(string name, double price_overlap)
  253. {
  254. datetime todayStart = iTime(Symbol(), PERIOD_D1, 0);
  255. datetime nextDayStart = todayStart + 86400;
  256. for(int i = 0; i < ObjectsTotal(0, 0, OBJ_RECTANGLE); i++)
  257. {
  258. string object_name = ObjectName(0, i, 0, OBJ_RECTANGLE);
  259. datetime object_time1 = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 1);
  260. datetime object_time0 = (datetime)ObjectGetInteger(0, object_name, OBJPROP_TIME, 0);
  261. double object_price0 = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 0);
  262. double object_price1 = ObjectGetDouble(0, object_name, OBJPROP_PRICE, 1);
  263. if(object_time1 > todayStart && object_time1 < nextDayStart)
  264. {
  265. if((StringFind(object_name, name) != -1))
  266. {
  267. double fvg_top = MathMax(object_price0, object_price1);
  268. double fvg_bottom = MathMin(object_price0, object_price1);
  269. if(fvg_top > price_overlap && fvg_bottom < price_overlap)
  270. {
  271. Print(" Called By: (", name, ") Object Name: ", object_name,
  272. " | Time 0: ", TimeToString(object_time0), " | Price 0: ", object_price0,
  273. " | Time 1: ", TimeToString(object_time1), " | Price 0: ", object_price0, " | Price 1: ", object_price1, " | \n FVG Top: ", fvg_top, " | FVG Bottom: ", fvg_bottom);
  274. return true;
  275. }
  276. }
  277. }
  278. }
  279. return false;
  280. }
  281. //+------------------------------------------------------------------+
  282. //| |
  283. //+------------------------------------------------------------------+
  284. int todayTradesCount(ENUM_DEAL_TYPE dealType)
  285. {
  286. int count = 0;
  287. ulong ticket_deal_Out=0, ticket_deal_In = 0;
  288. if(HistorySelect(iTime(Symbol(),PERIOD_D1,0), TimeCurrent()))
  289. {
  290. int total = HistoryDealsTotal();
  291. for(int i = total-1; i >= 0 ; i--)
  292. {
  293. ticket_deal_In = HistoryDealGetTicket(i);
  294. if((HistoryDealGetInteger(ticket_deal_In,DEAL_MAGIC) == magic_no) && HistoryDealGetInteger(ticket_deal_In,DEAL_ENTRY) == DEAL_ENTRY_IN
  295. && HistoryDealGetString(ticket_deal_In,DEAL_SYMBOL) == Symbol()) // here is the problem solved after break
  296. {
  297. if(HistoryDealGetInteger(ticket_deal_In, DEAL_TYPE) == dealType)
  298. {
  299. count++;
  300. }
  301. }
  302. }
  303. }
  304. return count;
  305. }
  306. //+------------------------------------------------------------------+
  307. //| |
  308. //+------------------------------------------------------------------+
  309. void placeBuyTrade()
  310. {
  311. double buySL = 0, buyTp=0;
  312. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  313. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  314. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  315. //if(stoploss != 0)
  316. // {
  317. // buySL = Ask - (stoploss * 10 * Point());
  318. // }
  319. if(select_sl == zone_based_sl)
  320. {
  321. buySL = lines("AbsLow");
  322. }
  323. if(select_sl == fvg_third)
  324. {
  325. //if(stoploss != 0)
  326. {
  327. buySL = iLow(Symbol(), PERIOD_CURRENT, 3) - (stoploss * 10 * Point());
  328. }
  329. }
  330. if(select_tp == zone_based)
  331. {
  332. buyTp = lines("VAH");
  333. }
  334. if(select_tp == risk_reward_based)
  335. {
  336. double distance = MathAbs((Ask - buySL) / Point());
  337. distance = (distance * tpMultiplier);
  338. buyTp = Ask + (distance * Point());
  339. }
  340. //if(takeprofit != 0)
  341. // {
  342. // buyTp = Ask + (takeprofit * 10 * Point());
  343. // }
  344. double distance_sl = MathAbs((Ask - buySL) / Point());
  345. if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,getlot(distance_sl),Ask,buySL,buyTp,"Buy Trade Placed"))
  346. {
  347. Print("Buy Trade Placed: ",trade.ResultOrder());
  348. }
  349. else
  350. {
  351. Print("Error in placing Buy: "+Symbol()+" ",GetLastError());
  352. }
  353. }
  354. //+------------------------------------------------------------------+
  355. //| |
  356. //+------------------------------------------------------------------+
  357. void placeSellTrade()
  358. {
  359. double sellSL = 0, sellTp = 0;
  360. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  361. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  362. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  363. //if(stoploss != 0)
  364. // {
  365. // sellSL = Bid + (stoploss * 10 * Point());
  366. // }
  367. if(select_sl == zone_based_sl)
  368. {
  369. sellSL = lines("AbsHigh");
  370. }
  371. if(select_sl == fvg_third)
  372. {
  373. //if(stoploss != 0)
  374. {
  375. sellSL = iHigh(Symbol(), PERIOD_CURRENT, 3) + (stoploss * 10 * Point());
  376. }
  377. }
  378. //if(takeprofit != 0)
  379. // {
  380. // sellTp = Bid - (takeprofit * 10 * Point());
  381. // }
  382. if(select_tp == zone_based)
  383. {
  384. sellTp = lines("VAL");
  385. }
  386. if(select_tp == risk_reward_based)
  387. {
  388. double distance = MathAbs((Bid - sellSL) / Point());
  389. distance = (distance * tpMultiplier);
  390. sellTp = Bid - (distance * Point());
  391. }
  392. double distance_sl = MathAbs((Bid - sellSL) / Point());
  393. if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,getlot(distance_sl),Bid,sellSL,sellTp,"Sell Trade Placed"))
  394. {
  395. Print("Sell Trade PLaced: ",trade.ResultOrder());
  396. }
  397. else
  398. {
  399. Print("Error in placing Sell: "+Symbol()+" ",GetLastError());
  400. }
  401. }
  402. //+------------------------------------------------------------------+
  403. //| |
  404. //+------------------------------------------------------------------+
  405. double getlot(double stop_loss)
  406. {
  407. Print("Tick Value: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE));
  408. Print("Tick Size: ",SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE));
  409. double modeTickV=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)
  410. ,modeTickS=SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE);
  411. // Print("Pip value: ", NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point))*10),2));
  412. double pipvalue = NormalizeDouble(((SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_VALUE)/(SymbolInfoDouble(Symbol(),SYMBOL_TRADE_TICK_SIZE)/Point()))*10),2);
  413. // pipvalue=NormalizeDouble((modeTickV/modeTickS/Point()),)
  414. // pipvalue=
  415. pipvalue = pipvalue / 10;
  416. double lotSize = lot_size;
  417. if(lot_calculator==rsk) //calculating risk
  418. {
  419. double riskamount=(risk/100)*AccountInfoDouble(ACCOUNT_BALANCE);
  420. double pipvalue_required=riskamount/stop_loss;
  421. lotSize = pipvalue_required/pipvalue;
  422. //sl=riskamount/pipValuelot
  423. int roundDigit=0;
  424. double step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);
  425. while(step<1)
  426. {
  427. roundDigit++;
  428. step=step*10;
  429. }
  430. Print("Round Digits:",roundDigit);
  431. lotSize = NormalizeDouble(lotSize,roundDigit);
  432. //
  433. }
  434. Print("Lot Size: ",lotSize);
  435. if(lotSize > SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX))
  436. {
  437. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
  438. }
  439. else
  440. if(lotSize<SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN))
  441. {
  442. lotSize=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
  443. }
  444. //---
  445. return lotSize;
  446. }
  447. //+------------------------------------------------------------------+
  448. //| |
  449. //+------------------------------------------------------------------+
  450. string check_bearish_bullish()
  451. {
  452. int bullishCount = 0;
  453. int bearishCount = 0;
  454. for(int i = 1; i <= 3; i++)
  455. {
  456. double open = iOpen(Symbol(), PERIOD_CURRENT, i);
  457. double close = iClose(Symbol(), PERIOD_CURRENT, i);
  458. if(close > open)
  459. {
  460. bullishCount++;
  461. }
  462. else
  463. if(close < open)
  464. {
  465. bearishCount++;
  466. }
  467. }
  468. // Output the result
  469. if(bullishCount > bearishCount)
  470. {
  471. return previousBullish;
  472. }
  473. else
  474. if(bearishCount > bullishCount)
  475. {
  476. return previousBearish;
  477. }
  478. else
  479. {
  480. return NULL;
  481. }
  482. }
  483. //+------------------------------------------------------------------+
  484. //| |
  485. //+------------------------------------------------------------------+
  486. string fvg_gap()
  487. {
  488. //Print("Imbalance: ");
  489. // if(check_bearish_bullish() == previousBullish)
  490. {
  491. if(iLow(Symbol(), PERIOD_CURRENT, 1) > iHigh(Symbol(), PERIOD_CURRENT, 3))
  492. {
  493. //double fvg_body = imbalance_gap * 10; // FVG Body
  494. double fvg_size = MathAbs((iLow(Symbol(), PERIOD_CURRENT, 1) - iHigh(Symbol(), PERIOD_CURRENT, 3))/Point());
  495. //fvg_size = fvg_size * 10 * Point();
  496. //if(fvg_size > fvg_body)
  497. {
  498. 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)))
  499. {
  500. Print(" Error in Drawing Buy Rectangle : "," rectangle "+(string)iTime(Symbol(),PERIOD_CURRENT,1)," ",GetLastError());
  501. }
  502. else
  503. {
  504. ObjectSetInteger(0, "Buy"+ (string) TimeCurrent(), OBJPROP_COLOR, bullish_color);
  505. ObjectSetInteger(0,"Buy"+ (string) TimeCurrent(), OBJPROP_FILL, true);
  506. //ObjectSetInteger(0,"Range",OBJPROP_BACK,false);
  507. Print("Bullish Fvg Body Size: ", fvg_size, " Name: ", "Buy" + (string) TimeCurrent());
  508. return previousBullish;
  509. }
  510. }
  511. }
  512. }
  513. // if(check_bearish_bullish() == previousBearish)
  514. {
  515. if(iLow(Symbol(), PERIOD_CURRENT, 3) > iHigh(Symbol(), PERIOD_CURRENT, 1))
  516. {
  517. //double fvg_body = imbalance_gap * 10; // FVG Body
  518. double fvg_size = MathAbs((iLow(Symbol(), PERIOD_CURRENT, 3) - iHigh(Symbol(), PERIOD_CURRENT, 1))/Point());
  519. //fvg_size = fvg_size * 10 * Point();
  520. //if(fvg_size > fvg_body)
  521. {
  522. 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)))
  523. {
  524. Print(" Error in Drawing Sell Rectangle : "," rectangle "+(string)iTime(Symbol(),PERIOD_CURRENT,1)," ",GetLastError());
  525. }
  526. else
  527. {
  528. ObjectSetInteger(0, "Sell"+ (string) TimeCurrent(), OBJPROP_COLOR, bearish_color);
  529. ObjectSetInteger(0,"Sell"+ (string) TimeCurrent(), OBJPROP_FILL, true);
  530. //ObjectSetInteger(0,"Range",OBJPROP_BACK,false);
  531. Print("Bearish Fvg Body Size: ", fvg_size, " Name: ", "Buy" + (string) TimeCurrent());
  532. return previousBearish;
  533. }
  534. }
  535. }
  536. }
  537. return NULL;
  538. }
  539. //+------------------------------------------------------------------+
  540. //| |
  541. //+------------------------------------------------------------------+
  542. bool newBar()
  543. {
  544. static datetime lastbar;
  545. datetime curbar = iTime(Symbol(), PERIOD_CURRENT, 0);
  546. if(lastbar != curbar)
  547. {
  548. lastbar = curbar;
  549. Print("<<<<<<<<>>>>>>>>>>>>New Bar Time V1.1. ", curbar, "<<<<<<<<>>>>>>>>>>>>");
  550. return (true);
  551. }
  552. else
  553. {
  554. return (false);
  555. }
  556. }
  557. //+------------------------------------------------------------------+
  558. //| |
  559. //+------------------------------------------------------------------+
  560. bool candleNotTouchingHigh(double priceToBreak, string calledBy)
  561. {
  562. int index = iBarShift(Symbol(), PERIOD_CURRENT, iTime(Symbol(), PERIOD_D1, 0), false);
  563. for(int i = 0; i <= index; i++)
  564. {
  565. if(calledBy == "buy")
  566. {
  567. double low = iLow(Symbol(), PERIOD_CURRENT, i);
  568. if(low < priceToBreak)
  569. return false;
  570. }
  571. else
  572. if(calledBy == "sell")
  573. {
  574. double high = iHigh(Symbol(), PERIOD_CURRENT, i);
  575. if(high > priceToBreak)
  576. return false;
  577. }
  578. }
  579. return true;
  580. }
  581. //+------------------------------------------------------------------+
  582. //| |
  583. //+------------------------------------------------------------------+
  584. //+------------------------------------------------------------------+