Нема описа

valFvgMt5.mq5 25KB

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