Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Try array referencing CurrentBar? or use array references i.e. Close[x]. I'm not using Powerlanguage at the moment. So, this may not be exactly correct.
If you have a signal then you can use Highest(Close,5) >= 1 for example to look for a signal or something like Highest(MyIndi, 5) >=1. This would tell you if had a signal within the most recent 5 bars. If you wanted the actual bar you might try something like HighestBar.
I am afraid your description doesn't really explain what you want to count exactly. Going by your question the correct answer would be "use currentbar". However I suppose you want to count the bars since the indicator did something, but without knowing that, it's hard to help you.
I would suggest to describe what you want the code to do with more detail and include screenshots showing what you are looking for, too. This should make it possible for other to understand what you have in mind.
use a variable that you reset to 0 (or 1) everytime the SMA crosses above the price and increment the variable on every new bar (or at the end of every bar) until the SMA crosses below price.
Now this variable will hold the number of bars that the SMA was above the price for this swing.
Another approach would be to store the bar number (using CurrentBar for example) in a variable when the SMA crosses above the price and when the SMA crosses below price you compute the difference between CurrenBar and the value of the variable.