暫無描述

line_level_ea.mq5 51KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. //+------------------------------------------------------------------+
  2. //| line_level_ea.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. enum tradeType
  12. {
  13. buyTrades, // Buy
  14. sellTrades, // Sell
  15. };
  16. enum NewsCloseOrder
  17. {
  18. CloseAllRunningOrder=0,
  19. LetTheOrderRun=1,
  20. };
  21. enum selectLine
  22. {
  23. LineOnNewsBar =0,
  24. LineOnNewsStop=1
  25. };
  26. #import "line_level_news_filter.ex5"
  27. //+------------------------------------------------------------------+
  28. //| |
  29. //+------------------------------------------------------------------+
  30. void initiateNews();
  31. int returnNewsStatus(bool High_Impact_News=true
  32. ,int High_Start_Time=60//Stop Trade before high News (min)
  33. ,int High_Stop_Time=15 //Stop Trade after high News (min)
  34. ,bool show_high_line=true//Show verticle Line when high news comes
  35. ,bool Medium_Impact_News=true
  36. ,int Medium_Start_Time=60//Stop Trade before medium News (min)
  37. ,int Medium_Stop_Time=15 //Stop Trade after medium News (min)
  38. ,bool show_medium_line=true//Show verticle Line when medium news comes
  39. ,bool Low_Impact_News=true
  40. ,int Low_Start_Time=60//Stop Trade before low News (min)
  41. ,int Low_Stop_Time=15 //Stop Trade after low News (min)
  42. ,bool show_low_line=true//Show verticle Line when low news comes
  43. ,string symbol=""
  44. ,string expert=""
  45. ,int GMT_Broker_Time=2
  46. ,selectLine sl=0
  47. ,string extraSymbol=""
  48. );
  49. #import
  50. input string string_0 = "<><><><><><> General SETTINGS <><><><><><>"; //__
  51. input int magic_no = 333; // Magic no
  52. input tradeType selectSide = buyTrades; // Select Side
  53. input double lot_size = 0.1; // Lot Size
  54. input double lot_multiplier = 2; // Lot Multiplier on Loss Trade
  55. input double levels_distence = 10; // Levels Distance in Dollars
  56. input double stoploss = 10; // Fixed Stop Loss in Pips
  57. input double takeprofit = 10; // Fixed Take Profit in Pips
  58. input bool countinueCycleAfterProfit = true; // Continue Trading After Profit
  59. input string time_setting = "<><><><><> Time Filter Settings <><><><><>"; //_
  60. input bool EnableTimeFilter = false; // Enable Time Filter
  61. input string startTime = "03:00"; // Start Time Session
  62. input string endTime = "09:00"; // End Time Session
  63. input string news = "<><><><><><> News Settings <><><><><><>"; // News
  64. input NewsCloseOrder newsClose = CloseAllRunningOrder; // On News Action on Running Orders
  65. input bool High_Impact_News = true; //High Impact News
  66. input int High_Start_Time = 60; //Stop Trade before high News (min)
  67. input int High_Stop_Time = 15; //Stop Trade after high News (min)
  68. input bool show_high_line = true; //Show verticle Line when high news comes
  69. input bool Medium_Impact_News = true; //Medium Impact News
  70. input int Medium_Start_Time = 60; //Stop Trade before medium News (min)
  71. input int Medium_Stop_Time = 15; //Stop Trade after medium News (min)
  72. input bool show_medium_line = true; //Show verticle Line when medium news comes
  73. input bool Low_Impact_News = true; //Low Impact News
  74. input int Low_Start_Time = 60; //Stop Trade before low News (min)
  75. input int Low_Stop_Time = 15; //Stop Trade after low News (min)
  76. input bool show_low_line = true; //Show verticle Line when low news comes
  77. input selectLine Select_News_Line = 0; //News Line
  78. input bool mobileAlert = true; //Mobile Alert
  79. int GMT_Broker_Time = +2; //GMT_Broker_Time Time of your Broker
  80. // Global Variables
  81. double above_level = 0, below_level = 0;
  82. static double tickCurrentBid = 0, tickCurrentAsk = 0;
  83. double tickPreviousBid = 0, tickPreviousAsk = 0;
  84. datetime startTradingTime = 0, endTradingTime = 0;
  85. string sep = ":"; // A separator as a character
  86. ushort u_sep; // The code of the separator character
  87. string result1[];
  88. datetime ea_start_time = 0;
  89. bool tradeNow = true;
  90. bool printingDisplay = true;
  91. string Lname="newsLabel3";
  92. //+------------------------------------------------------------------+
  93. //| Expert initialization function |
  94. //+------------------------------------------------------------------+
  95. int OnInit()
  96. {
  97. //---
  98. // news
  99. int timeDifference = (int)TimeCurrent() - (int)TimeGMT();
  100. Print("Time Difference is: ", timeDifference);
  101. if(timeDifference > 0)
  102. {
  103. GMT_Broker_Time = +timeDifference/3600;
  104. }
  105. else
  106. if(timeDifference < 0)
  107. {
  108. GMT_Broker_Time = timeDifference/3600;
  109. }
  110. else
  111. if(timeDifference == 0)
  112. {
  113. GMT_Broker_Time = timeDifference;
  114. }
  115. Print("Gmt Time: ", TimeGMT(), " Broker Gmt Time: ", GMT_Broker_Time);
  116. if(!MQLInfoInteger(MQL_TESTER))
  117. {
  118. initiateNews();
  119. }
  120. // Fill Values above and below levels
  121. trade.SetExpertMagicNumber(magic_no);
  122. trade.SetDeviationInPoints(10);
  123. trade.SetTypeFilling(ORDER_FILLING_IOC);
  124. trade.LogLevel(LOG_LEVEL_ALL);
  125. trade.SetAsyncMode(false);
  126. ea_start_time = TimeCurrent();
  127. double currentPrice = iClose(Symbol(), PERIOD_CURRENT, 0);
  128. getNearestLevels(currentPrice, levels_distence, below_level, above_level);
  129. //---
  130. return(INIT_SUCCEEDED);
  131. }
  132. //+------------------------------------------------------------------+
  133. //| Expert deinitialization function |
  134. //+------------------------------------------------------------------+
  135. void OnDeinit(const int reason)
  136. {
  137. //---
  138. }
  139. //+------------------------------------------------------------------+
  140. //| Main Activity function |
  141. //+------------------------------------------------------------------+
  142. void mainActivity()
  143. {
  144. //---
  145. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  146. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  147. tickPreviousBid = tickCurrentBid;
  148. tickCurrentBid = Bid;
  149. tickPreviousAsk = tickCurrentAsk;
  150. tickCurrentAsk = Ask;
  151. timeConversion();
  152. // Comment(" Below Value is: ", below_level, " Above Value: ", above_level, " Previous Tick: ", tickPreviousAsk, " Tick Current Ask: ", tickCurrentAsk);
  153. double lastLot = 0;
  154. if(!countinueCycleAfterProfit)
  155. if(selectLatestTicket(lastLot) > 0)
  156. {
  157. tradeNow = false;
  158. }
  159. // Comment(" Trades Count: ", orderCount(), " Below Value is: ", below_level, " Above Value: ", above_level);
  160. if(orderCount() == 0)
  161. {
  162. double latestClosePrice = getClosePriceByTicket();
  163. if(latestClosePrice > 0)
  164. {
  165. getNearestLevels(latestClosePrice, levels_distence, below_level, above_level);
  166. if(printingDisplay)
  167. {
  168. Print(" ---------------------------------- Resetting Level no trade open. Setting new Levels using last ticket close price: ", latestClosePrice, " ------------------------------------------------ ");
  169. Print(" Current Price: ", latestClosePrice, " Below Value is: ", below_level, " Above Value: ", above_level);
  170. printingDisplay = false;
  171. }
  172. }
  173. }
  174. else
  175. {
  176. printingDisplay = true;
  177. }
  178. if(tradeNow)
  179. if((EnableTimeFilter && TimeCurrent() >= startTradingTime && TimeCurrent() < endTradingTime) || !EnableTimeFilter)
  180. {
  181. if(above_level == 0 && below_level == 0)
  182. {
  183. double currentPrice = iClose(Symbol(), PERIOD_CURRENT, 0);
  184. getNearestLevels(currentPrice, levels_distence, below_level, above_level);
  185. Print(" Price Levels Updated on New Session Start. ");
  186. }
  187. if(selectSide == buyTrades) // Buy trade case
  188. {
  189. if(((tickPreviousAsk < above_level) && (tickCurrentAsk >= above_level)) ||
  190. ((tickPreviousAsk > below_level) && (tickCurrentAsk <= below_level)))
  191. {
  192. placeBuyTrade();
  193. Print(" ----------------------------- Buy Trade Executed and Levels Updated -----------------------------------------------------");
  194. double currentPrice = 0;
  195. if((tickPreviousAsk < above_level) && (tickCurrentAsk >= above_level))
  196. {
  197. currentPrice = above_level;
  198. }
  199. else
  200. if(((tickPreviousAsk > below_level) && (tickCurrentAsk <= below_level)))
  201. {
  202. currentPrice = below_level;
  203. }
  204. getNearestLevels(currentPrice, levels_distence, below_level, above_level);
  205. Print(" Current Price: ", currentPrice, " Below Value is: ", below_level, " Above Value: ", above_level);
  206. }
  207. }
  208. if(selectSide == sellTrades)
  209. {
  210. if(((tickPreviousBid < above_level) && (tickCurrentBid >= above_level)) ||
  211. ((tickPreviousBid > below_level) && (tickCurrentBid <= below_level)))
  212. {
  213. placeSellTrade();
  214. Print(" ----------------------------- Sell Trade Executed and Levels Updated -----------------------------------------------------");
  215. double currentPrice = 0;
  216. if((tickPreviousBid < above_level) && (tickCurrentBid >= above_level))
  217. {
  218. currentPrice = above_level;
  219. }
  220. else
  221. if(((tickPreviousBid > below_level) && (tickCurrentBid <= below_level)))
  222. {
  223. currentPrice = below_level;
  224. }
  225. getNearestLevels(currentPrice, levels_distence, below_level, above_level);
  226. Print(" Current Price: ", currentPrice, " Below Value: ", below_level, " Above Value: ", above_level);
  227. }
  228. }
  229. }
  230. else
  231. {
  232. below_level = 0;
  233. above_level = 0;
  234. }
  235. }
  236. //+------------------------------------------------------------------+
  237. //| Expert tick function |
  238. //+------------------------------------------------------------------+
  239. void OnTick()
  240. {
  241. static int status=-1,preStatus=-1;
  242. status=returnNewsStatus(High_Impact_News
  243. ,High_Start_Time
  244. ,High_Stop_Time
  245. ,show_high_line
  246. ,Medium_Impact_News
  247. ,Medium_Start_Time
  248. ,Medium_Stop_Time
  249. ,show_medium_line
  250. ,Low_Impact_News
  251. ,Low_Start_Time
  252. ,Low_Stop_Time
  253. ,show_low_line
  254. ,Symbol()
  255. ,MQLInfoString(MQL_PROGRAM_NAME)
  256. ,GMT_Broker_Time
  257. ,Select_News_Line
  258. ,""
  259. );
  260. if(status==0)
  261. {
  262. mainActivity();
  263. }
  264. if(status==1 || status==2 || status==3)
  265. {
  266. if(newsClose==0)
  267. {
  268. if(orderCount_1(POSITION_TYPE_BUY,magic_no)>0)
  269. closeTrades(POSITION_TYPE_BUY,magic_no);
  270. if(orderCount_1(POSITION_TYPE_SELL,magic_no)>0)
  271. closeTrades(POSITION_TYPE_SELL,magic_no);
  272. }
  273. else
  274. if(newsClose==1)
  275. {
  276. mainActivity();
  277. }
  278. }
  279. if(status!=preStatus)
  280. {
  281. if(status==0 && preStatus!=-1)
  282. {
  283. {
  284. ObjectSetString(0,Lname,OBJPROP_TEXT,"");
  285. }
  286. Alert("Trading is start");
  287. if(mobileAlert)
  288. SendNotification("Trading is start");
  289. preStatus=status;
  290. }
  291. else
  292. if(status==1)
  293. {
  294. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrRed);
  295. ObjectSetString(0,Lname,OBJPROP_TEXT,"High Impact News");
  296. Alert("Trading Stop due to high impact news");
  297. if(mobileAlert)
  298. SendNotification("Trading Stop due to high impact news");
  299. preStatus=status;
  300. }
  301. else
  302. if(status==2)
  303. {
  304. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrBlue);
  305. ObjectSetString(0,Lname,OBJPROP_TEXT,"Medium Impact News");
  306. Alert("Trading Stop due to medium impact news");
  307. if(mobileAlert)
  308. SendNotification("Trading Stop due to medium impact news");
  309. preStatus=status;
  310. }
  311. else
  312. if(status==3)
  313. {
  314. ObjectSetInteger(0,Lname,OBJPROP_COLOR,clrGreen);
  315. ObjectSetString(0,Lname,OBJPROP_TEXT,"Low Impact News");
  316. Alert("Trading Stop due to low impact news");
  317. if(mobileAlert)
  318. SendNotification("Trading Stop due to low impact news");
  319. preStatus=status;
  320. }
  321. }
  322. else
  323. mainActivity();
  324. }
  325. //+------------------------------------------------------------------+
  326. //| Calculate Base Level Function |
  327. //+------------------------------------------------------------------+
  328. double calculateBaseLevel(double price, double step)
  329. {
  330. return step * MathFloor(price / step);
  331. }
  332. //+------------------------------------------------------------------+
  333. //| Get Nearest Levels Function |
  334. //+------------------------------------------------------------------+
  335. void getNearestLevels(double currentPrice, double step,
  336. double &LowerLevel, double &UpperLevel)
  337. {
  338. double epsilon = 0.000001;
  339. // Compute the anchor as the nearest multiple of step.
  340. double anchor = MathRound(currentPrice / step) * step;
  341. double diff = fabs(currentPrice - anchor);
  342. // If currentPrice exactly equals the anchor, use symmetric levels.
  343. if(diff < epsilon)
  344. {
  345. LowerLevel = anchor - step;
  346. UpperLevel = anchor + step;
  347. return;
  348. }
  349. // Special handling for step == 10: use non–symmetric levels.
  350. if(step == 10)
  351. {
  352. if(currentPrice > anchor)
  353. {
  354. LowerLevel = anchor;
  355. UpperLevel = anchor + step;
  356. }
  357. else // currentPrice < anchor
  358. {
  359. LowerLevel = anchor - step;
  360. UpperLevel = anchor;
  361. }
  362. return;
  363. }
  364. // For all other steps, use the ratio threshold logic.
  365. double ratio = diff / step;
  366. double threshold = 0.45; // Adjusted threshold
  367. if(currentPrice > anchor)
  368. {
  369. if(ratio > threshold)
  370. {
  371. LowerLevel = anchor - step;
  372. UpperLevel = anchor + step;
  373. }
  374. else
  375. {
  376. LowerLevel = anchor;
  377. UpperLevel = anchor + step;
  378. }
  379. }
  380. else // currentPrice < anchor
  381. {
  382. if(ratio > threshold)
  383. {
  384. LowerLevel = anchor - step;
  385. UpperLevel = anchor + step;
  386. }
  387. else
  388. {
  389. LowerLevel = anchor - step;
  390. UpperLevel = anchor;
  391. }
  392. }
  393. }
  394. //+------------------------------------------------------------------+
  395. //| Place Buy Trade Function |
  396. //+------------------------------------------------------------------+
  397. void placeBuyTrade()
  398. {
  399. double buySL = 0, buyTp=0;
  400. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  401. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  402. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  403. if(stoploss != 0)
  404. {
  405. buySL = Ask - (stoploss * 10 * Point());
  406. }
  407. if(takeprofit != 0)
  408. {
  409. buyTp = Ask + (takeprofit * 10 * Point());
  410. }
  411. double lot = 0;
  412. double lastLot = 0;
  413. if(selectLatestTicket(lastLot) < 0)
  414. {
  415. lot = lastLot * lot_multiplier;
  416. }
  417. else
  418. {
  419. lot = lot_size;
  420. }
  421. if(trade.PositionOpen(Symbol(),ORDER_TYPE_BUY,NormalizeDouble(lot, 2),Ask,buySL,buyTp,"Buy Trade Placed"))
  422. {
  423. Print("Buy Trade Placed: ", trade.ResultOrder());
  424. }
  425. else
  426. {
  427. Print("Error in placing Buy: "+Symbol()+" ",GetLastError());
  428. }
  429. }
  430. //+------------------------------------------------------------------+
  431. //| Place Sell Trade Function |
  432. //+------------------------------------------------------------------+
  433. void placeSellTrade()
  434. {
  435. double sellSL = 0, sellTp = 0;
  436. //openPrice = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  437. double Ask = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
  438. double Bid = SymbolInfoDouble(Symbol(),SYMBOL_BID);
  439. if(stoploss != 0)
  440. {
  441. sellSL = Bid + (stoploss * 10 * Point());
  442. }
  443. if(takeprofit != 0)
  444. {
  445. sellTp = Bid - (takeprofit * 10 * Point());
  446. }
  447. double lot = 0;
  448. double lastLot = 0;
  449. if(selectLatestTicket(lastLot) < 0)
  450. {
  451. lot = lastLot * lot_multiplier;
  452. }
  453. else
  454. {
  455. lot = lot_size;
  456. }
  457. if(trade.PositionOpen(Symbol(),ORDER_TYPE_SELL,NormalizeDouble(lot, 2),Bid,sellSL,sellTp,"Sell Trade Placed"))
  458. {
  459. Print("Sell Trade PLaced: ", trade.ResultOrder());
  460. }
  461. else
  462. {
  463. Print("Error in placing Sell: "+Symbol()+" ",GetLastError());
  464. }
  465. }
  466. //+------------------------------------------------------------------+
  467. //| Time Conversion Function |
  468. //+------------------------------------------------------------------+
  469. void timeConversion()
  470. {
  471. MqlDateTime date, date1;
  472. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date);
  473. u_sep=StringGetCharacter(sep,0);
  474. StringSplit(startTime,u_sep,result1);
  475. date.hour = (int)StringToInteger(result1[0]);
  476. date.min = (int)StringToInteger(result1[1]);
  477. startTradingTime = StructToTime(date);
  478. TimeToStruct(iTime(Symbol(),PERIOD_CURRENT,0),date1);
  479. StringSplit(endTime,u_sep,result1);
  480. date.hour = (int)StringToInteger(result1[0]);
  481. date.min = (int)StringToInteger(result1[1]);
  482. endTradingTime = StructToTime(date);
  483. }
  484. //+------------------------------------------------------------------+
  485. //| Select Latest Ticket Function |
  486. //+------------------------------------------------------------------+
  487. double selectLatestTicket(double &lastOrderLot)
  488. {
  489. int count = 0;
  490. ulong ticket_deal_Out=0, ticket_deal_In = 0;
  491. datetime latestCloseTime = 0;
  492. double orderProfit = 0;
  493. ulong latestTicket = 0;
  494. if(HistorySelect(ea_start_time, TimeCurrent()))
  495. {
  496. int total = HistoryDealsTotal();
  497. for(int i = total-1; i >= 0 ; i--)
  498. {
  499. ticket_deal_Out = HistoryDealGetTicket(i);
  500. if((HistoryDealGetInteger(ticket_deal_Out,DEAL_MAGIC) == magic_no) && HistoryDealGetInteger(ticket_deal_Out,DEAL_ENTRY) == DEAL_ENTRY_OUT
  501. && HistoryDealGetString(ticket_deal_Out,DEAL_SYMBOL) == Symbol()) // here is the problem solved after break
  502. {
  503. datetime orderCloseTime = (datetime) HistoryDealGetInteger(ticket_deal_Out, DEAL_TIME);
  504. if(orderCloseTime > latestCloseTime)
  505. {
  506. latestCloseTime = (datetime) HistoryDealGetInteger(ticket_deal_Out, DEAL_TIME);
  507. orderProfit = HistoryDealGetDouble(ticket_deal_Out, DEAL_PROFIT);
  508. latestTicket = ticket_deal_Out;
  509. lastOrderLot = HistoryDealGetDouble(ticket_deal_Out, DEAL_VOLUME);
  510. // Print(" Last order Lot: ", lastOrderLot);
  511. }
  512. }
  513. }
  514. }
  515. // Print(" Latest Selected Ticket: ", latestTicket, " Order Close Time: ", latestCloseTime, " Ticket Profit: ", orderProfit);
  516. return orderProfit;
  517. }
  518. //+------------------------------------------------------------------+
  519. //| Get Close Price By Ticket Function |
  520. //+------------------------------------------------------------------+
  521. double getClosePriceByTicket()
  522. {
  523. ulong ticket_deal_Out=0, ticket_deal_In = 0;
  524. datetime latestCloseTime = 0;
  525. double orderClosePrice = 0;
  526. ulong latestTicket = 0;
  527. if(HistorySelect(ea_start_time, TimeCurrent()))
  528. {
  529. int total = HistoryDealsTotal();
  530. for(int i = total-1; i >= 0 ; i--)
  531. {
  532. ticket_deal_Out = HistoryDealGetTicket(i);
  533. if((HistoryDealGetInteger(ticket_deal_Out,DEAL_MAGIC) == magic_no) && HistoryDealGetInteger(ticket_deal_Out,DEAL_ENTRY) == DEAL_ENTRY_OUT
  534. && HistoryDealGetString(ticket_deal_Out,DEAL_SYMBOL) == Symbol()) // here is the problem solved after break
  535. {
  536. datetime orderCloseTime = (datetime) HistoryDealGetInteger(ticket_deal_Out, DEAL_TIME);
  537. if(orderCloseTime > latestCloseTime)
  538. {
  539. orderClosePrice = HistoryDealGetDouble(ticket_deal_Out, DEAL_PRICE);
  540. latestCloseTime = orderCloseTime;
  541. }
  542. }
  543. }
  544. }
  545. return orderClosePrice;
  546. }
  547. //+------------------------------------------------------------------+
  548. //| Order Count Function |
  549. //+------------------------------------------------------------------+
  550. int orderCount()
  551. {
  552. int count = 0;
  553. for(int i= PositionsTotal()-1; i>=0; i--)
  554. {
  555. ulong ticket = PositionGetTicket(i);
  556. if(PositionSelectByTicket(ticket))
  557. {
  558. if(PositionGetInteger(POSITION_MAGIC) == magic_no && PositionGetString(POSITION_SYMBOL) == Symbol())
  559. {
  560. //if(PositionGetInteger(POSITION_TYPE) == type)
  561. {
  562. count++;
  563. }
  564. }
  565. }
  566. }
  567. return count;
  568. }
  569. //+------------------------------------------------------------------+
  570. //| Order Count 1 with Parameters Function |
  571. //+------------------------------------------------------------------+
  572. int orderCount_1(int type,int magic)
  573. {
  574. int count1=0;
  575. for(int i= PositionsTotal()-1; i>=0; i--)
  576. {
  577. ulong ticket = PositionGetTicket(i);
  578. if(PositionSelectByTicket(ticket))
  579. {
  580. if(PositionGetInteger(POSITION_MAGIC) == magic && PositionGetString(POSITION_SYMBOL) == Symbol())
  581. {
  582. if(PositionGetInteger(POSITION_TYPE) == type)
  583. {
  584. count1++;
  585. }
  586. }
  587. }
  588. }
  589. return count1;
  590. }
  591. //+------------------------------------------------------------------+
  592. //| Close Trades Function |
  593. //+------------------------------------------------------------------+
  594. void closeTrades(int type,int magicno)
  595. {
  596. Print("Total order: ",OrdersTotal());
  597. for(int i= PositionsTotal()-1; i>=0; i--)
  598. {
  599. ulong ticket = PositionGetTicket(i);
  600. if(PositionSelectByTicket(ticket))
  601. {
  602. if(PositionGetInteger(POSITION_TYPE) == type)
  603. {
  604. if(PositionGetInteger(POSITION_MAGIC) == magicno && PositionGetString(POSITION_SYMBOL) == Symbol())
  605. {
  606. if(!trade.PositionClose(PositionGetInteger(POSITION_TICKET)))
  607. {Print("Problem in closing order order ",PositionGetInteger(POSITION_TICKET)); }
  608. else
  609. {
  610. Print("Order Closed by closeTrades() new filter",PositionGetInteger(POSITION_TICKET));
  611. }
  612. }
  613. }
  614. }
  615. }
  616. }
  617. //+------------------------------------------------------------------+