portfolio trader

Questions about MultiCharts and user contributed studies.
shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

portfolio trader

Postby shanemcdonald » 05 Sep 2014

With the portfolio trader not having bar magnifier available, how will this affect walk forward testing with portfolio trader ?

During live sim autotrading, Will portfolio trader only calculate minute data ? HLC data ? Tick data ?

thanks

shane

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: portfolio trader

Postby Henry MultiСharts » 08 Sep 2014

Hello shanemcdonald,

How Signals are Calculated describes this behavior:

Calculation on historical data. Regular mode (IOG disabled. Bar Magnifier disabled)
The script is calculated on the bar close. It's considered that all prices were within the bar (Intra-bar Price movement assumption is used). An order is filled on any price within the bar.

Realtime. Normal mode.
The script is calculated on the bar close. An order is placed on this bar close/next bar open. An order is then filled on any tick price within the next bar.

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: portfolio trader

Postby orion » 14 Oct 2014

A few related questions:

1) I assume that PT in 9.0 release still does not support IOG or BarMagnifier?

2) If PT does not support IOG, can we assume that strategy orders such as setStopLoss, setBreakEven, setProfitTarget, and setPercentTrailing which the help pages say work on intrabar basis continue to work on intrabar basis in PT?

3) This is not a PT question. I wanted to check my assumption on chart-based IOG-enabled trading with you since the help pages talk about how buy and sell orders have a one bar or one tick duration and are cancelled if not filled within the specified bar or tick.

My confusion is with the word "cancelled" since that can imply hundreds of cancellations being fired at the broker within a bar as the strategy calculates on each tick but the order does not get filled for reasons of liquidity or price limits. I assume MC is not firing hundreds of order cancels at the broker and that what is going on is something like following:

After strategy calculation on a tick, an order is placed. If strategy recalculates the same order on next tick, then nothing is done with the order that was sent to the broker (so no actual cancel takes place). But if strategy does not recalculate the same order, the order with the broker is cancelled.

Thanks.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: portfolio trader

Postby Henry MultiСharts » 17 Oct 2014

1) I assume that PT in 9.0 release still does not support IOG or BarMagnifier?
Portfolio trader does not support IOG and BarMagnifier for signals. IOG is supported for the money management signal only.
2) If PT does not support IOG, can we assume that strategy orders such as setStopLoss, setBreakEven, setProfitTarget, and setPercentTrailing which the help pages say work on intrabar basis continue to work on intrabar basis in PT?
When SetStopLoss and other Set*** commands are not under condition (not under begin-end) - they are evaluated intra-bar (even if IOG is off).
3) I assume MC is not firing hundreds of order cancels at the broker and that what is going on is something like following: After strategy calculation on a tick, an order is placed. If strategy recalculates the same order on next tick, then nothing is done with the order that was sent to the broker (so no actual cancel takes place). But if strategy does not recalculate the same order, the order with the broker is cancelled.
That is correct. The orders are valid at broker while they are sent by the strategy. That means the conditions for order generation should be met in your code on each bar close or each tick (if IOG=ON) calculation while you need to keep your orders active. If you want to modify an order - just change the parameter you need (price or quantity) and the order will be modified or cancelled and resubmitted (depends on broker).

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: portfolio trader

Postby orion » 17 Oct 2014

Thank you Henry for the explanation. I wanted to clarify some finer points related to this topic.

1) I assume that PT supports signals using second bars and so one can work around the lack of IOG in PT by coding signals using finer grained bars?

2) I assume one can bracket an entry immediately using both setStopLoss and setProfitTarget. Since these are evaluated intrabar even with IOG off, I assume that when you use these set* instructions, it does not result in stop or limit orders being filed with the broker and that instead PT running on my computer evaluates the set* orders on tick-by-tick basis and if any of them are true then a market order is placed with the broker? Please clarify these details about the timing of the orders and the type of orders (stop vs limit vs market).

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: portfolio trader

Postby Henry MultiСharts » 20 Oct 2014

