automatic lot-size calculating function? - page 4

 

Are the include file in the right file folder?

 
Antonsan:

Is it a bug that only happened to me?
I can not compile any file with MetaEditor mq4 if I put a line with # include.
Nor have I been able to compile mq4 files that have a line # include in the code.
Only enables lines
# Include <stderror.mqh>
# Include <stdlib.mqh>
# Include <WinUser32.mqh>

In addition to phillip's post:

IF above is what you have in code... please consider careful read of language docs.

NO whitespace between # and include

NO uppercase I ... use lowercase i

 

In the Analyze Currency file, I seem to have a problem with the SymbolType() method.

I am trading CADJPY, my accountcurrency() is USD, but it allways returns SymbolType = 6.

The reasons is that MarketInfo("USDJPY", MODE_LOTSIZE) always returns 0.

I can only get the LOT_SIZE for the current chart. ex. MarketInfo("CADJPY", MODE_LOTSIZE) works fine.

Is this an issue with MetaTrader, how come I can't get other pairs properties?

 

What broker are you using Ricotter? Do they offer USDJPY for you to trade?

Just to confirm your code is implemented correctly you should download FXDD and open a demo account and try your code on CADJPY. It should work if you have the include files setup correctly.

 
1005phillip:

What broker are you using Ricotter? Do they offer USDJPY for you to trade?

Just to confirm your code is implemented correctly you should download FXDD and open a demo account and try your code on CADJPY. It should work if you have the include files setup correctly.

I just did some more testing. I stripped everything, and in the start() function I only added the MarketInfo call. On live trading, it works fine, but when I use the tester, it returns 0 for anything other than the symbol I am running the test on.

I will test it with FXDD, thanks.

 
Ricotter:

I just did some more testing. I stripped everything, and in the start() function I only added the MarketInfo call. On live trading, it works fine, but when I use the tester, it returns 0 for anything other than the symbol I am running the test on.

I will test it with FXDD, thanks.

Same thing with FXDD. If I try to call MarketInfo("USDJPY", MODE_LOTSIZE) while running the tester against the CADJPY pair, it returns 0. I even downloaded the history for USDCAD and USDJPY.

 
Ricotter:

Same thing with FXDD. If I try to call MarketInfo("USDJPY", MODE_LOTSIZE) while running the tester against the CADJPY pair, it returns 0. I even downloaded the history for USDCAD and USDJPY.

MarketInfo() only works for tested symbol in the Tester. See all Tester limitations here -> https://www.mql5.com/en/articles/1512.
 
gordon:
MarketInfo() only works for tested symbol in the Tester. See all Tester limitations here -> https://www.mql5.com/en/articles/1512.

Thanks!

 

The code will do multiple things for you, it is symbol() agnostic, and it will compute the max lotsize to take for a position based on the equity you are willing to risk and the stoploss price. Once you have that lotsize value it can also compute for you the profit potential based on your takeprofit price.

It computes the crosses correctly as well, which is what you were after...however you need to be aware that you cannot correctly backtest on crosses because of a fundamental design limitation of MT4's backtester which prevents your EA from accessing the historical price data for other currency pairs during the backtest. In practice what this means is that all monetary valuations that come from trading cross-pairs in a backtest are fundamentally wrong, meaning the profit/loss of the trades themselves when converted into the account's currency by the backtester are simply wrong.

The code I linked to computes them correctly, analytically, no shortcuts taken. But they can't be used in backtesting on crosses because the code will try and calculate market valuations correctly and the backtester will prevent it from doing so and as such the code will simply return error alerts (as it would in real-life forward testing if the broker somehow broke their currency definitions).

 
1005phillip:

The code will do multiple things for you, it is symbol() agnostic, and it will compute the max lotsize to take for a position based on the equity you are willing to risk and the stoploss price. Once you have that lotsize value it can also compute for you the profit potential based on your takeprofit price.

It computes the crosses correctly as well, which is what you were after...however you need to be aware that you cannot correctly backtest on crosses because of a fundamental design limitation of MT4's backtester which prevents your EA from accessing the historical price data for other currency pairs during the backtest. In practice what this means is that all monetary valuations that come from trading cross-pairs in a backtest are fundamentally wrong, meaning the profit/loss of the trades themselves when converted into the account's currency by the backtester are simply wrong.

The code I linked to computes them correctly, analytically, no shortcuts taken. But they can't be used in backtesting on crosses because the code will try and calculate market valuations correctly and the backtester will prevent it from doing so and as such the code will simply return error alerts (as it would in real-life forward testing if the broker somehow broke their currency definitions).

This guy does it using file history.

https://www.mql5.com/en/articles/1493

Reason: