├── README.md ├── SuperMao.mq4 ├── SuperMaoHFT.mq4 ├── SuperMaoIchiMoku.mq4 ├── TakeProfitStopLoss.mqh └── openordercheck.mqh /README.md: -------------------------------------------------------------------------------- 1 | # Trading Bot SuperMao 2 | 3 | SuperMao is a trading bot named after my imaginary cat. It trades on MetaTrader trading platform. It takes into account 4 | the following things before taking any position- 5 | 6 | 1. If the Ask price is within lower band of 2 standard deviation and upper band 1 standard deviation Bollinger Bands and the MACD line is above the MACD signal line, 7 | it goes long. The Stop Loss is set at the lower band of 6 standard deviation Bollinger Band. Take Profit is set at the 8 | upper band of the 1 standard deviation Bollinger Bands. 9 | 10 | 2. If the Bid price is within upper bands of 2 standard deviation and lower band 1 standard deviation Bollinger Bands and the MACD line is below the MACD 11 | Signal Line it goes short. The Stop Loss is set at the upper band of 6 standard deviation Bollinger Bands. Take Profit is set 12 | at the lowr band of the 1 standard deviation Bollinger Bands. 13 | 14 | 3. A currency pair can have only one active positon on a specific timeframe, SuperMao stops you from losing everything too quickly. 15 | 16 | ### Disclaimer 17 | 18 | SuperMao is not perfect, don't set it free. It can blow your capital as quickly as 1 week. Don't blame the cat, blame the creator. However, he is working procrastinatingly to make the cat a better hunter. 19 | 20 | According to the back-test run on the previous 6-month data, SuperMao has a success rate of over 90%. 21 | ![Alt text](https://user-images.githubusercontent.com/8532244/85926007-09723c80-b8be-11ea-8d90-d9ed6b5c6a80.PNG) 22 | -------------------------------------------------------------------------------- /SuperMao.mq4: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| SuperMao.mq4 | 3 | //| Copyright 2020, khantanvir | 4 | //| https://github.com/tanvird3 | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2020, khantanvir" 7 | #property link "https://github.com/tanvird3" 8 | #property version "2.00" 9 | #property strict 10 | #include 11 | 12 | input string MySymbol = NULL; // provide the symbol 13 | input ENUM_TIMEFRAMES MyTimeFrame = PERIOD_CURRENT; // For per minute, hour or monthly 14 | input int MyAvgPeriod = 50; // time frame for calculating moving average 15 | input ENUM_APPLIED_PRICE MyPrice = PRICE_CLOSE; // what price do we want to consider 16 | input double LotSize = 0.01; // the lot size we wish to trade 17 | input int FirstBBand = 1; 18 | input int SecondBBand = 2; 19 | input int ThirdBBand = 6; 20 | input int MacdFast = 24; 21 | input int MacdSlow = 52; 22 | input int MacdSignal = 18; 23 | input string ContUpdate = "NO"; // Should TP & SL Keep Updating Continuously 24 | 25 | //+------------------------------------------------------------------+ 26 | //| | 27 | //+------------------------------------------------------------------+ 28 | int MagicNumber = 9228+Period()+StringGetChar(MySymbol, 0)+StringGetChar(MySymbol, 3); //set the unique number for each comb of currency pair and timeframe 29 | int OrderId; 30 | //+------------------------------------------------------------------+ 31 | //| Expert initialization function | 32 | //+------------------------------------------------------------------+ 33 | int OnInit() 34 | { 35 | //--- 36 | Alert("You Have Just Awakened SuperMao"); 37 | //--- 38 | return(INIT_SUCCEEDED); 39 | } 40 | //+------------------------------------------------------------------+ 41 | //| Expert deinitialization function | 42 | //+------------------------------------------------------------------+ 43 | void OnDeinit(const int reason) 44 | { 45 | //--- 46 | Alert("SuperMao Is Going Into Hybernation"); 47 | } 48 | //+------------------------------------------------------------------+ 49 | //| Expert tick function | 50 | //+------------------------------------------------------------------+ 51 | void OnTick() 52 | { 53 | //--- 54 | 55 | // first band is at 1 std 56 | double UBBAND1 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, FirstBBand, 0, MyPrice, MODE_UPPER, 0); 57 | double LBBAND1 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, FirstBBand, 0, MyPrice, MODE_LOWER, 0); 58 | 59 | // second band is at 2 std 60 | double UBBAND2 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, SecondBBand, 0, MyPrice, MODE_UPPER, 0); 61 | double LBBAND2 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, SecondBBand, 0, MyPrice, MODE_LOWER, 0); 62 | double MBBAND = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, SecondBBand, 0, MyPrice, MODE_MAIN, 0); 63 | 64 | // third band is at 6 std 65 | double UBBAND6 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, ThirdBBand, 0, MyPrice, MODE_UPPER, 0); 66 | double LBBAND6 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, ThirdBBand, 0, MyPrice, MODE_LOWER, 0); 67 | 68 | // macd histogram value for confirmation 69 | double MACDMAIN = iMACD(MySymbol, MyTimeFrame, MacdFast, MacdSlow, MacdSignal, MyPrice, MODE_MAIN, 0); 70 | double MACDSIGNAL = iMACD(MySymbol, MyTimeFrame, MacdFast, MacdSlow, MacdSignal, MyPrice, MODE_SIGNAL, 0); 71 | 72 | // if there is no order only then a new order would be sent 73 | if(!CheckOpenOrder(MagicNumber)) 74 | { 75 | if(Ask >= LBBAND2 && Ask < UBBAND1 && MACDMAIN > MACDSIGNAL) //if price is between lower band 2 and upper band 1 and macd line above macd signal go long 76 | { 77 | 78 | Alert("Buy Now at "+ NormalizeDouble(Ask, Digits)); 79 | Alert("Take Proft at "+ NormalizeDouble(UBBAND1, Digits)); 80 | Alert("Stop Loss at "+ NormalizeDouble(LBBAND6, Digits)); 81 | OrderId = OrderSend(MySymbol, OP_BUYLIMIT, LotSize, Ask, 10, NormalizeDouble(LBBAND6, Digits), NormalizeDouble(UBBAND1, Digits), NULL, MagicNumber); 82 | if(OrderId < 0) 83 | Alert("The Order Could Not Be Sent, ErrorCode: " + GetLastError()); 84 | } 85 | else 86 | if(Bid <= UBBAND2 && Bid > LBBAND1 && MACDMAIN < MACDSIGNAL) //if price is between upper band 2 and lower band 1 and macd below signal go short 87 | { 88 | Alert("Sell Now at "+ NormalizeDouble(Bid, Digits)); 89 | Alert("Take Proft at "+ NormalizeDouble(LBBAND1, Digits)); 90 | Alert("Stop Loss at "+ NormalizeDouble(UBBAND6, Digits)); 91 | OrderId = OrderSend(MySymbol, OP_SELLLIMIT, LotSize, Bid, 10, NormalizeDouble(UBBAND6, Digits), NormalizeDouble(LBBAND1, Digits), NULL, MagicNumber); 92 | if(OrderId < 0) 93 | Alert("The Order Could Not Be Sent, ErrorCode: " + GetLastError()); 94 | } 95 | /*else 96 | { 97 | Alert("Hold Your Nerve"); 98 | }*/ 99 | } 100 | else // if an order has already been placed 101 | { 102 | if(ContUpdate=="Yes") 103 | { 104 | if(OrderSelect(OrderId, SELECT_BY_TICKET)==true) // check if extracting data is possible 105 | { 106 | int orderType = OrderType(); // check the ordertype, 0 = long, 1 = short 107 | double UpdatedTakeProfit; 108 | if(orderType == 0) 109 | { 110 | UpdatedTakeProfit = NormalizeDouble(UBBAND1, Digits); // modify the take profit for long position 111 | } 112 | else 113 | { 114 | UpdatedTakeProfit = NormalizeDouble(LBBAND1, Digits); // modify the take profit for short position 115 | } 116 | double TP = OrderTakeProfit(); 117 | double OpenPrice = OrderOpenPrice(); 118 | double TPdistance = MathAbs(TP - UpdatedTakeProfit); 119 | if((orderType ==0 && TP!=UpdatedTakeProfit && UpdatedTakeProfit > OpenPrice && TPdistance >= .0001) || (orderType ==1 && TP!=UpdatedTakeProfit && UpdatedTakeProfit < OpenPrice && TPdistance >= .0001)) // if the currect take profit is not equal to the updated take profit by at least a pip 120 | { 121 | bool ModifySuccess = OrderModify(OrderId, OrderOpenPrice(), OrderStopLoss(), UpdatedTakeProfit, 0); 122 | if(ModifySuccess == true) 123 | { 124 | Print("Order modified: ",OrderId); 125 | } 126 | else 127 | { 128 | Print("Unable to modify order: ",OrderId); 129 | } 130 | } 131 | } 132 | } 133 | } 134 | } 135 | //+------------------------------------------------------------------+ 136 | -------------------------------------------------------------------------------- /SuperMaoHFT.mq4: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| SuperMao.mq4 | 3 | //| Copyright 2020, khantanvir | 4 | //| https://github.com/tanvird3 | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2020, khantanvir" 7 | #property link "https://github.com/tanvird3" 8 | #property version "2.00" 9 | #property strict 10 | #include 11 | #include 12 | 13 | input string MySymbol = "USDJPY"; // provide the symbol 14 | input double ProfitTarget = 1; 15 | input double StopLoss = 5; 16 | input ENUM_TIMEFRAMES MyTimeFrame = PERIOD_CURRENT; // For per minute, hour or monthly 17 | input int MyAvgPeriod = 50; // time frame for calculating moving average 18 | input ENUM_APPLIED_PRICE MyPrice = PRICE_CLOSE; // what price do we want to consider 19 | input double LotSize = 0.01; // the lot size we wish to trade 20 | input int FirstBBand = 1; 21 | input int SecondBBand = 2; 22 | input int ThirdBBand = 6; 23 | input int MacdFast = 24; 24 | input int MacdSlow = 52; 25 | input int MacdSignal = 18; 26 | input string ContUpdate = "NO"; // Should TP & SL Keep Updating 27 | 28 | //+------------------------------------------------------------------+ 29 | //| | 30 | //+------------------------------------------------------------------+ 31 | int MagicNumber = 2000+Period()+StringGetChar(MySymbol, 0)+StringGetChar(MySymbol, 3); //set the unique number for each comb of currency pair and timeframe 32 | int OrderId; 33 | //+------------------------------------------------------------------+ 34 | //| Expert initialization function | 35 | //+------------------------------------------------------------------+ 36 | int OnInit() 37 | { 38 | //--- 39 | Alert("You Have Just Awakened SuperMao_HFT"); 40 | //--- 41 | return(INIT_SUCCEEDED); 42 | } 43 | //+------------------------------------------------------------------+ 44 | //| Expert deinitialization function | 45 | //+------------------------------------------------------------------+ 46 | void OnDeinit(const int reason) 47 | { 48 | //--- 49 | Alert("SuperMao_HFT Is Going Into Hybernation"); 50 | } 51 | //+------------------------------------------------------------------+ 52 | //| Expert tick function | 53 | //+------------------------------------------------------------------+ 54 | void OnTick() 55 | { 56 | //--- 57 | 58 | // first band is at 1 std 59 | double UBBAND1 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, FirstBBand, 0, MyPrice, MODE_UPPER, 0); 60 | double LBBAND1 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, FirstBBand, 0, MyPrice, MODE_LOWER, 0); 61 | 62 | // second band is at 2 std 63 | double UBBAND2 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, SecondBBand, 0, MyPrice, MODE_UPPER, 0); 64 | double LBBAND2 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, SecondBBand, 0, MyPrice, MODE_LOWER, 0); 65 | double MBBAND = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, SecondBBand, 0, MyPrice, MODE_MAIN, 0); 66 | 67 | // third band is at 6 std 68 | double UBBAND6 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, ThirdBBand, 0, MyPrice, MODE_UPPER, 0); 69 | double LBBAND6 = iBands(MySymbol, MyTimeFrame, MyAvgPeriod, ThirdBBand, 0, MyPrice, MODE_LOWER, 0); 70 | 71 | // macd histogram value for confirmation 72 | double MACDMAIN = iMACD(MySymbol, MyTimeFrame, MacdFast, MacdSlow, MacdSignal, MyPrice, MODE_MAIN, 0); 73 | double MACDSIGNAL = iMACD(MySymbol, MyTimeFrame, MacdFast, MacdSlow, MacdSignal, MyPrice, MODE_SIGNAL, 0); 74 | 75 | // if there is no order only then a new order would be sent 76 | 77 | if(Ask >= LBBAND2 && Ask < UBBAND1 && MACDMAIN > MACDSIGNAL) //if price is between lower band 2 and upper band 1 and macd line above macd signal go long 78 | { 79 | double TPL = TPLong(MySymbol, LotSize, ProfitTarget); 80 | TPL = MathMin(TPL, UBBAND1); 81 | 82 | double SLL = SLLong(MySymbol, LotSize, StopLoss); 83 | SLL = MathMax(SLL, LBBAND6); 84 | 85 | Alert("Buy Now at "+ NormalizeDouble(Ask, Digits)); 86 | Alert("Take Proft at "+ NormalizeDouble(TPL, Digits)); 87 | Alert("Stop Loss at "+ NormalizeDouble(SLL, Digits)); 88 | OrderId = OrderSend(MySymbol, OP_BUYLIMIT, LotSize, Ask, 10, NormalizeDouble(SLL, Digits), NormalizeDouble(TPL, Digits), NULL, MagicNumber); 89 | if(OrderId < 0) 90 | Alert("The Order Could Not Be Sent, ErrorCode: " + GetLastError()); 91 | } 92 | else 93 | if(Bid <= UBBAND2 && Bid > LBBAND1 && MACDMAIN < MACDSIGNAL) //if price is between upper band 2 and lower band 1 and macd below signal go short 94 | { 95 | double TPS = TPShort(MySymbol, LotSize, ProfitTarget); 96 | TPS = MathMax(TPS, LBBAND1); 97 | 98 | double SLS = SLShort(MySymbol, LotSize, StopLoss); 99 | SLS = MathMin(SLS, UBBAND6); 100 | 101 | Alert("Sell Now at "+ NormalizeDouble(Bid, Digits)); 102 | Alert("Take Proft at "+ NormalizeDouble(LBBAND1, Digits)); 103 | Alert("Stop Loss at "+ NormalizeDouble(UBBAND6, Digits)); 104 | OrderId = OrderSend(MySymbol, OP_SELLLIMIT, LotSize, Bid, 10, NormalizeDouble(SLS, Digits), NormalizeDouble(TPS, Digits), NULL, MagicNumber); 105 | if(OrderId < 0) 106 | Alert("The Order Could Not Be Sent, ErrorCode: " + GetLastError()); 107 | } 108 | /*else 109 | { 110 | Alert("Hold Your Nerve"); 111 | }*/ 112 | } 113 | //+------------------------------------------------------------------+ 114 | -------------------------------------------------------------------------------- /SuperMaoIchiMoku.mq4: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| SuperMao.mq4 | 3 | //| Copyright 2020, khantanvir | 4 | //| https://github.com/tanvird3 | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2020, khantanvir" 7 | #property link "https://github.com/tanvird3" 8 | #property version "2.00" 9 | #property strict 10 | #include 11 | 12 | input string MySymbol = NULL; // provide the symbol 13 | input ENUM_TIMEFRAMES MyTimeFrame = PERIOD_CURRENT; // For per minute, hour or monthly 14 | input ENUM_APPLIED_PRICE MyPrice = PRICE_CLOSE; // what price do we want to consider 15 | input double LotSize = 0.10; // the lot size we wish to trade 16 | input int TenKanSen = 9; 17 | input int KijunSen = 26; 18 | input int SenKouSpanB = 52; 19 | input int TakeProfit = 5; 20 | input int StopLoss = .2; 21 | 22 | input string ContUpdate = "Yes"; // Should TP & SL Keep Updating Continuously 23 | 24 | //+------------------------------------------------------------------+ 25 | //| | 26 | //+------------------------------------------------------------------+ 27 | int MagicNumber = 5000+Period()+StringGetChar(MySymbol, 0)+StringGetChar(MySymbol, 3); //set the unique number for each comb of currency pair and timeframe 28 | int OrderId; 29 | //+------------------------------------------------------------------+ 30 | //| Expert initialization function | 31 | //+------------------------------------------------------------------+ 32 | int OnInit() 33 | { 34 | //--- 35 | Alert("You Have Just Awakened SuperMaoIchiMoku"); 36 | //--- 37 | return(INIT_SUCCEEDED); 38 | } 39 | //+------------------------------------------------------------------+ 40 | //| Expert deinitialization function | 41 | //+------------------------------------------------------------------+ 42 | void OnDeinit(const int reason) 43 | { 44 | //--- 45 | Alert("SuperMaoIchiMoku Is Going Into Hybernation"); 46 | } 47 | //+------------------------------------------------------------------+ 48 | //| Expert tick function | 49 | //+------------------------------------------------------------------+ 50 | void OnTick() 51 | { 52 | //--- 53 | 54 | // Set the Ichimoku Properties 55 | double tenkan_sen = iIchimoku(NULL,0,TenKanSen,KijunSen,SenKouSpanB,MODE_TENKANSEN,0); 56 | double kinjun_sen = iIchimoku(NULL,0,TenKanSen,KijunSen,SenKouSpanB,MODE_KIJUNSEN,0); 57 | double senkou_spanA = iIchimoku(NULL,0,TenKanSen,KijunSen,SenKouSpanB,MODE_SENKOUSPANA,0); 58 | double senkou_spanB = iIchimoku(NULL,0,TenKanSen,KijunSen,SenKouSpanB,MODE_SENKOUSPANB,0); 59 | 60 | // if there is no order only then a new order would be sent 61 | if(!CheckOpenOrder(MagicNumber)) 62 | { 63 | if(tenkan_sen > kinjun_sen && Close[0] > MathMin(senkou_spanA, senkou_spanB)) //if tenken_sen is above kinjun_sen and Close is within or above the cloud go long 64 | { 65 | Alert("Buy Now at "+ NormalizeDouble(Ask, Digits)); 66 | Alert("Take Proft at "+ NormalizeDouble(Ask+ Ask * TakeProfit/100, Digits)); // primary take profit is set at the designated level 67 | //Alert("Stop Loss at "+ NormalizeDouble(MathMin(senkou_spanA, senkou_spanB), Digits)); 68 | Alert("Stop Loss at "+ NormalizeDouble(Ask - Ask * TakeProfit/100, Digits)); // stop loss is set at the designated level 69 | OrderId = OrderSend(MySymbol, OP_BUYLIMIT, LotSize, Ask, 10, NormalizeDouble(Ask - Ask * TakeProfit/100, Digits), NormalizeDouble(Ask+ Ask * TakeProfit/100, Digits), NULL, MagicNumber); 70 | if(OrderId < 0) 71 | Alert("The Order Could Not Be Sent, ErrorCode: " + GetLastError()); 72 | } 73 | else 74 | if(tenkan_sen < kinjun_sen && Close[0] < MathMax(senkou_spanA, senkou_spanB)) //if tenken_sen is below kinjun_sen and Close is within or below the cloud go short 75 | { 76 | Alert("Sell Now at "+ NormalizeDouble(Bid, Digits)); 77 | Alert("Take Proft at "+ NormalizeDouble(Bid-Bid * TakeProfit/100, Digits)); 78 | //Alert("Stop Loss at "+ NormalizeDouble(MathMax(senkou_spanA, senkou_spanB),Digits)); 79 | Alert("Stop Loss at "+ NormalizeDouble(Bid+Bid * TakeProfit/100, Digits)); 80 | OrderId = OrderSend(MySymbol, OP_SELLLIMIT, LotSize, Bid, 10, NormalizeDouble(Bid+Bid * TakeProfit/100, Digits), NormalizeDouble(Bid-Bid * TakeProfit/100, Digits), NULL, MagicNumber); 81 | if(OrderId < 0) 82 | Alert("The Order Could Not Be Sent, ErrorCode: " + GetLastError()); 83 | } 84 | /*else 85 | { 86 | Alert("Hold Your Nerve"); 87 | }*/ 88 | } 89 | else // if an order has already been placed 90 | { 91 | if(ContUpdate=="Yes") 92 | { 93 | if(OrderSelect(OrderId, SELECT_BY_TICKET)==true) // check if extracting data is possible 94 | { 95 | int orderType = OrderType(); // check the ordertype, 0 = long, 1 = short 96 | double UpdatedTakeProfit; 97 | if(orderType == 0) 98 | { 99 | if(tenkan_sen < kinjun_sen) // if the tenken_sen has come below kinjun_sen sell 100 | { 101 | UpdatedTakeProfit = NormalizeDouble(Bid, Digits); // modify the take profit for long position i.e. sell at current bid 102 | } 103 | } 104 | else 105 | { 106 | if(tenkan_sen > kinjun_sen) // if the tenken_sen has gone above kinjun_sen 107 | { 108 | UpdatedTakeProfit = NormalizeDouble(Ask, Digits); // modify the take profit for short position ie buy at current ask 109 | } 110 | } 111 | double TP = OrderTakeProfit(); 112 | double OpenPrice = OrderOpenPrice(); 113 | double TPdistance = MathAbs(TP - UpdatedTakeProfit); 114 | if((orderType==0 && TP!=UpdatedTakeProfit && UpdatedTakeProfit > OpenPrice && TPdistance >= .0001) || (orderType==1 && TP!=UpdatedTakeProfit && UpdatedTakeProfit < OpenPrice && TPdistance >= .0001)) // if the currect take profit is not equal to the updated take profit by at least a pip 115 | { 116 | bool ModifySuccess = OrderModify(OrderId, OrderOpenPrice(), OrderStopLoss(), UpdatedTakeProfit, 0); 117 | if(ModifySuccess == true) 118 | { 119 | Print("Order modified: ",OrderId); 120 | } 121 | else 122 | { 123 | Print("Unable to modify order: ",OrderId); 124 | } 125 | } 126 | } 127 | } 128 | } 129 | } 130 | //+------------------------------------------------------------------+ 131 | -------------------------------------------------------------------------------- /TakeProfitStopLoss.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| TakeProfitStopLoss.mqh | 3 | //| Copyright 2020, khantanvir | 4 | //| https://www.mql5.com | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2020, khantanvir" 7 | #property link "https://www.mql5.com" 8 | #property strict 9 | //+------------------------------------------------------------------+ 10 | //| defines | 11 | //+------------------------------------------------------------------+ 12 | // #define MacrosHello "Hello, world!" 13 | // #define MacrosYear 2010 14 | //+------------------------------------------------------------------+ 15 | //| DLL imports | 16 | //+------------------------------------------------------------------+ 17 | // #import "user32.dll" 18 | // int SendMessageA(int hWnd,int Msg,int wParam,int lParam); 19 | // #import "my_expert.dll" 20 | // int ExpertRecalculate(int wParam,int lParam); 21 | // #import 22 | //+------------------------------------------------------------------+ 23 | //| EX5 imports | 24 | //+------------------------------------------------------------------+ 25 | // #import "stdlib.ex5" 26 | // string ErrorDescription(int error_code); 27 | // #import 28 | //+------------------------------------------------------------------+ 29 | double TPLong(string MySymbol, double LotSize, double ProfitTarget) 30 | { 31 | //--- 32 | string QuoteCurrency = StringSubstr(MySymbol, 3); 33 | string BaseCurrency = StringSubstr(MySymbol, 0, 3); 34 | 35 | double TP; 36 | 37 | if(QuoteCurrency == "USD") 38 | { 39 | double TradingUSD = Ask; 40 | TP = TradingUSD + 1 / (100000 * LotSize) * ProfitTarget; 41 | } 42 | else 43 | if(BaseCurrency == "USD") 44 | { 45 | double TradingUSD = 1; 46 | TP = (TradingUSD + 1 / (100000 * LotSize) * 1) * Ask; 47 | } 48 | else 49 | { 50 | double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_ASK); 51 | if(TradingUSD == 0) 52 | { 53 | TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_ASK); 54 | } 55 | TP = (Ask / TradingUSD + 1 / (100000 * LotSize) * ProfitTarget) * TradingUSD ; 56 | } 57 | return (TP); 58 | } 59 | 60 | //+------------------------------------------------------------------+ 61 | //| | 62 | //+------------------------------------------------------------------+ 63 | double TPShort(string MySymbol, double LotSize, double ProfitTarget) 64 | { 65 | //--- 66 | string QuoteCurrency = StringSubstr(MySymbol, 3); 67 | string BaseCurrency = StringSubstr(MySymbol, 0, 3); 68 | 69 | double TP; 70 | 71 | if(QuoteCurrency == "USD") 72 | { 73 | double TradingUSD = Bid; 74 | TP = TradingUSD - 1 / (100000 * LotSize) * ProfitTarget; 75 | } 76 | else 77 | if(BaseCurrency == "USD") 78 | { 79 | double TradingUSD = 1; 80 | TP = (TradingUSD - 1 / (100000 * LotSize) * 1) * Bid; 81 | } 82 | else 83 | { 84 | double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_BID); 85 | if(TradingUSD == 0) 86 | { 87 | TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_BID); 88 | } 89 | TP = (Bid / TradingUSD - 1 / (100000 * LotSize) * ProfitTarget) * TradingUSD ; 90 | } 91 | return (TP); 92 | } 93 | 94 | //+------------------------------------------------------------------+ 95 | //| | 96 | //+------------------------------------------------------------------+ 97 | double SLLong(string MySymbol, double LotSize, double StopLoss) 98 | { 99 | //--- 100 | string QuoteCurrency = StringSubstr(MySymbol, 3); 101 | string BaseCurrency = StringSubstr(MySymbol, 0, 3); 102 | 103 | double SL; 104 | 105 | if(QuoteCurrency == "USD") 106 | { 107 | double TradingUSD = Ask; 108 | SL = TradingUSD - 1 / (100000 * LotSize) * StopLoss; 109 | } 110 | else 111 | if(BaseCurrency == "USD") 112 | { 113 | double TradingUSD = 1; 114 | SL = (TradingUSD - 1 / (100000 * LotSize) * StopLoss) * Ask; 115 | } 116 | else 117 | { 118 | double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_ASK); 119 | if(TradingUSD == 0) 120 | { 121 | TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_ASK); 122 | } 123 | SL = (Ask / TradingUSD - 1 / (100000 * LotSize) * StopLoss) * TradingUSD ; 124 | } 125 | return (SL); 126 | } 127 | 128 | //+------------------------------------------------------------------+ 129 | //| | 130 | //+------------------------------------------------------------------+ 131 | double SLShort(string MySymbol, double LotSize, double StopLoss) 132 | { 133 | //--- 134 | string QuoteCurrency = StringSubstr(MySymbol, 3); 135 | string BaseCurrency = StringSubstr(MySymbol, 0, 3); 136 | 137 | double SL; 138 | 139 | if(QuoteCurrency == "USD") 140 | { 141 | double TradingUSD = Bid; 142 | SL = TradingUSD + 1 / (100000 * LotSize) * StopLoss; 143 | } 144 | else 145 | if(BaseCurrency == "USD") 146 | { 147 | double TradingUSD = 1; 148 | SL = (TradingUSD + 1 / (100000 * LotSize) * StopLoss) * Bid; 149 | } 150 | else 151 | { 152 | double TradingUSD = MarketInfo("USD"+QuoteCurrency, MODE_BID); 153 | if(TradingUSD == 0) 154 | { 155 | TradingUSD = 1 / MarketInfo(QuoteCurrency+"USD", MODE_BID); 156 | } 157 | SL = (Bid / TradingUSD + 1 / (100000 * LotSize) * StopLoss) * TradingUSD ; 158 | } 159 | return (SL); 160 | } 161 | //+------------------------------------------------------------------+ 162 | -------------------------------------------------------------------------------- /openordercheck.mqh: -------------------------------------------------------------------------------- 1 | //+------------------------------------------------------------------+ 2 | //| openordercheck.mqh | 3 | //| Copyright 2020, khantanvir | 4 | //| https://github.com/tanvird3 | 5 | //+------------------------------------------------------------------+ 6 | #property copyright "Copyright 2020, khantanvir" 7 | #property link "https://github.com/tanvird3" 8 | #property strict 9 | //+------------------------------------------------------------------+ 10 | //| defines | 11 | //+------------------------------------------------------------------+ 12 | // #define MacrosHello "Hello, world!" 13 | // #define MacrosYear 2010 14 | //+------------------------------------------------------------------+ 15 | //| DLL imports | 16 | //+------------------------------------------------------------------+ 17 | // #import "user32.dll" 18 | // int SendMessageA(int hWnd,int Msg,int wParam,int lParam); 19 | // #import "my_expert.dll" 20 | // int ExpertRecalculate(int wParam,int lParam); 21 | // #import 22 | //+------------------------------------------------------------------+ 23 | //| EX5 imports | 24 | //+------------------------------------------------------------------+ 25 | // #import "stdlib.ex5" 26 | // string ErrorDescription(int error_code); 27 | // #import 28 | //+------------------------------------------------------------------+ 29 | // This function checks if there is any open order already by the same expert advisor by checking the magic nuber 30 | 31 | bool CheckOpenOrder (int MyMagicNumber) 32 | { 33 | int OpenOrder = OrdersTotal(); // checks total number of openorder 34 | 35 | for (int i = 0; i < OpenOrder; i++) // loop through all the open order, picks data with OrderSelect and checks the magic nubmber of the order 36 | { 37 | if (OrderSelect(i, SELECT_BY_POS) == true) // if it succeeds to pull the data of ther order 38 | { 39 | if (OrderMagicNumber() == MyMagicNumber) // check the orders magic number 40 | { 41 | return true; // if the OrderMagicNumber of any order matches MyMagicNumber that means there is alreay an open order sent through this EA 42 | } 43 | } 44 | } 45 | return false; // otherwise false and allow the EA to send new order 46 | } 47 | 48 | bool CheckMarketOpen () 49 | { 50 | if(IsTradeAllowed()) 51 | { 52 | return true; 53 | } 54 | else 55 | { 56 | return false; 57 | } 58 | 59 | } --------------------------------------------------------------------------------