Thank you Henry for the explanation. I wanted to clarify some finer points related to this topic.

1) I assume that PT supports signals using second bars and so one can work around the lack of IOG in PT by coding signals using finer grained bars?
All data resolutions are supported in Portfolio Trader.
2) I assume one can bracket an entry immediately using both setStopLoss and setProfitTarget. Since these are evaluated intrabar even with IOG off, I assume that when you use these set* instructions, it does not result in stop or limit orders being filed with the broker and that instead PT running on my computer evaluates the set* orders on tick-by-tick basis and if any of them are true then a market order is placed with the broker? Please clarify these details about the timing of the orders and the type of orders (stop vs limit vs market).
It depends on the broker you are using. Please check the Order Types information and the description of the broker profile you are using.

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: portfolio trader

Postby orion » 20 Oct 2014

2) I assume one can bracket an entry immediately using both setStopLoss and setProfitTarget. Since these are evaluated intrabar even with IOG off, I assume that when you use these set* instructions, it does not result in stop or limit orders being filed with the broker and that instead PT running on my computer evaluates the set* orders on tick-by-tick basis and if any of them are true then a market order is placed with the broker? Please clarify these details about the timing of the orders and the type of orders (stop vs limit vs market).
It depends on the broker you are using.
Henry,

Thanks for the reply. I will be using IB as broker and would like to understand the details of how auto trading using Portfolio Trader works with IB.

1) To clarify my understanding, even though your help pages say that the built-in set* orders work intrabar, PT running on my computer is not doing a tick-by-tick evaluation (even with IOG off) in the case of IB for setProfitTarget and setStopLoss orders?

2) Assume I entered a long position and my PL code has following two lines for exit at either a profit target or a stop loss. There are three variations and I would like to understand if there are any differences between the variations when it comes to MC/PT to IB interface.

Specifically, please answer the following for all 3 variations: Is the profit target a native IB limit order and the stop loss a native IB stop order and does MC/PT automatically link them in an IB OCA group?

2(a) // exit using two explicit sells

Code: Select all

if (marketPosition = 1) then begin
sell next bar at buyProfitPrice limit;
sell next bar at buyStopPrice stop;
end;
2(b) // exit using explicit sell and a built-in

Code: Select all

if (marketPosition = 1) then
sell next bar at buyProfitPrice limit;
setStopLoss(buyStopPrice);
2(c) // exit using two built-in

Code: Select all

setProfitTarget(buyProfitPrice);
setStopLoss(buyStopPrice);
end;
3) I notice that the IB API has a EClientSocket with two methods placeOrder() and cancelOrder() and I am assuming MC/PT uses these two methods to "modify" orders. If my PL code issues a limit order on a bar and then reissues the same order with a different price on the next bar, does that result in a pair of cancelOrder() and placeOrder() messages being fired at IB which means my limit order will go to the back of the queue and thus adversely affect my fill even though I may have modified the limit price in my favor?

4) In other words, the lack of a native modifyOrder() in the IB API works against the trader? (I am not saying this is a MC problem; this is simply the hand that IB is dealing its customers.)

Regards,
orion

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: portfolio trader

Postby Henry MultiСharts » 21 Oct 2014

Henry,

Thanks for the reply. I will be using IB as broker and would like to understand the details of how auto trading using Portfolio Trader works with IB.

1) To clarify my understanding, even though your help pages say that the built-in set* orders work intrabar, PT running on my computer is not doing a tick-by-tick evaluation (even with IOG off) in the case of IB for setProfitTarget and setStopLoss orders?
That is correct.
2) Assume I entered a long position and my PL code has following two lines for exit at either a profit target or a stop loss. There are three variations and I would like to understand if there are any differences between the variations when it comes to MC/PT to IB interface.

Specifically, please answer the following for all 3 variations: Is the profit target a native IB limit order and the stop loss a native IB stop order and does MC/PT automatically link them in an IB OCA group?

2(a) // exit using two explicit sells

Code: Select all

