- Taking a trade at 01:05 AM
- How to I put in leverage on the EA
- How to code?
I’m having issues with my EA that I’ve spent coding over the past few weeks.
You MUST check for errors returned when submitting a trade order. You don't.
Start checking (start printing first) the result of the trade order.
You MUST check for errors returned when submitting a trade order. You don't.
Start checking (start printing first) the result of the trade order.
There are no errors returned when I use the EA that is why I am confused
There are no errors returned when I use the EA that is why I am confused
And where are the errors? You must analyze the result of a trade and analyze whether there is an error or not.
Example of actions: sent a Buy trade order and printed the result:
Gets the code of request result | |
Gets the code of request result as a string |
- www.mql5.com
And where are the errors? You must analyze the result of a trade and analyze whether there is an error or not.
Example of actions: sent a Buy trade order and printed the result:
Gets the code of request result | |
Gets the code of request result as a string |
//+------------------------------------------------------------------+ //| ExpoProfit.mq4 | //| Harry Ward | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Harry Ward" #property link "https://www.mql5.com" #property version "1.00" #property strict int maxOrders = 1; int buyOrders = 0; int sellOrders = 0; double lotSize = 0.01*(AccountBalance()/10); input int inpPeriod = 84; // Period input double inpDivisor = 2.0; // Divisor ("speed") input ENUM_APPLIED_PRICE inpPrice = PRICE_CLOSE; // Price input string InpTradeComment = __FILE__; // Trade comment input int InpMagicNumber = 69420; // Magic number const string IndicatorName = "HMA Dynamic Color"; void OnTick() { double currentSMA = iMA(NULL, 0,100,0,MODE_EMA,PRICE_CLOSE,0); if (!NewBar()) return; if (iCustom(NULL,0,IndicatorName, 84, true, true, true,1, 0) < currentSMA) { buyOrders = 0; } if ((iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) > 0) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) < 2) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) > currentSMA) && (buyOrders<1)) { sellOrders = 0; } if ((iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,1, 1) > 0) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,1, 1) < 2) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,1, 1) > currentSMA) && (sellOrders<1)) { OrderSend(Symbol(),OP_SELL,lotSize,Bid,3,0,0,"ExpoProfit",0,0,clrRed); sellOrders = sellOrders + 1; lotSize = lotSize*2; } if ((iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) > 0) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) < 2) && (iCustom(Symbol(),Period(),IndicatorName, inpPeriod, inpDivisor, inpPrice, true,0, 0) < currentSMA) && (buyOrders<1)) { OrderSend(Symbol(),OP_BUY,lotSize,Ask,3,0,0,"ExpoProfit",0,0,clrGreen); buyOrders = buyOrders + 1; lotSize = lotSize*2; } if ((iCustom(NULL,0,IndicatorName, 84, true, true, true,0, 0)> currentSMA) && (countBuyPositions()>0) && (iCustom(NULL,0,IndicatorName, 84, true, true, true,1, 0)>currentSMA)) { closeAllBuy(); lotSize = 0.01*(AccountBalance()/10); buyOrders = 0; } if ((iCustom(NULL,0,IndicatorName, 84, true, true, true,1, 0) < currentSMA) && (countSellPositions()>0)) { closeAllSell(); lotSize = 0.01*(AccountBalance()/10); sellOrders = 0; } } void closeAllBuy() { for (int i = OrdersTotal();i >= 0; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if (OrderSymbol() == Symbol()) if (OrderType()==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),Bid,3,NULL); } } } void closeAllSell() { for (int i = OrdersTotal();i >= 0; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if (OrderSymbol() == Symbol()) if (OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),Ask,3,NULL); } } } bool NewBar() { static datetime priorTime = 0; datetime currentTime = iTime(Symbol(), Period(), 0); bool result = (currentTime!=priorTime); priorTime = currentTime; return(result); } int countBuyPositions() { int numberOfBuyPositions = 0; for(int i = OrdersTotal()-1; i >= 0 ; i--) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); string currencyPair = OrderSymbol(); if (_Symbol == currencyPair) if(OrderType()==OP_BUY) { numberOfBuyPositions = numberOfBuyPositions +1; } } return numberOfBuyPositions; } int countSellPositions() { int numberOfSellPositions = 0; for(int i = OrdersTotal()-1; i >= 0 ; i--) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); string currencyPair = OrderSymbol(); if (_Symbol == currencyPair) if(OrderType()==OP_SELL) { numberOfSellPositions = numberOfSellPositions +1; } } return numberOfSellPositions;
This is my code, I don't know what youre asking me to do
This is my code, I don't know what youre asking me to do
Your code is MQL4.
Topics concerning MT4 and MQL4 have their own section.
You have been answered as if you were using MQL5.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
Your code is MQL4.
Topics concerning MT4 and MQL4 have their own section.
You have been answered as if you were using MQL5.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
Ok thanks, sorry about that
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use