Suspend Trading after a Loss Limit Using Real-Time P&L

CQG's backtesting does not have the ability to feed P&L information back into the trading system itself. The autotrading environment, however, has a solution for that: the P&L Study.

Profit & Loss (P&L) Study

The Profit & Loss Study is one of several trading studies. It has a single output representing profit and loss of any specific account or all accounts.

Currency is determined by contract and account:

  • For a specific contract, the currency of the contract is used.
  • For a specific account and all contracts, the reporting currency of the specified account is used. If it is not specified, USD is used.
  • For all accounts and all contracts, USD is used.

For the current trading day, P&L is calculated for the bar time.

P&L Parameters

In my trading system I just add the additional rule that trading is only allowed if the P&L of the account I will be running autotrading on is greater than the maximum loss I want.

In this case I am running on account “PS1006” and if the closed P&L is greater than 1000€ (DAX Future), it continues to trade. If it falls below that level, it stops.

Caution: There is one bar delay in that information.

I am using a simple Slow Stochastic reverse system here. So on the bar that triggers the long exit, it also goes short.There was already a 1400€ loss displayed, but because the realized loss is only known after the position is closed, and at the same moment the new position is already opened, it did not prevent the trade. If the new trade would have happened one bar later, it would have been prevented.

So in the real world you need to set your “discard trading level” a little bit closer than you actually want. In this example it allowed one more trade and the total loss was 1837€ before actually stopping the autotrade.

It is wise to have the P&L Study displayed at all times to visualize what is happening.

If I want to resume trading now on the same account, first I have to turn off autotrading manually. Second, I have to set up a new value in the Formula Toolbox, taking the loss we had already experienced into account. It will be very useful to use a parameter for the “discard trading level” in order to avoid going into the code all the time.

This time I did not attach a pac; you just need to add the ONE line to every trade of your own trading system and set it up with the correct account and value.

Learn more from CQG HTML Help