Timed Exit

Questions about MultiCharts and user contributed studies.
StefanoSF
Posts: 116
Joined: 19 Aug 2012
Location: San Francisco
Has thanked: 23 times
Been thanked: 30 times
Contact:

Timed Exit

Postby StefanoSF » 21 Dec 2014

I have a short strategy with a timed exit of 25 days. I noticed if i turn off the script some day after the initial entry, that the strategy starts recounting based on the day I restart Autotrading not the original entry date. My Strategy Properties are set to: "Entries/Exits are based on execution confirmation by broker (Sync)" and "Show the Assign the initial Market Positions at the Broker dialogue".

Can someone tell me may be wrong:

Code: Select all

Input:
ShortHoldPeriod(25);

Variables:
EntryBars(0);
EntryBars=BarsSinceEntry(0);

SetStopShare;

{---- Exit----}
If MP = -1 and ShortHoldPeriod>0 and EntryBars >= ShortHoldPeriod Then Buytocover(" Bar Count") next bar at market;

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Timed Exit

Postby JoshM » 22 Dec 2014

I have a short strategy with a timed exit of 25 days. I noticed if i turn off the script some day after the initial entry, that the strategy starts recounting based on the day I restart Autotrading not the original entry date.
As I understand it, when auto-trading of a trading strategy is restarted, the previous historical trades are not available anymore. In that case, `BarsSinceEntry` will not return the previous trade (since there was none). At least, when I enable auto-trading on a chart, all previous historical backtest trades are gone and I start with an empty, 'new' Strategy Performance Report.

Perhaps you can store the `CurrentBar` value in a variable when the entry condition occurs? Then than value can be compared on every bar to see if that was 25 days ago.

StefanoSF
Posts: 116
Joined: 19 Aug 2012
Location: San Francisco
Has thanked: 23 times
Been thanked: 30 times
Contact:

Re: Timed Exit

Postby StefanoSF » 22 Dec 2014

Thanks Josh.

To clarify my post, rather then 25 days, it should read 25 bars as I use daily bars. Shouldn't my strategy know how many bars ago I entered the trade? If "Show Historical Orders" is turned on, it clearly shows the original entry bar from where to count from.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Timed Exit

Postby JoshM » 23 Dec 2014

Shouldn't my strategy know how many bars ago I entered the trade? If "Show Historical Orders" is turned on, it clearly shows the original entry bar from where to count from.
I can't really answer if MultiCharts should or shouldn't work that way; perhaps MultiCharts Support can join in? They know best how the program should or should not work.

What I know is that I can't seem to get historical order entry data in PowerLanguage after disabling a trading strategy and turning it back on again. I just tested it again with MC 9.0, and it still doesn't seem to work that way:

Code: Select all

if (GetAppInfo(aistrategyauto) = 1) then begin

Print("BarsSinceEntry(0) = ", barssinceentry(0),
" BarsSinceEntry(1) = ", barssinceentry(1));

if (MarketPosition(0) = 0) then
Buy 1 contracts next bar at market;

end;

{
Output with the initial position created by the strategy:
BarsSinceEntry(0) = 0.00 BarsSinceEntry(1) = 0.00
BarsSinceEntry(0) = 1.00 BarsSinceEntry(1) = 0.00
BarsSinceEntry(0) = 2.00 BarsSinceEntry(1) = 0.00
BarsSinceEntry(0) = 3.00 BarsSinceEntry(1) = 0.00
BarsSinceEntry(0) = 4.00 BarsSinceEntry(1) = 0.00
Output after disabling/enabling the strategy (with the open position):
BarsSinceEntry(0) = 0.00 BarsSinceEntry(1) = 0.00
BarsSinceEntry(0) = 0.00 BarsSinceEntry(1) = 0.00
BarsSinceEntry(0) = 0.00 BarsSinceEntry(1) = 0.00
}
If it can work, that would be great. But does someone know how? :)

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

Re: Timed Exit

