PowerLanguage question. Total bars since open

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
stockmacd
Posts: 23
Joined: 28 Feb 2007

PowerLanguage question. Total bars since open

Postby stockmacd » 06 Jul 2008

this may be a very easy question, but I've spent the last 3 hours trying to figure out how to get a count of the total bars since open.

i'm during 1 min chart, so for example:
start of trading session = 9:30

at 9:45 the total bars should be 15
at 10:00 the total bars should be 30..etc..etc..

any help would be greatly appreciated. :D

User avatar
ABC
Posts: 516
Joined: 16 Dec 2006
Has thanked: 110 times
Been thanked: 290 times
Contact:

Postby ABC » 06 Jul 2008

stockmacd,

you can realize this with a counter you have to reset once before your new session begins.

In case "MyBarNumber" and "MyBarCounter" are variables, you can do the following:

Code: Select all

If CurrentBar <> MyBarNumber then begin
   MyBarNumber = CurrentBar;
   MyBarCounter = MyBarCounter + 1;
end;


A second idea would be to store the CurrentBar value on the session start into a variable and substract it from the current CurrentBar value, to get the number of bars from session start to the most recent bar.

Best regards,

ABC

User avatar
RobotMan
Posts: 375
Joined: 12 Jul 2006
Location: Los Altos, California, USA
Has thanked: 31 times
Been thanked: 12 times
Contact:

Postby RobotMan » 07 Jul 2008

Code: Select all

// Function: bpBSS (Bars Since Start)

If time>=Sess2StartTime and time<=Sess2EndTime then BEGIN
   bpBSS = bpBSS[1] + 1;
end Else bpBSS = 0;


stockmacd
Posts: 23
Joined: 28 Feb 2007

Postby stockmacd » 07 Jul 2008

I've tried both solutions, but it's not working. I must be doing something wrong.

vars:barcounter(0) ;

If time>=Sess1StartTime and time<=Sess1EndTime then BEGIN
barcounter= barcounter[1] + 1;
end Else barcounter= 0;

print(TimeToString(time) + " count=" + NumToStr(barcounter,0));

output:

12:00:00 AM count=1
12:00:00 AM count=2
12:00:00 AM count=3
12:00:00 AM count=4
12:00:00 AM count=5
12:00:00 AM count=6
12:00:00 AM count=7
12:00:00 AM count=8
12:00:00 AM count=9
12:00:00 AM count=10
12:00:00 AM count=11
12:00:00 AM count=12
.......... keeps on going and going. It looks like "time" is always outputed as 12:00 am. Do I need to change a setting in quotemanager?

User avatar
RobotMan
Posts: 375
Joined: 12 Jul 2006
Location: Los Altos, California, USA
Has thanked: 31 times
Been thanked: 12 times
Contact:

Postby RobotMan » 07 Jul 2008

Sorry, I trade emini and wrote for globex 24 hour.

For US stock, try this:
----------------------------------------------------------------
// Function: bpBSSstk

bpBSSstk = IFF(time=sess1firstbartime,1,bpBSSstk + 1);

----------------------------------------------------------------

To check; go to chart and "insert study..." / ""Custom 1 Line""
Formula: bpBSSstk

See Attached.

Bob Perry
Los Altos,CA
Attachments
Goog1min.jpg
Goog1min.jpg (76.82 KiB) Viewed 357 times

stockmacd
Posts: 23
Joined: 28 Feb 2007

Postby stockmacd » 07 Jul 2008

Awesome,
that worked great RobotMan

Thank you !


Return to “User Contributed Studies and Indicator Library”