Account.Margin not correct : Unacceptable

Created at 16 Aug 2023, 08:22
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
NC

ncel01

Joined 19.03.2020

Account.Margin not correct : Unacceptable
16 Aug 2023, 08:22


Dear cTrader Team,

I noticed that Account.Magin, Account.FreeMargin, Account.MarginLevel, etc., do not return the correct values.

This happens (at least) when backtesting with indices.

I wonder how it is possible that, at this stage, Spotware did not manage to have this fully functional, as these are the most basic calculations in trading, as well as the most important when it comes to risk management.

As you might understand, it is more than legitimate for any trader to question abut cTrader reliability when, after more than 10 years, traders cannot even rely on such a basic trading information.

Suggestion: Maybe it's time to stop with superfluous features, graphics, etc., and start focusing on the essential.

I do not know about your business but, as I've already mentioned in the past, traders need an effective trading solution above anything described as visually “beautiful”.

Thanks for your understanding.


@ncel01
Replies

firemyst
17 Aug 2023, 01:01

Evidence?

Screen captures showing the issue?

 


@firemyst

Spotware
17 Aug 2023, 04:56

Dear ncel01,

Please provide us with exact steps to reproduce the problem.

Best regards,

cTrader Team


@Spotware

ncel01
17 Aug 2023, 05:36

Hi to both,

Does that mean you were not able to reproduce the problem or, you didn't even try to?

You can always compare Account.Margin with its calculated value (by applying its formula), through prints, whenever a position is opened/closed.

I guess there's no big science behind it.


@ncel01

firemyst
17 Aug 2023, 06:43

RE: Account.Margin not correct : Unacceptable

ncel01 said: 

Hi to both,

Does that mean you were not able to reproduce the problem or, you didn't even try to?

You can always compare Account.Margin with its calculated value (by applying its formula), through prints, whenever a position is opened/closed.

I guess there's no big science behind it.

Why would anyone have tried when you didn't show what was wrong (through screen captures) or explain how such values were wrong?

Basically, if you can't take the time to explain/show the details, nobody is going to waste their time trying to find an alleged needle-in-a-haystack that nobody else seems to have reported.


@firemyst

ncel01
17 Aug 2023, 10:20 ( Updated at: 17 Aug 2023, 10:24 )

Explain what, exactly? That Account.Margin does not return the right value when backtesting indices? I did it.

Needle-in-a-haystack?

Account.Margin is an API property and you're making it something very abstract. More precisely, you're making a drama out of something really simple:

Print(Account.Margin);

It can be a needle-in-a-haystack if you can't see any issue when trying the above, however, it should not a big deal to try it. Is it?

Anyway, at the end it is up to you to check this or not. If this is for you a detail for you feel free to not check it.

If I had to provide evidence on every cTrader issue I would need to work full time on it, however, this is not an option since I already have a 8/5 job.


@ncel01

PanagiotisChar
17 Aug 2023, 11:01

Hi @ncel01,

I would have had a look at this too but I am not in a mood to interrogate you or figure out what you are doing. For some unknown reason, you never have time to share the information requested from you by others but you have the time to write tens of lines of moaning comments. 

I have been on this forum for so many years and believe me most of your problems would have been solved 10x faster if you had been 10% more cooperative. But for an unknown reason you always seem to choose the collision path. Good luck with this


@PanagiotisChar

ncel01
17 Aug 2023, 12:49

Hi Panagiotis,

You never have time to share the information requested.

That's definitely not true.

Please feel free to share a single thread where I haven't provide any evidence.

On the other hand, I remember that, I've already provided evidence in the past and that I didn't get any feedback from you afterwards. So, I really have some difficulty in understanding your concept of being cooperative.

Moaning comments: I have no idea what you mean by that and, to be honest, I prefer not to know.

I am still totally willing to provide evidence on this, that's not the point. If someone (including Spotware) is not able to reproduce this by simply printing Account.Margin, I'll be glad to provide any further details as I've already done many times in the past.

Account.Margin is an API property. Something generic that has nothing to do with my code. That's why I didn't feel a need to provide any further details in advance regarding this. It's not that I don't want to nor that I am not willing to do it. As simple as that.


@ncel01

ncel01
17 Aug 2023, 18:14 ( Updated at: 21 Dec 2023, 09:23 )

Dear cTrader Team,

Below is a very basic cBot sample that will allow you to check this.
I've also added some screenshots for your reference.

My questions:

  1. How come that symbol leverage is higher than that of the account? Even for a demo account you should agree that this does not make any sense at all.
  2. What formula is used to calculate Account.Margin?
    As you can see, even when there are open positions, zero is returned. Also, this returns completely different results from those provided by the given formula, regardless of what leverage (as mentioned above) is used in the calculation.

