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.
Replies
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

ctid+customer-395444
22 Sep 2019, 15:53
RE:
ryanoia@gmail.com said:
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 }@ctid+customer-395444