Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Questions about MultiCharts .NET and user contributed studies.
dnickless
Posts: 21
Joined: 02 May 2016
Has thanked: 2 times
Been thanked: 2 times

Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby dnickless » 13 Feb 2017

Hi all

I am running a 1d strategy in Portfolio Trader that selects some Nasdaq 100 components and takes a buy/sell/do nothing decision for each of them.

Using a Money Management Signal, I try to maximize my exposure in a smart way across all symbols. In order to do so, what I would want to make sure is that all SELL orders get executed before all BUY orders so I can use my full buying power. Otherwise BUY orders might get rejected because the pending SELLs have not been executed at the point in time when a BUY hits the broker.

How would I do that?

Thanks!

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby Angelina MultiСharts » 13 Feb 2017

Hello dnickless,

If by SELL order you mean exiting the position, then we'd recommend checking the market position before generating the Entry.

It is also possible to check the state of the particular orders in your script. Please see the following examples, demonstrating how to get the order info from Order and Position Tracker:
viewtopic.php?t=10730
viewtopic.php?t=11028

dnickless
Posts: 21
Joined: 02 May 2016
Has thanked: 2 times
Been thanked: 2 times

Re: Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby dnickless » 13 Feb 2017

Thank you! Let me try to be a bit more precise:

Imagine, the strategy buys one single stock today and it decides to put all my cash into it. Then tomorrow, it decides to sell the entire position and buy something else instead. In this case, while I'm still 100% invested, the broker potentially rejects the second attempt to buy stock because I'm out of cash. So I would want to execute the sell order first (so I would have cash again) and then buy again.

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby Angelina MultiСharts » 14 Feb 2017

Dnickless,

It is not possible to set the execution order for the orders generated on one calculation.
Your strategy has to generate all the exit orders first, and the entry ones after checking the market position or Sell order statuses.

dnickless
Posts: 21
Joined: 02 May 2016
Has thanked: 2 times
Been thanked: 2 times

Re: Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby dnickless » 14 Feb 2017

Thank you so far! How would I best go about implementing this logic? I basically have only one triggering event (bar close) where I take all my decisions at the moment.

Would I need to first process only sells in the bar close event and then use the RecalcAfter feature to trigger another event some seconds later? Would those orders still be sent to the broker even though the session is technically over?

Or can I use a session template to somehow define two points in time at which I run the calculation? E.g. 3:58pm (sells only) and 3:59pm (buy orders only)?

Or is there another way?

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby Angelina MultiСharts » 17 Feb 2017

dnickless,

In this case the only solution I see is to use a more detailed resolution.
RecalcLastBarAfter will lead to strategy recalculation, but the the orders are not going to be sent intrabar.

dnickless
Posts: 21
Joined: 02 May 2016
Has thanked: 2 times
Been thanked: 2 times

Re: Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby dnickless » 17 Feb 2017

Is every symbol calculated in its own thread and independent from other symbols? In this case, I might simply attempt to do a Thread.Sleep(10000) to pause for ten seconds when I want to buy. The sell orders would not get paused so they should be executed straight away. Could that work?

dnickless
Posts: 21
Joined: 02 May 2016
Has thanked: 2 times
Been thanked: 2 times

Re: Portfolio Trader + Money Management Signal: Sequence of order submission to broker

Postby dnickless » 09 Mar 2017

Well, to answer my own question: All symbols run on the same thread, the Money Management signal runs on another one. So my idea did not work. ;(

@Angelina, regarding your idea of using a more detailed resolution: How exctly would that work? I need daily bars to take a trading decision at the end of a day (a few seconds before the Exchange closes - currently 1 minute with a session template that is configured to signal the session end at 15:59).


Return to “MultiCharts .NET”