I am testing my program and getting errors 130 and 4051.
I have attached my code so could someone more experienced have a look.
This is my first program so please could you not judge me for beginner mistakes.
The file you attached is an "executable" and not your source code, so there is very little we can do to help you except to guess what the problem is.
However, in another of your forum topics (probably double posting) you were already informed of some of the bugs in your source code (which you seem to want to ignore).
The usual suspects are (for MQL4 in this case):
- Not using the proper predefined codes for type of order: OP_BUY, OP_SELL, etc.
- Using the wrong opening or closing price for the order type: Buy Orders open with Ask and close with Bid, while Sell Orders open with Bid and close on Ask.
- Not checking your brokers conditions for minimum stop size, etc. Market conditions such as STOP_LEVEL and FREEZE_LEVEL, etc.
- Although not related to these specific error codes, you should also check the Volume conditions of the broker while you are at.
Please also read the documentation again and especially the Requirements and Limitations in Making Trades!
- book.mql4.com
The file you attached is an "executable" and not your source code, so there is very little we can do to help you except to guess what the problem is.
However, in another of your forum topics (probably double posting) you were already informed of some of the bugs in your source code (which you seem to want to ignore).
The usual suspects are (for MQL4 in this case):
- Not using the proper predefined codes for type of order: OP_BUY, OP_SELL, etc.
- Using the wrong opening or closing price for the order type: Buy Orders open with Ask and close with Bid, while Sell Orders open with Bid and close on Ask.
- Not checking your brokers conditions for minimum stop size, etc. Market conditions such as STOP_LEVEL and FREEZE_LEVEL, etc.
- Although not related to these specific error codes, you should also check the Volume conditions of the broker while you are at.
Please also read the documentation again and especially the Requirements and Limitations in Making Trades!
I have attached the other file i have for my program.
With the other topic i took it into advice and corrected the issue but currently there is a different issue.
In future, please continue to use your original topic when doing a follow-up instead of starting a new thread.
As mentioned on the other thread as well as here, please use the predefined constants and not hard coded values for OP_BUY, OP_SELL, etc.
This also goes for all the other hard-coded values you are using in calculations. Use variables so that you correct problems and adjust values more easily.
Also, make sure that your price quotes, such as the Stop-Loss and Take-Profit are properly aligned to the Tick size.
... double tickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE ); ... double normalised_price = round( price / tick_size ) * tick_size; ... // Or use a function double Round2Ticksize( double price ) { double tick_size = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE ); return( round( price / tick_size ) * tick_size ); }
In order to continue, please correct the issues I have already pointed out first, before posting your corrected code here again for review.
Here are some further details from other threads with regards to some of the points I outlined in my previous post:
Forum on trading, automated trading systems and testing trading strategies
Fernando Carreiro, 2017.08.26 02:02
Are you referring to the Broker's "Stops Level"? If so, then you can use:
- For old style, pure MQL4: MarketInfo() function with the "MODE_STOPLEVEL" identifier
MODE_STOPLEVEL
14
Stop level in points
A zero value of MODE_STOPLEVEL means either absence of any restrictions on the minimal distance for Stop Loss/Take Profit or the fact that a trade server utilizes some external mechanisms for dynamic level control, which cannot be translated in the client terminal. In the second case, GetLastError() can return error 130, because MODE_STOPLEVEL is actually "floating" here.
- For MQL4+/5 (recommended solution for compatibility in both versions): SymbolInfoInteger() function with "SYMBOL_TRADE_STOPS_LEVEL"
SYMBOL_TRADE_STOPS_LEVEL
Minimal indention in points from the current close price to place Stop orders
int
Forum on trading, automated trading systems and testing trading strategies
Fernando Carreiro, 2016.06.19 21:54
I have already replied to that question - learn about STOP-LEVEL and FREEZE-LEVEL, conditions which are set by your broker that affect the placement and minimum sizes for Stop-Loss and Take-Profit.
For example, if I trade the AUD/CAD currency pair on RoboForex's Pro-Standard (non-ECN account), the minimum stop size (also known as STOP-LEVEL), is 8 pips.
So, look at your broker's Contract Specifications to see what the minimum stop size is for the currency pair you were using. It is probably 7 pips and that will explain your problem.
Before setting a Stop-Loss or a Take Profit you should always take into account the values of "MarketInfo( _Symbol, MODE_STOPLEVEL )" and "MarketInfo( _Symbol, MODE_FREEZELEVEL )".
Forum on trading, automated trading systems and testing trading strategies
How to calculate lots using multiplier according to number of opened orders?
Fernando Carreiro, 2017.09.01 21:57
Don't use NormalizeDouble(). Here is some guidance (code is untested, just serves as example):
// Variables for Symbol Volume Conditions double dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN ), dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX ), dblLotsStep = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP ); // Variables for Geometric Progression double dblGeoRatio = 2.8, dblGeoInit = dblLotsMinimum; // Calculate Next Geometric Element double dblGeoNext = dblGeoInit * pow( dblGeoRatio, intOrderCount + 1 ); // Adjust Volume for allowable conditions double dblLotsNext = fmin( dblLotsMaximum, // Prevent too greater volume fmax( dblLotsMinimum, // Prevent too smaller volume round( dblGeoNext / dblLotsStep ) * dblLotsStep ) ); // Align to Step value
I am testing my program and getting errors 130 and 4051.
I have attached my code so could someone more experienced have a look.
This is my first program so please could you not judge me for beginner mistakes.
Error 130 is INVALID STOP
130 |
ERR_INVALID_STOPS |
Invalid stops |
See this page.
https://docs.mql4.com/constants/errorswarnings/enum_trade_return_codes
- docs.mql4.com
In future, please continue to use your original topic when doing a follow-up instead of starting a new thread.
As mentioned on the other thread as well as here, please use the predefined constants and not hard coded values for OP_BUY, OP_SELL, etc.
This also goes for all the other hard-coded values you are using in calculations. Use variables so that you correct problems and adjust values more easily.
Also, make sure that your price quotes, such as the Stop-Loss and Take-Profit are properly aligned to the Tick size.
In order to continue, please correct the issues I have already pointed out first, before posting your corrected code here again for review.
Here are some further details from other threads with regards to some of the points I outlined in my previous post
Could you please explain what tick size is.
The tick size is the minimum price change or step for a symbol in question. For example, for the S&P500, the tick size is 0.25 and for the EUR/USD it is 0.0001 (4-digit broker) or 0.00001 (5-digit broker).
Please note that this is not the same as point size in MetaTrader, even though in forex they are the same value, but for several other symbols they can be different.
It seems that you are are unaware of certain key concepts for both Trading and Coding. I suggest that you first dedicate some time researching both the Trading concepts as well as the Coding basics as well.
Read the Online Documentation and use the search feature both on this site and on Google (or other search engine) to help find the information you need.
There are also several good books to read, mentioned in the following Forum topic:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am testing my program and getting errors 130 and 4051.
I have attached my code so could someone more experienced have a look.
This is my first program so please could you not judge me for beginner mistakes.