if (marketPosition = 1) then begin
sell next bar at buyProfitPrice limit;
sell next bar at buyStopPrice stop;
end;
2(b) // exit using explicit sell and a built-in

Code: Select all

if (marketPosition = 1) then
sell next bar at buyProfitPrice limit;
setStopLoss(buyStopPrice);
Limit and Stop orders are supported on broker end: Order types. Such orders can be placed only on bar close in PT. All orders generated on the same calculation are in the OCO group. OCO group can be native and emulated: Interactive Brokers Broker Profile
2(c) // exit using two built-in

Code: Select all

setProfitTarget(buyProfitPrice);
setStopLoss(buyStopPrice);
end;
If you have such orders under If-Then conditional statement - such orders can be generated only on bar close in PT. If you do not use them under If-Then conditional statement - such orders can be generated and sent intra-bar. IB's native stop and limit orders are sent when setProfitTarget and setStopLoss commands are used.
3) I notice that the IB API has a EClientSocket with two methods placeOrder() and cancelOrder() and I am assuming MC/PT uses these two methods to "modify" orders. If my PL code issues a limit order on a bar and then reissues the same order with a different price on the next bar, does that result in a pair of cancelOrder() and placeOrder() messages being fired at IB which means my limit order will go to the back of the queue and thus adversely affect my fill even though I may have modified the limit price in my favor?

4) In other words, the lack of a native modifyOrder() in the IB API works against the trader? (I am not saying this is a MC problem; this is simply the hand that IB is dealing its customers.)
IB API supports order modification. This functionality is supported in MultiCharts. Here is an extract from the API documentation:
To modify an order using the API, resubmit the order you want to modify using the same order id, but with the price or quantity modified as required. Only certain fields such as price or quantity can be altered using this method. If you want to change the order type or action, you will have to cancel the order and submit a new order.

orion
Posts: 250
Joined: 01 Oct 2014
Has thanked: 65 times
Been thanked: 104 times

Re: portfolio trader

Postby orion » 21 Oct 2014

2(c) // exit using two built-in

Code: Select all

setProfitTarget(buyProfitPrice);
setStopLoss(buyStopPrice);
end;
If you have such orders under Begin-End loop - such orders can be generated only on bar close in PT. If you do not use them under Begin-End loop - such orders can be generated and sent intra-bar. IB's native stop and limit orders are sent when setProfitTarget and setStopLoss commands are used.
Henry,

Many thanks for the explanations. This is a lot more clear now.

1) Your email mentioned packaging the exit variations (a) and (b) in an IB OCA group. I assume same is done for the built-in pair variation (c)?

2) Regarding orders under "begin-end loop" precluding them from being sent intrabar and being sent intrabar otherwise. That is not clear to me.

Isn't PT currently lacking IOG and so all calculation is being done on bar close and hence such orders can only be sent on bar close by PT even though they may be executed intrabar by IB?

Regards,
orion

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: portfolio trader

Postby Henry MultiСharts » 21 Oct 2014

Henry,

Many thanks for the explanations. This is a lot more clear now.

1) Your email mentioned packaging the exit variations (a) and (b) in an IB OCA group. I assume same is done for the built-in pair variation (c)?
Yes, all orders generated on the same calculation are in the same OCO group.
2) Regarding orders under "begin-end loop" precluding them from being sent intrabar and being sent intrabar otherwise. That is not clear to me.

Isn't PT currently lacking IOG and so all calculation is being done on bar close and hence such orders can only be sent on bar close by PT even though they may be executed intrabar by IB?
SetStopLoss function is evaluated intra-bar disregard the IOG if your code is like the following:

Code: Select all

If MarketPosition = 0 then buy next bar at market;

SetStopLoss(); // not under conditional statement
if your code is like the following then IOG=True is required to have SetStopLoss generated intra-bar:

Code: Select all

If MarketPosition = 0 then buy next bar at market;
If MarketPosition = 1 then SetStopLoss(); // under conditional statement


Return to “MultiCharts”