Postby Henry MultiСharts » 23 Dec 2014

After restart of auto trading in SA mode strategy has no information regarding the orders that were previously executed. As Josh has mentioned - that is possible to create a code that will store the information regarding the current position/orders (before switching off the auto trading), then read the required information on the next run and continue the trading.

In AA mode the backtesting results remain on the chart after starting the auto trading, and can be accessed from code.

StefanoSF
Posts: 116
Joined: 19 Aug 2012
Location: San Francisco
Has thanked: 23 times
Been thanked: 30 times
Contact:

Re: Timed Exit

Postby StefanoSF » 02 Jan 2015

To allow bar counting exits to work after a strategy restart, would adding a "Entry BarNumber" input to the Assign the Initial Market Position at the Broker solve this problem?

Image
Attachments
EntryBar.png
(7.55 KiB) Downloaded 2572 times

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Timed Exit

Postby evdl » 03 Jan 2015

Hello Stefano,

Some time ago I made a script to sync the position and stoploss/profit target in the case the autotrader goes off for some reason or to have your position after a restart overnight.

The script will generate a textfile with all the last know positions and this will be imported in mc (without manually filling it in) once you activate the autotrader again. The strategy will know your last position and go on from there.

The barnumber is not in the script, but you can edit this in.

http://www.multicharts.com/discussion/v ... =5&t=11109

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

Re: Timed Exit

Postby Henry MultiСharts » 05 Jan 2015

To allow bar counting exits to work after a strategy restart, would adding a "Entry BarNumber" input to the Assign the Initial Market Position at the Broker solve this problem?

Image
You may want to submit a feature request to the Project Management of our web site so other users can vote for it: https://www.multicharts.com/pm/

StefanoSF
Posts: 116
Joined: 19 Aug 2012
Location: San Francisco
Has thanked: 23 times
Been thanked: 30 times
Contact:

Re: Timed Exit

Postby StefanoSF » 05 Jan 2015

Vote here for allowing timed exits to work after strategy restart:

http://www.multicharts.com/pm/viewissue ... no=MC-1831

Ming80
Posts: 24
Joined: 18 Jun 2012
Has thanked: 20 times
Been thanked: 1 time

Re: Timed Exit

Postby Ming80 » 18 Mar 2016

Ran into the same problem on time exits and voted as well.

I tend to reload the charts and fresh start MC each day so I lose the value of barssinceentry.

Did any of you guys have a workaround for barsinceentry?
Would this entail capturing the entry bar number (or date) somehow and re-entering it into the strategy as an input? Pleased to hear if anyone can point me in the right direction thanks!

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

Re: Timed Exit

Postby Henry MultiСharts » 12 Apr 2016

Ran into the same problem on time exits and voted as well.

I tend to reload the charts and fresh start MC each day so I lose the value of barssinceentry.

Did any of you guys have a workaround for barsinceentry?
Would this entail capturing the entry bar number (or date) somehow and re-entering it into the strategy as an input? Pleased to hear if anyone can point me in the right direction thanks!
Hello Ming80,

You can store the required value in a text file and then read it when the auto trading is restarted.

User avatar
Smoky
Posts: 507
Joined: 03 Dec 2010
Location: Thailand
Has thanked: 97 times
Been thanked: 115 times

Re: Timed Exit

Postby Smoky » 13 Apr 2016

hello all,

I think the best solution would be that Multicharts manage the reboot of stategy, because when you are on the market and you have to restart MC, you lose long time on loading charts.

First MC ccompute signals from the begining , you click on SA mode, MC compute again from first bar the stategy !

Even if you start in mode SA MC will compute from the first bar...

Everybody win time if MC keep in mind all trades, on warm start you are ready to auto-trade immediately :) (safety and speed )

The only thing to controle : no change on stategy that's all.

For me in, auto-trading it's the most beautiful thing that it can happen...

vote + 1 ok ;)

maybe it's also the best way to synchronize multi-charts trading on same instruments ....


Return to “MultiCharts”