Trendlines and text misbehave on tick charts

Questions about MultiCharts and user contributed studies.
PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Trendlines and text misbehave on tick charts

Postby PD Quig » 09 Apr 2013

I've got a strategy that also plots fib levels, entry, stop, target, etc. trendlines on the chart so I can see what it's thinking. It was originally developed for use on minute charts, but I recently discovered that its results are better when I use it on a tick chart. As designed, on the minute chart the trend lines print immediately to the right of the most recent bar and move to the right as each new bar is printed. I do some offsetting of the text so that it isn't bunched up and is easier to read.

On the tick chart the strategy executes entries and target exits properly, but some problems are caused by the fact that tick bars are not time-based:
  • The TL_new function (which, of course, takes as inputs start_time and end_time) and the Text_new function (which needs an input start_time) appear to be confused. I can't seem to adjust where text and lines print very well anymore.

    Also, the backtest mode EOD exit code I've been using for years no longer works properly (it leaves the position open). I'm assuming this is also because tick bars are not likely to hit at exactly 16:00, 16:15 or whenever.
I'd appreciate any thoughts if anybody has had similar issues in the past.

Thx,

PDQ
Attachments
Tick_Chart.png
How displayed on a tick chart
(28.14 KiB) Downloaded 952 times
Minute_Chart.png
How displayed on a minute chart
(21.09 KiB) Downloaded 959 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trendlines and text misbehave on tick charts

Postby TJ » 09 Apr 2013

I've got a strategy that also plots fib levels, entry, stop, target, etc. trendlines on the chart so I can see what it's thinking. It was originally developed for use on minute charts, but I recently discovered that its results are better when I use it on a tick chart. As designed, on the minute chart the trend lines print immediately to the right of the most recent bar and move to the right as each new bar is printed. I do some offsetting of the text so that it isn't bunched up and is easier to read.

On the tick chart the strategy executes entries and target exits properly, but some problems are caused by the fact that tick bars are not time-based:
  • The TL_new function (which, of course, takes as inputs start_time and end_time) and the Text_new function (which needs an input start_time) appear to be confused. I can't seem to adjust where text and lines print very well anymore.

    Also, the backtest mode EOD exit code I've been using for years no longer works properly (it leaves the position open). I'm assuming this is also because tick bars are not likely to hit at exactly 16:00, 16:15 or whenever.
I'd appreciate any thoughts if anybody has had similar issues in the past.

Thx,

PDQ
Look up the drawing object keywords with the _s suffix. They are MultiCharts' exclusive sub-minute keywords.

eg.

TL_NEW_s
TIME_s

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 09 Apr 2013

Thanks, TJ, I'll check it out. I'll post back if I figure out the EOD exit problem.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trendlines and text misbehave on tick charts

Postby TJ » 09 Apr 2013

...

Also, the backtest mode EOD exit code I've been using for years no longer works properly (it leaves the position open). I'm assuming this is also because tick bars are not likely to hit at exactly 16:00, 16:15 or whenever.[/list]

I'd appreciate any thoughts if anybody has had similar issues in the past.

Thx,

PDQ
on a sub-minute chart (ie. tick, seconds, range, etc), the time has 6 digits. ie. your 1600 will become 160000. You have to adjust your codes accordingly.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 09 Apr 2013

Ahhhhhh.

Makes sense. Thank you, swami.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trendlines and text misbehave on tick charts

Postby TJ » 09 Apr 2013

Ahhhhhh.

Makes sense. Thank you, swami.
yw

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 10 Apr 2013

All my trendlines work perfectly now, but my open position still failed to close EOD after switching to time_s and currenttime_s.

To debug, I reduced the code down to just a simple market order entry and the EOD exit code I'm using:

Code: Select all

[IntrabarOrderGeneration = true];

[LegacyColorValue = true];

//*************************************************************************
// inputs and variable initialization section
//*************************************************************************

inputs:
StartTime (165000),
EndTime (165100);


//*************************************************************************
// entries execution section
//*************************************************************************


if currenttime_s >= StartTime then buy ("LE") 1 shares next bar at market; // enter long

//*************************************************************************
// Close positions EOD
//*************************************************************************


// live trading EOD exit

if GetAppinfo(aiRealTimeCalc) = 1 and Currenttime_s >= EndTime then once begin

Sell("RT_EOD_LX") CurrentShares shares this bar;
Buy to cover("RT_EOD_SX") CurrentShares shares this bar;
end

else

// backtesting exit

if time_s >= EndTime then begin

Sell ("BT_EOD_LX") CurrentShares shares this bar;
Buy to cover ("BT_EOD_SX") CurrentShares shares this bar;
end;
Order entry was weird too. Maybe because it was after hours, but couldn't get either the entry or exit executions to work at the specified time.

Point me?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trendlines and text misbehave on tick charts

Postby TJ » 10 Apr 2013

why do you have "once" in your code?

Code: Select all

if GetAppinfo(aiRealTimeCalc) = 1 and Currenttime_s >= EndTime then once begin

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 10 Apr 2013