Should I provide you with any additional information please let me know.

Thanks for clarifying.

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class MarginTest : Robot
    {
        protected override void OnStart()
        {
            Positions.Opened += Positions_Opened;
            Positions.Closed += Positions_Closed;

            Print("Symbol leverage : ", Symbol.DynamicLeverage[0].Leverage);
            Print("Account leverage : ", Account.PreciseLeverage);
            Print("Symbol currency : ", Symbol.QuoteAsset);
            Print("Account currency : ", Account.Asset);
            Print("Symbol pip size : ", Symbol.PipSize);

            PlaceLimitOrder(TradeType.Buy, SymbolName, Symbol.QuantityToVolumeInUnits(1), Symbol.Ask - 300, null, 1500 * Symbol.PipSize, 1500 * Symbol.PipSize);
            PlaceLimitOrder(TradeType.Buy, SymbolName, Symbol.QuantityToVolumeInUnits(1), Symbol.Ask - 600, null, 1500 * Symbol.PipSize, 1500 * Symbol.PipSize);
        }

        private void Positions_Opened(PositionOpenedEventArgs obj)
        {
            Print("**************** Positions_Opened ****************");
            Print("Amount of open positions : ", Positions.Count);

            double tradesTotalSize = 0;
            double accountMargin;

            foreach (var position in Positions)
                tradesTotalSize += position.VolumeInUnits * position.EntryPrice;

            accountMargin = tradesTotalSize / Symbol.DynamicLeverage[0].Leverage;

            Print("Calculated account margin : {0:0.00}", accountMargin);
            Print("Account.Margin : ", Account.Margin);

            Print("Error (%) : {0:0.0}", 100 * (1 - Account.Margin / accountMargin));
        }

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
            if (PendingOrders.Count == 0 && Positions.Count == 0)
                Stop();
        }
    }
}

@ncel01

ncel01
31 Aug 2023, 08:57

cTrader Team,

Any update on this?

Thanks for informing.


@ncel01

Spotware
31 Aug 2023, 10:33

RE: Account.Margin not correct : Unacceptable

ncel01 said: 

cTrader Team,

Any update on this?

Thanks for informing.

Dear ncel01,

We have identified the issue and it will be resolved in an upcoming update.

Best Regards,

cTrader Team


@Spotware

ncel01
31 Aug 2023, 11:00

RE: RE: Account.Margin not correct : Unacceptable

Spotware said: 

ncel01 said: 

cTrader Team,

Any update on this?

Thanks for informing.

Dear ncel01,

We have identified the issue and it will be resolved in an upcoming update.

Best Regards,

cTrader Team

cTrader Team,

Great. Thanks for the update!


@ncel01

ncel01
06 Aug 2024, 21:22 ( Updated at: 07 Aug 2024, 05:28 )

Dear cTrader Team,

It seems that after a year this issue still remains.
Has this been overlooked, maybe?


@ncel01

ncel01
15 Aug 2024, 16:01

?


@ncel01

PanagiotisCharalampous
16 Aug 2024, 08:37

RE: Account.Margin not correct : Unacceptable

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 


@PanagiotisCharalampous

ncel01
16 Aug 2024, 12:13 ( Updated at: 16 Aug 2024, 12:15 )

RE: RE: Account.Margin not correct : Unacceptable

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.


@ncel01

PanagiotisCharalampous
16 Aug 2024, 13:54

RE: RE: RE: Account.Margin not correct : Unacceptable

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.

Hi ncel01,

Yes I do

 

However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.

 


@PanagiotisCharalampous

ncel01
20 Aug 2024, 11:08 ( Updated at: 20 Aug 2024, 11:11 )

RE: RE: RE: RE: Account.Margin not correct : Unacceptable

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.

Hi ncel01,

Yes I do

 

However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.

 

Panagiotis,

The functionality should work correctly when the option is checked.

How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position?
Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?

Thanks.


@ncel01

PanagiotisCharalampous
21 Aug 2024, 05:16

RE: RE: RE: RE: RE: Account.Margin not correct : Unacceptable

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.

Hi ncel01,

Yes I do

 

However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.

 

Panagiotis,

The functionality should work correctly when the option is checked.

How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position?
Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?

Thanks.

Hi ncel01,

It works fine on Variance as well. 

Please send a full screenshot like the above, so that we can understand what you are doing


@PanagiotisCharalampous

ncel01
21 Aug 2024, 17:49

RE: RE: RE: RE: RE: RE: Account.Margin not correct : Unacceptable

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.

Hi ncel01,

Yes I do

 

However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.

 

Panagiotis,

The functionality should work correctly when the option is checked.

