IntraBar timestamps in a strategy - How?  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
JoshM
Posts: 2045
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1518 times
Been thanked: 1465 times
Contact:

IntraBar timestamps in a strategy - How?

Postby JoshM » 14 Feb 2013

Goal
I want to make a time filter that works intrabar. For example, one minute before the bar closes, exit the open position. I want to achieve this without adding an additional data series to the chart, since that messes up the chart.

Settings
IOG on, BarMagnifier On set to one tick resolution (tick data is available), Chart: 3 minute chart (but the solution should work regardless of the chart period).

Code example

Code: Select all

[IntrabarOrderGeneration = True];

Variables:
   IntraBarPersist TickCounter(0),
   dtBar(0);

once cleardebug;

if (Date <> CurrentDate) then #return;
   
dtBar = ELDateToDateTime(Date) + ELTimeToDateTime_s(Time_s);

TickCounter += 1;

Print(FormatDate("dd-MM-yy ", dtbar), FormatTime("HH:mm:ss   ", dtbar), TickCounter);

if (BarStatus(1) = 2) then
   TickCounter = 0;


Output

Code: Select all

14-02-13 12:45:00     70.00
14-02-13 12:45:00     71.00
14-02-13 12:45:00     72.00
14-02-13 12:45:00     73.00
14-02-13 12:45:00     74.00
14-02-13 12:45:00     75.00
14-02-13 12:45:00     76.00
14-02-13 12:45:00     77.00
14-02-13 12:48:00      1.00
14-02-13 12:48:00      2.00
14-02-13 12:48:00      3.00
14-02-13 12:48:00      4.00
14-02-13 12:48:00      5.00
14-02-13 12:48:00      6.00
14-02-13 12:48:00      7.00
14-02-13 12:48:00      8.00
14-02-13 12:48:00      9.00
14-02-13 12:48:00     10.00
14-02-13 12:48:00     11.00
14-02-13 12:48:00     12.00
14-02-13 12:48:00     13.00
14-02-13 12:48:00     14.00
14-02-13 12:48:00     15.00
14-02-13 12:48:00     16.00
14-02-13 12:48:00     17.00
14-02-13 12:48:00     18.00
14-02-13 12:48:00     19.00
14-02-13 12:48:00     20.00
14-02-13 12:48:00     21.00
14-02-13 12:48:00     22.00
14-02-13 12:48:00     23.00
14-02-13 12:48:00     24.00
14-02-13 12:48:00     25.00
14-02-13 12:48:00     26.00
14-02-13 12:48:00     27.00
14-02-13 12:48:00     28.00
14-02-13 12:48:00     29.00
14-02-13 12:48:00     30.00


Question/problem
As the output shows, while there are multiple ticks processed per bar, the time stamp of each processed tick is the bar closing time. How can I get the actual time of the tick? Anyone got an idea? :)

User avatar
TJ
Posts: 6482
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 956 times
Been thanked: 1867 times

Re: IntraBar timestamps in a strategy - How?

Postby TJ » 14 Feb 2013

on a 3 minute chart, if you want 1 minute before bar end, you are looking for a currenttime difference:

TIME = EOB time
CURRENTTIME = real time
target time (a real time) = EOB time minus 1 minute of real time
These users thanked the author TJ for the post:
JoshM

User avatar
JoshM
Posts: 2045
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1518 times
Been thanked: 1465 times
Contact:

Re: IntraBar timestamps in a strategy - How?

Postby JoshM » 14 Feb 2013

TJ wrote:on a 3 minute chart, if you want 1 minute before bar end, you are looking for a currenttime difference:

TIME = EOB time
CURRENTTIME = real time
target time (a real time) = EOB time minus 1 minute of real time

Thanks TJ, that would solve it for real-time trading. Do you might have an idea how to do this when backtesting?

User avatar
TJ
Posts: 6482
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 956 times
Been thanked: 1867 times

Re: IntraBar timestamps in a strategy - How?  [SOLVED]

Postby TJ » 14 Feb 2013

JoshM wrote:
TJ wrote:on a 3 minute chart, if you want 1 minute before bar end, you are looking for a currenttime difference:

TIME = EOB time
CURRENTTIME = real time
target time (a real time) = EOB time minus 1 minute of real time

Thanks TJ, that would solve it for real-time trading. Do you might have an idea how to do this when backtesting?

For backtesting, you have to use a 2nd data series for finer time resolution.
These users thanked the author TJ for the post:
JoshM

User avatar
JoshM
Posts: 2045
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1518 times
Been thanked: 1465 times
Contact:

Re: IntraBar timestamps in a strategy - How?

Postby JoshM » 14 Feb 2013

TJ wrote:For backtesting, you have to use a 2nd data series for finer time resolution.

Hm, I was already afraid of that. Since the signal is a sort of combination of discretionary and a strategy, the chart needs to remain "readable" and adding a much finer time resolution doesn't allow that. In all other cases it would have been a good solution, though.

While not the answer I hoped for, thanks for your help TJ. :)

User avatar
Henry MultiСharts
Posts: 8317
Joined: 25 Aug 2011
Has thanked: 1185 times
Been thanked: 2640 times

Re: IntraBar timestamps in a strategy - How?

Postby Henry MultiСharts » 22 Feb 2013

JoshM wrote:How can I get the actual time of the tick? Anyone got an idea?


Hello JoshM,

In MultiCharts 9 we will introduce a new reserved word that will provide acces to Bar Magnifier's data series Data and Time values.
These users thanked the author Henry MultiСharts for the post (total 3):
SUPERJoshMno erocla

no erocla
Posts: 112
Joined: 31 May 2013
Has thanked: 51 times
Been thanked: 7 times

Re: IntraBar timestamps in a strategy - How?

Postby no erocla » 09 Nov 2015

Hi all,

i'm interested to this features too, there's any news ?

Thank you
Regards
No Erocla

evdl
Posts: 396
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 84 times
Been thanked: 122 times

Re: IntraBar timestamps in a strategy - How?

Postby evdl » 09 Nov 2015

With IOG and BM on 1 tick, you can use "datetime_bar_update". This will show you the time of every tick in ms.

Code: Select all

vars: Intrabarpersist Bartime_value("");

// bar time per tick on ms
Bartime_value = datetimetostring_ms(datetime_bar_update);
These users thanked the author evdl for the post (total 3):
no eroclasptraderHenry MultiСharts


Return to “MultiCharts”