How does Portfolio Trader handle Postrade______ functions?  [SOLVED]

Questions about MultiCharts and user contributed studies.
denniswklam
Posts: 5
Joined: 22 Nov 2016
Has thanked: 4 times

How does Portfolio Trader handle Postrade______ functions?

Postby denniswklam » 12 Dec 2019

Dear MC Support Team,

I am studying how to use Portfolio Trader and planning to setup a portfolio similar to Portfolio Rank Signal example. I am planning to use a custom benchmark function which was coded to employ

"PosTradeCount(), PosTradeEntryBar(), PosTradeExitBar(), PosTradeProfit(), PosTradeEntryPrice(), TotalTrades, etc." functions

for "Input: Formula( )" in the Base Signal.

However, I wish to clarify how does PT handle the output of these functions in different modes (Backtesting, Optimization, Auto Trading Mode) regarding the historical data and real-time data before I actually starting the project.

My assumptions under Backtesting Mode:
1) I assume in backtesting & optimization mode, PT will use the historical data to generate "hypothetical trades" for every instrument within a strategy, before the Money Management Signal determines if order instructions are really allowed for each instrument according to the ranking rule sorted the output values of each instrument from my custom benchmark function, which relies on PosTrade_____ functions.

2) I assume the PosTrade____ functions will return the hypothetical trade records for each instrument disregard whether the Money Management Signal disallowing order instructions to go through if its a low priority instrument.

My Questions:
1) Are my assumptions correct?
2) What about the case for optimization mode?
3) In Auto Trade Mode, how does PT handle these PosTrade____ functions return?
4) As I assume real trade order is started only after Auto Trade is turned on, but no actual trades has been started before Auto Trade Mode is on. Will PosTradeCount(n) always be zero right after Auto Trade is turned on? And without any completed trade, does my custom benchmark function simply not work and can't return any value for money management signal to rank?
5) Assuming my custom benchmark function does work to output indicative values for ranking in MM, as MM signal is supposed to disallow order instructions for those low priority instruments. Does PosTrade____ function of these disallowed instrument eventually return its hypothetical trades records or nil in backtesting and auto trading mode?

Thanks in advance.
DL

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: How does Portfolio Trader handle Postrade______ functions?

Postby Svetlana MultiCharts » 17 Dec 2019

Hello, denniswklam

Calculation of signals does not depend on the mode. The calculation is the same in backtesting, optimization and auto trading. The difference is that the orders are sent to the broker in auto trading.
There is no such term as "hypothetical trades". The strategy generates orders as specified in its algorithm. MM signal can only disallow an order or reduce its size. If an order was generated and went through all checks, it will be sent for execution in the Backtesting Engine or in the Auto Trading system (if auto trading is turned on).
PosTrade keywords work with filled orders only, they do not count any hypothetical orders. By “Filled” we mean the orders executed in backtesting or auto trading.

Answers to your questions:
1) Are my assumptions correct?
No.
2) What about the case for optimization mode?
3) In Auto Trade Mode, how does PT handle these PosTrade____ functions return?
The same for optimization and auto trading.
4) As I assume real trade order is started only after Auto Trade is turned on, but no actual trades has been started before Auto Trade Mode is on. Will PosTradeCount(n) always be zero right after Auto Trade is turned on?
Yes, it will for sync mode.
No, it won’t, if it is async mode and there are orders executed during calculation no historical data.
See the following article for more info about sync vs async mode:
https://www.multicharts.com/trading-sof ... _Execution
5) Does PosTrade____ function of these disallowed instrument eventually return its hypothetical trades records or nil in backtesting and auto trading mode?
It does not return any hypothetical trades records. It returns information for the filled orders only.

denniswklam
Posts: 5
Joined: 22 Nov 2016
Has thanked: 4 times

Re: How does Portfolio Trader handle Postrade______ functions?

Postby denniswklam » 20 Dec 2019

Svetlana, Thanks for your responses.

As per your attached article described:
"Asynchronous mode: allows for viewing the backtesting results. Provides access to the historical trades info with the help of PosTrade keywords."
I think I should plan my project with this AA mode under Portfolio Trader in mind, but your response in above Q5 seems to be an issue for my plan to work, and I would like to further clarify the follows:

Scenario:
Assuming in Portfolio Trader, Auto Trading is on, a portfolio with one strategy under AA mode, applying the same signals on several different instruments. (Signal 1: Entry, Signal 2: Exit, Signal 3: My custom benchmark function (which is coded to record historical trades using PosTrade keywords and output an indicative value for later ranking by MM signal).

Even in AA mode, as you point out, PosTrade keywords "returns information for the filled orders only" and I use these PosTrade keywords in Signal 3 for each of the instruments.

Please kindly clarify/define "the filled orders":
Q1)
a) Are these filled orders returned from PosTrade keyword in Signal 3 of each instrument triggered by Signal 1 & 2 "independent" of final permission & reduced size from MM signal (i.e. ignoring MM permission output)?
b) Or these filled orders are returning the Postrade values of each specific instrument only after being processed and allowed by MM signal (i.e only considering MM output?)
c) Or any other cases?

I presume my custom function in Signal 3 will have the correct trade records it needs to be calculated correctly if above Q1(a) is the actual case.
Q2) How do I resolve the problem if Q1(b) is the case?

I am thinking, is it possible that, for each instrument within the portfolio under PT which I turn ON auto trading, I separately create the same instrument by chart trader windows in MC running individually in AA mode with Auto Trading OFF, and with all Signal 1,2,3 applied, and use global variables GV function to link between chart trader windows Signal 3 thru (GVSetValue) & portfolio trader strategy Signal 3 thru (GVGetValue)? In order to transfer the correct output values of my custom function (with PosTrade keywords) in Signal 3 of each instrument, from Chart trader to MM signal to rank and permit trading in PT. Does this resolve the problem? Or am I over thinking/complicating it and there is simpler solution?

Thanks in advance.
DL

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: How does Portfolio Trader handle Postrade______ functions?  [SOLVED]

Postby Svetlana MultiCharts » 24 Dec 2019

denniswklam,

Orders gradually go through the following stages.
Orders are generated by individual signals, go through MM-signal checking and go through internal Portfolio money management/margin filters specified in the Portfolio Settings. After that the generated orders are sent for execution.
In AA mode they are sent to the Backtesting Engine and to the broker. All PosTrade keywords will return the values calculated by the Backtesting Engine, regardless whether the orders are executed by the broker or not.

If you want PosTrade keywords to return the values without MM-signal and internal settings influence, then
- remove MM-signal;
- configure the portfolio to have no money management/margin limits for orders:
In the Money Management Settings section
Exposure should be 100%
Max % of Capital at Risk per Position should be 100%
In the Required Capital Assumptions in Margin Trading section
Margin value % should be 0
Max Potential Loss % should be 0

denniswklam
Posts: 5
Joined: 22 Nov 2016
Has thanked: 4 times

Re: How does Portfolio Trader handle Postrade______ functions?

Postby denniswklam » 24 Dec 2019

Svetlana,

Thanks for explaining PosTrade keywords under PT.

I will try out your suggested approach. Thanks!

Merry Christmas
DL


Return to “MultiCharts”