How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position?
Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?

Thanks.

Hi ncel01,

It works fine on Variance as well. 

Please send a full screenshot like the above, so that we can understand what you are doing

Hi Panagiotis,

Thanks for looking into this again. I meant an account with a different broker, not exactly the broker version of cTrader.
So far, I found that Account.Margin is not correct in the following cases (at least):

  • Example 1: Any live account (tested with Pepperstone and TopFX)
  • Example 2: New demo accounts (without trading activity) where Symbol Leverage > Account Leverage (tested with Varianse)

I've added a screenshot for each of these examples (see below). I am running the cBot shared above (historical data is checked).
Note that, regardless of what leverage is considered (symbol/account), the calculated account margin does not match Account.Margin in any of the cases shown.

Something is clearly not going as expected here.
The results show that there is not a unique/consistent calculation for Account.Margin, no matter the situation.

Example 1:

Example 2:
 

Something else I noticed in the meantime that I also don't understand: Positions.Count is returning 0 while called inside Positions_Opened().
See below.


@ncel01

PanagiotisCharalampous
22 Aug 2024, 05:26

RE: RE: RE: RE: RE: RE: RE: Account.Margin not correct : Unacceptable

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.

Hi ncel01,

Yes I do

 

However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.

 

Panagiotis,

The functionality should work correctly when the option is checked.

How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position?
Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?

Thanks.

Hi ncel01,

It works fine on Variance as well. 

Please send a full screenshot like the above, so that we can understand what you are doing

Hi Panagiotis,

Thanks for looking into this again. I meant an account with a different broker, not exactly the broker version of cTrader.
So far, I found that Account.Margin is not correct in the following cases (at least):

  • Example 1: Any live account (tested with Pepperstone and TopFX)
  • Example 2: New demo accounts (without trading activity) where Symbol Leverage > Account Leverage (tested with Varianse)

I've added a screenshot for each of these examples (see below). I am running the cBot shared above (historical data is checked).
Note that, regardless of what leverage is considered (symbol/account), the calculated account margin does not match Account.Margin in any of the cases shown.

Something is clearly not going as expected here.
The results show that there is not a unique/consistent calculation for Account.Margin, no matter the situation.

Example 1:

Example 2:
 

Something else I noticed in the meantime that I also don't understand: Positions.Count is returning 0 while called inside Positions_Opened().
See below.

Hi ncel01,

As far as I can see, in all the cases with discrepancy, your account currency is different to the symbol currency, however your calculations do not include any conversion logic. The API's property converts the margin to the account's currency value. The XTE issue seems a separate issue, can you report it in a different thread?

Best regards,

Panagiotis


@PanagiotisCharalampous

ncel01
24 Aug 2024, 17:31

RE: RE: RE: RE: RE: RE: RE: RE: Account.Margin not correct : Unacceptable

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.

Hi ncel01,

Yes I do

 

However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.

 

Panagiotis,

The functionality should work correctly when the option is checked.

How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position?
Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?

Thanks.

Hi ncel01,

It works fine on Variance as well. 

Please send a full screenshot like the above, so that we can understand what you are doing

Hi Panagiotis,

Thanks for looking into this again. I meant an account with a different broker, not exactly the broker version of cTrader.
So far, I found that Account.Margin is not correct in the following cases (at least):

  • Example 1: Any live account (tested with Pepperstone and TopFX)
  • Example 2: New demo accounts (without trading activity) where Symbol Leverage > Account Leverage (tested with Varianse)

I've added a screenshot for each of these examples (see below). I am running the cBot shared above (historical data is checked).
Note that, regardless of what leverage is considered (symbol/account), the calculated account margin does not match Account.Margin in any of the cases shown.

Something is clearly not going as expected here.
The results show that there is not a unique/consistent calculation for Account.Margin, no matter the situation.

Example 1:

Example 2:
 

Something else I noticed in the meantime that I also don't understand: Positions.Count is returning 0 while called inside Positions_Opened().
See below.

Hi ncel01,

As far as I can see, in all the cases with discrepancy, your account currency is different to the symbol currency, however your calculations do not include any conversion logic. The API's property converts the margin to the account's currency value. The XTE issue seems a separate issue, can you report it in a different thread?

Best regards,

Panagiotis

Hi Panagiotis,

You're completely right, I messed it up. Please disregard the examples 1 and 2 above!
My apologies for the hassle!

Regarding Positions.Count = 0, I'll create a new post, as suggested.
I believe this can be related to my screenshot above, where Positions.Count = 1, while Account.Margin = 0. However, on that example, I was using a Varianse account.
Unfortunately, I am no longer able to reproduce that issue again.

Thank you once gain! 


@ncel01