How to limit max contracts AA mode

Questions about MultiCharts and user contributed studies.
tpredictor
Posts: 102
Joined: 05 Mar 2014
Has thanked: 1 time
Been thanked: 11 times

How to limit max contracts AA mode

Postby tpredictor » 07 Sep 2021

I was testing a strategy in live today in AA mode. This was a simple test strategy that open a new position on every bar and set a small tick profit target. It was set to only allow 1 position-- not multiple entries. In the code, I check the market position (not market position at broker nor market strategy position) and it look like my strategy was opening multiple contracts.

Questions

(1) Is this expected behavior?
(2) For risk control and limited the # of contracts should I use MarketPosition_at_Broker_for_The_Strategy?
(3) Is there a guide how to protect myself/recode for backtesting to live when running in MC in AA mode? I do not recall having to do this when automating in TS.
(4) As well --- not tested yet, if I set a 5 tick target and the broker fills 1 tick worse then strategy, will the profit target still be +5 ticks? This is my desired behavior.

I noticed also that MC did not ask that my account was setup on the dialog but only after the strategy was running. Suggest that you test that in the dialog and not allow to close or start the strategy without the account set (this was for rithmic) because as is, I would miss trades for an error that ca be caught on configuration.

tpredictor
Posts: 102
Joined: 05 Mar 2014
Has thanked: 1 time
Been thanked: 11 times

Re: How to limit max contracts AA mode

Postby tpredictor » 07 Sep 2021

Also I read "setstoploss/setprofittarget" works from broker fill but when I wrap my strategy logic like so:

>>if MarketPosition_at_Broker_for_The_Strategy = 0 then begin

It looks like the entryprice was lost/profit target set to zero. Will continue to test some more. But maybe I am going down the wrong path because my strategies are pretty basic. Perhaps I should not need to do the broker keywords?

tpredictor
Posts: 102
Joined: 05 Mar 2014
Has thanked: 1 time
Been thanked: 11 times

Re: How to limit max contracts AA mode

Postby tpredictor » 08 Sep 2021

Update

(A) it looks like it is just something the trader order manager does when filled to set the price to zero.

(B) My question is really though when running in AA mode should I need to recode to look at broker position or is this something rare. Is there a list of safe guards I can set in the code for limiting # of contracts or common other mistakes? Another thing is it says that the profit target always uses the broker price but in the strategy orders manager I don't think they matched. It looks like my code got into this situation due to limit order not filled and/or order entry sent at same time due to testing code. Is there a template I can use to add "safe" checks in my code somewhere? It look like it would just keep adding contracts. If I recode to use the MP for broker SP then my code won't work in backtest.

I guess what I am getting at is there a universal pattern when using MP at broker that won't break the backtest or is it really required I use MP at broker if I use certain "other constraints"?

It seems that most sync errors occur due to limit orders. The way I would *like* for limit orders to work is they don't fill unless filled at broker. This is what NT 8 does I believe and that works well for most tick strategies. So, I do not need why we exactly we need a "seconds filled" setting for though.

User avatar
Vlada MultiCharts
Posts: 242
Joined: 22 Apr 2020
Has thanked: 8 times
Been thanked: 54 times

Re: How to limit max contracts AA mode

Postby Vlada MultiCharts » 14 Sep 2021

Hello,

We can recommend to use SA mode to avoid the situation of chart/broker asynchronization.
Please check our Wiki article describing the peculiarities of Asynchronous Auto Trading (AA) and Synchronous Auto Trading (SA) mode.

tpredictor
Posts: 102
Joined: 05 Mar 2014
Has thanked: 1 time
Been thanked: 11 times

Re: How to limit max contracts AA mode

Postby tpredictor » 14 Sep 2021

Thanks but it reads that SA mode cannot support running multiple strategies on the same symbol-- given that most serious traders will be running multiple strategies more documentation/help on AA mode should be added.


Return to “MultiCharts”