Margin Level

Created at 27 Jul 2019, 15:36
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!
RY

ryanoia@gmail.com

Joined 09.03.2018

Margin Level
27 Jul 2019, 15:36


Hello,

Is there any way to prevent the cbot from executing market orders if the resulting margin level due to the opening of the said position results in a less than x % margin level, where x is a user-defined parameter?

Thanks for the assistance, if any. 


@ryanoia@gmail.com
Replies

firemyst
22 Sep 2019, 15:53

RE:

ryanoia@gmail.com said:

Hello,

Is there any way to prevent the cbot from executing market orders if the resulting margin level due to the opening of the said position results in a less than x % margin level, where x is a user-defined parameter?

Thanks for the assistance, if any. 

You can easily check the margin levels before entering a position.

Code sample below:

if (Account.MarginLevel.HasValue && Account.MarginLevel >= minimumMarginLevelsToEnterPositions)
{
   //place your orders here
}

Otherwise, the only way I know of is immediately after executing your order successfully, check the margin levels and if it's below the threshold, close the position.

Example:

TradeResult r = ExecuteMarketOrder( .... );
if (r.IsSuccessful && Account.MarginLevel < minimumMarginLevelParameter)
{
   //close the position and anything else you want to do
}

 


@firemyst

ryanoia@gmail.com
22 Sep 2019, 16:41

Thanks for the response. I know how to do that too but did not consider this because it doesn't prevent the bot from opening positions in the first place.


@ryanoia@gmail.com

PanagiotisCharalampous
23 Sep 2019, 09:04

Hi ryanoia@gmail.com,

To do so you will first need to calculate the required margin of a new position. This thead might give you some guidance.

Best Regards,

Panagiotis


@PanagiotisCharalampous

ctid2434759
03 Jan 2023, 02:53

RE:

Hi Ryanoia,

Did you figure out a way to do this? This is exactly what I'm stuck on.

Do not fill new order if the resulting margin level due to the opening of said positions results in a less than x% margin level, were x is a user defined parameter.


@ctid2434759