PureBytes Links
Trading Reference Links
|
At 02:53 PM 4/24/2005, Chris Cheatham wrote:
>Hi,
>
>I am stuck. Trying to write a function in TS 8.1 similar in function to
>lastbaronchart, except I need it to return true ONLY for the last COMPLETE
>bar on chart on an "update every tick" indicator. For example, if I add the
>indicator to the chart and it is 11:13, and we're working on the 11:15
>five-minute bar, I need it to return true for the 11:10 bar so I can trigger
>drawing code that is too complex to run real time. (With tls drawn on a real
>time bar, they must be theoretically redrawn on every tick, can't be drawn
>once and left alone. ) Any ideas would be appreciated. Seems so basic, but
>I've been playing with it off and on for three days and have not come up
>with anything practical.
>
>Thanks,
>Chris
Hi Chris
I'm not sure whether BarStatus can be of use to you here, but you can look into it. Here is the Help entry on this Function:
-----------------------------
BarStatus(Reserved Word)
This reserved word is used with multiple data series (same symbol, different data intervals) or ActivityBar studies to determine whether the current tick is the opening or closing tick of a bar in the other data series, or whether it is a trade ‘inside the bar.’
BarStatus(DataNum)
DataNum is a numeric expression representing the data stream that is being evaluated. 1 refers to Data1, 2 to Data2 and so on. DataNum can be between 1 and 50, inclusive.
Notes:
This reserved word will return one of four possible values:
2 = the closing tick of a bar
1 = a tick within a bar
0 = the opening tick of a bar
-1 = an error occurred while executing the reserved word
The data series referenced must be applied to the chart. For example, to use BarStatus (2), a second data series must be applied to the chart.
Example
To perform an operation when the ActivityBar is the last trade of the ‘big’ bar, you could write:
If BarStatus(1) = 2 Then
{Your Operation Here} ;
… where Data1 is the price chart, and your analysis technique is an ActivityBar study.
Additional Example
The following statements reset the numeric variable Value1 to 0 when the bar to which the ActivityBar study is applied is closed:
If BarStatus(1) = 2 Then
Value1 = 0
Else
Value1 = Value1 + 1;
----------------------------
Also, perhaps instead of drawing on the last tick of a fully formed bar, you could trigger off the first tick of a new bar, and draw with the data up to the just finished bar.
It is easy to detect whether you are at the first tick on a new bar - just save the current bar date/time in a global variable, and retrieve the previously saved ones to see if the current one is different.
Hope that helps,
Mike Gossland
|