Discussion of article "Step-by-Step Guide to Writing an Expert Advisor in MQL5 for Beginners" - page 13

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
With all the changes to the MQL5 programming an updated version of this step by step code is needed, if i copy this code it no longer compiles - is there a version with the latest changes - many thanks.
Hello Michael,
Thanks for your comment. I will look into your suggestion and if any update to the codes are necessary, it will be made available soon.
why output error code :10030 ?
help, Is anybody here ?
why output error code :10030 ?
First of all thanks for the article, It's helping me with getting started on mql5 programming.
I've tried your code and there's a bit of code on the OnInit() that I don't understand the purpose of it:
//--- Let us handle currency pairs with 5 or 3 digit prices instead of 4
STP = StopLoss;
TKP = TakeProfit;
if(_Digits==5 || _Digits==3)
{
STP = STP*10;
TKP = TKP*10;
}
This part modifies the values of take profit and stop loss pibs causing a difference between your input values and the ones really being used.
However, if I remove the two lines inside the if, then I often receive error 10016 (invalid stops) when sending the order to the server. The first attempt to place an order goes well and I get the 10009, but then most of the following times I get a 10016. I've debugged the EA, and all stop loses and take profits seem to be alright with the difference of being stop loss 30 or 300 and take profit 100 or 1000 pibs above or below the current price.
I cannot find the reason why the server gives me an error 10016 when the STP and TKP are not multiplied by 10.
Anyone can explain me why the error happens or the purpose of multiplying by 10 when _Digits are 5 or 3?
Thanks for your help.
help, Is anybody here ?
why output error code :10030 ?
Hello,
Can you let us know how you get the error?
eshelios.sr:
First of all thanks for the article, It's helping me with getting started on mql5 programming.
I've tried your code and there's a bit of code on the OnInit() that I don't understand the purpose of it:
//--- Let us handle currency pairs with 5 or 3 digit prices instead of 4
STP = StopLoss;
TKP = TakeProfit;
if(_Digits==5 || _Digits==3)
{
STP = STP*10;
TKP = TKP*10;
}
This part modifies the values of take profit and stop loss pibs causing a difference between your input values and the ones really being used.
However, if I remove the two lines inside the if, then I often receive error 10016 (invalid stops) when sending the order to the server. The first attempt to place an order goes well and I get the 10009, but then most of the following times I get a 10016. I've debugged the EA, and all stop loses and take profits seem to be alright with the difference of being stop loss 30 or 300 and take profit 100 or 1000 pibs above or below the current price.
I cannot find the reason why the server gives me an error 10016 when the STP and TKP are not multiplied by 10.
Anyone can explain me why the error happens or the purpose of multiplying by 10 when _Digits are 5 or 3?
Thanks for your help.
Hello,
First from your explanation, when you removed those lines of code, you get an error and when you did not multiply the stoploss/takeprofit values by 10, you get an error? This I believe has explained that those lines of code are very important.
Back to the article, it explained those lines of code are necessary if you are using a chart with 5 decimal digits (0.XXXXX) or 3 decimal digits (0.XXX) currency pairs.
So here we want to make sure that our EA works very well with all brokers. Digits or Digits() returns the number of decimal digits determining the accuracy of price of the current chart symbol. For a 5-digit or 3-digit price chart, we multiply both the Stop Loss and the Take Profit by 10.
See examples below:
5 - Decimal Digits price
3 - Decimal Digits price
I hope this has answered your question.
Hello,
Can you let us know how you get the error?
step 1: download your this sample code.
step 2: compile it in mql5 .
step 3:in mt5,open chart eurusd 1m, then ,click "auto trading"
step 4:set break symbol in code line 223,224 etc...
step 5:click start debugging button in mt5, then,show this error.
step 1: download your this sample code.
step 2: compile it in mql5 .
step 3:in mt5,open chart eurusd 1m, then ,click "auto trading"
step 4:set break symbol in code line 223,224 etc...
step 5:click start debugging button in mt5, then,show this error.
Hello,
Thanks for sharing your steps. If I can take you back to the code,
if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
{
Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
}
else
{
Alert("The Buy order request could not be completed -error:",GetLastError()); // line 223
ResetLastError(); // line 224
return;
}
As far as I know, the code did what its supposed to do. You got the error because the order you tried to place was NOT SUCCESSFUL and that is what the line 223 was supposed to do. Please read this - https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes - to know what the error means. (Actually, 10030 means Invalid order filling type ).
To understand what the order filling type -ORDER_FILLING_FOK -
mrequest.type_filling = ORDER_FILLING_FOK; // Order execution type ( line 213 )
means, please read https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling
Hope this answered your question.
Hi Samuel,
I downloaded the code, installed it and ran it and I realized it's opening buy and sell orders mostly at every candle that meet the criteria (I'm using H1 as timeframe).
I did not debugging and realized some part of the codes are not triggered. Are you guys able to run the EA properly with the code available for download?