I just added that yesterday while throwing ideas at the wall. It is redundant I guess.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trendlines and text misbehave on tick charts

Postby TJ » 10 Apr 2013

I just added that yesterday while throwing ideas at the wall. It is redundant I guess.
"Once" means to perform the task ONCE and never to do it again.

If your chart has 100 days on it,
that snippet of code will be performed on the 1st day and never again.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 10 Apr 2013

Dropping the "once" that I added yesterday while fiddling around did, indeed, fix the problem. What I don't understand, however, is why it didn't work: all the execution code for the real strategy is embedded within a begin/end loop that only operates on the current day forward. That loop's conditions should never be met until the end of the current day, so I'm having a brain fart as to why adding "once" would have hosed it up.

Anyway, it works. Thanks!

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 11 Apr 2013

Sorry to be a drone on this one subject, but I now realize that there is another facet to the EOD exit issues I was experiencing on tick charts. Call me slow, but I finally realized that when using statements like:

if currenttime_s >= 160000 then sell currentshares this bar;

or,

if time_s >= 160000 then sell currentshares this bar;

on a tick chart will NOT necessarily cause the strategy to exit at 16:00:00.... what it WILL do is cause the strategy to execute a sell when the first tick bar to close after 16:00:00 finally closes. During times of low activity this can be minutes later than the desired exit time.

Is there any way to execute a purely TIME-BASED exit on a tick chart (maybe adding another minute-based chart as data2)?
Last edited by PD Quig on 11 Apr 2013, edited 1 time in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trendlines and text misbehave on tick charts

Postby TJ » 11 Apr 2013

Sorry to be a drone on this one subject, but I now realize that there is another facet to the EOD exit issues I was experiencing on tick charts. Call me slow, but I finally realized that when using statements like:
if currenttime_s >= 160000 then sell currentshares this bar;
or,
if time_s >= 160000 then sell currentshares this bar;
on a tick chart will NOT necessarily cause the strategy to exit at 16:00:00.... what it WILL do is cause the strategy to execute a sell when the first tick bar to close after 16:00:00 finally closes. During times of low activity this can be minutes later than the desired exit time.
Is there any way to execute a purely TIME-BASED exit on a tick chart without adding another minute-based chart as data2?
Look up:

RecalcLastBarAfter

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

Re: Trendlines and text misbehave on tick charts

Postby Henry MultiСharts » 12 Apr 2013

Sorry to be a drone on this one subject, but I now realize that there is another facet to the EOD exit issues I was experiencing on tick charts. Call me slow, but I finally realized that when using statements like:

if currenttime_s >= 160000 then sell currentshares this bar;

or,

if time_s >= 160000 then sell currentshares this bar;

on a tick chart will NOT necessarily cause the strategy to exit at 16:00:00.... what it WILL do is cause the strategy to execute a sell when the first tick bar to close after 16:00:00 finally closes. During times of low activity this can be minutes later than the desired exit time.

Is there any way to execute a purely TIME-BASED exit on a tick chart (maybe adding another minute-based chart as data2)?
Look up:

RecalcLastBarAfter
Check this sample code.

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 12 Apr 2013

Thanks Henry and TJ.

I was flailing around with RecalcLastBarAfter but your code snip is clean and simple. I've tested it number of times and it works yet it does seem to lag by 5-8 secs so I'll have to build in a buffer.

Thanks again, guys!

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Trendlines and text misbehave on tick charts

Postby TJ » 12 Apr 2013

Lots of examples here;
just plug the keyword in the search box at the top right corner and presto!

PD Quig
Posts: 191
Joined: 27 Apr 2010
Location: San Jose
Has thanked: 67 times
Been thanked: 10 times

Re: Trendlines and text misbehave on tick charts

Postby PD Quig » 13 Apr 2013

It appears that running in replay mode causes GetAppinfo(aiRealTimeCalc) to return a value of 1.00 even though there is no connection to a live data stream. Is this as designed?

Seems odd, if so. Also reduces the utility of replay mode because the following code causes the position to exit as soon as opened:

Code: Select all

// live trading EOD exit

if GetAppinfo(aiRealTimeCalc) = 1 and (currenttime_s >= CalcTime_s(EndTime, -8)) then begin

RecalcLastBarAfter(1);

sell ("RT_EOD_LX") next bar at market;
buytocover("RT_EOD_SX") next bar at market;
end

else

// backTesting exit

if time_s >= EndTime then begin

Sell ("BT_EOD_LX") CurrentShares shares this bar;
Buy to cover ("BT_EOD_SX") CurrentShares shares this bar;
end;

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

Re: Trendlines and text misbehave on tick charts

Postby Henry MultiСharts » 16 Apr 2013

It appears that running in replay mode causes GetAppinfo(aiRealTimeCalc) to return a value of 1.00 even though there is no connection to a live data stream. Is this as designed?
That is expected behavior. Playback is simulation of realtime data.


Return to “MultiCharts”