Margin higher than expected

Created at 15 Jul 2023, 02:46
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!
FR

friedrich.sonntag

Joined 15.07.2023

Margin higher than expected
15 Jul 2023, 02:46


 

Hello dear ctradudes and dudenes,

I am coding on my cbots for quite some time now, and there is one part of which I cannot wiggle my head around.
And unfortunately I am not able to find help in the questions from others.

If I open a position, the Margin of the Position is higher than I formerly have calculated.


double wantedMargin = 50;
double wantedMarginInCorrectAsset = AssetConverter.Convert(wantedMargin, Assets.GetAsset("EUR"), Symbol.QuoteAsset);

double helper = wantedMarginInCorrectAsset / Symbol.Ask; // since Symbol.Ask is in Symbol.QuoteAsset
double volume = helper * Leverage;  // in my case 5
double normVolume = Symbol.NormalizeVolume(volume, RoundingMode.Down); // to not exceed bugdet

TradeResult result = executeMarketOrder(TradeType.Buy, Symbol, normVolume, "myLabel");

// BUT after succesfull opening:
// result.Position.Margin == 66.07 != 50 == wantedMargin
//
// WHY?

I am struggeling with this task for a long time now, and hopefully someone can help.
All kind of related threads are always forex trades and I am not sure how that changes something if I trade a stock.

Base question is how to get the correct value that executeMarketOrder expects with a given amount of margin I want to invest?

All the best to you!


 


@friedrich.sonntag