What if this happens when trading?🥶

Posted By: AdamWu

What if this happens when trading?🥶 - 07/29/20 02:59

I have my startegy ready. But onece I start tarding, I must know what will happen and how to hanle them. To make things clear, I made a flow chart:
[Linked Image]

And there are two questions inside:
Question1: If manually changed the balance, should the “Balance” value in the code be changed accordingly?
Question2: Will close some trades by hand harm the startegy? What is the correct way to handle this?

Attached picture when trade.jpg
Posted By: AndrewAMD

Re: What if this happens when trading?🥶 - 07/29/20 03:28

Easy:
Margin call, add money, margin call, add money... tongue
Posted By: AdamWu

Re: What if this happens when trading?🥶 - 07/29/20 04:52

How about the "Balance" value? Should I make a bar to refelct how much I add or draw out?
Posted By: AndrewAMD

Re: What if this happens when trading?🥶 - 07/29/20 20:13

During live trading, yes, your broker plugin will update the Balance and Equity values. (Unless you override this behavior using the SET_PATCH broker command.)

Now, if you want to simulate it in a backtest instead, manually changing the Balance value does not work. Instead, consider applying credits and debits to your account using enterTrade(). I explain how to do this on my blog:
https://www.vitaltrades.com/2020/07/14/adding-exact-fee-and-credit-calculations-to-zorro/
Posted By: AdamWu

Re: What if this happens when trading?🥶 - 07/29/20 22:33

Thanks a lot. It is much more clear now. 👍
Posted By: Grant

Re: What if this happens when trading?🥶 - 07/29/20 22:43

I believe it's best to limit the risk of a margin call to a minimum by implementing this into your strategy. For example with proper money management and with a diversified portfolio.

To make sure my strategy is prone to margin calls, I've included this into my code:

Code
if(Equity - MarginVal < 0)
    {
    printf("\n***CRITICAL***");
    printf("\nMargin Call: Margin (%.2f) >= Equity (%.2f)", MarginVal, Equity);
    printf("\nTheoretical Equity should be: 'Balance(%.2f) + WinValTotal(%.2f) - LossValTotal(%.2f)'", Balance, WinValTotal, LossValTotal);
    quit()//(Optional);	
    }
Posted By: AdamWu

Re: What if this happens when trading?🥶 - 07/30/20 07:59

Hi Grant, good points. So your strategy just stop there and manually deal with margin call and open positions? If there are 30 open positions, it is not easy to handle by hand.
How about red alert earlier but don't quit the strategy. Add some money and let stragtegy go on?
Posted By: Grant

Re: What if this happens when trading?🥶 - 07/30/20 09:45

Hi Adam,

I only use this rule in my test strategy, not the production version.
In case you receive a margin call, it's too late to fund your account anyway.

By using a brokerCommand -> GET_POSITION (see https://zorro-project.com/manual/en/brokercommand.htm), you can validate which positions are still active.

Yeah, you can add an alert warning. For example when your margin reaches 80% of your available funds:

Code
if(MarginVal / Equity > 0.8)
Posted By: AdamWu

Re: What if this happens when trading?🥶 - 07/30/20 23:13

Thanks, I will implement this feature into my strategy. 👍👍👍
© 2024 lite-C Forums