How to find number of bars when a signal occurred?
Author: thetraderman
Creation Date: 4/19/2011 12:30 PM
profile picture

thetraderman

#1
Is there a way I can find the total number of bars when a signal or a point in time occurred which would be different than Bars.Count? In other words I have a situation where I get a signal at bar 50 but at the time I had a maximum of 800 bars on the pane. However at one point when I got the signal the maximum number of bars could have been 55 assuming counting foward in time. If I use Bars.Count I get 800 but in reality I would like to get a return value of 55 which was the maximum number of bars at the time the signal occured?
profile picture

Eugene

#2
Save the number in a variable/series?
profile picture

thetraderman

#3
Eugene, Cone,

I've been trying to implement what you said but this is the issue I am running into. When in backtest mode if I have 800 bars on the pane Bars.Count-1 is fixed to 799 thoughout the whole test. If however I insert bars after 799 then Bars.Count updates. This is true for realtime data as well. I really would like to know if there is a way to get the Bars.Count number in back testing mode as WL goes though each and every bar. The reason for this is my indicator as all indicators has a lag so I want to update my signal to occur at the latest bar and not some bar in the past after the fact. There must be a way to do it. I saved the bars going foward which seems to work (i.e., bar 800, 801, etc) after the base was already created but currently I am missing the backtesting history which is important. I guess this is the problem I have with a two loop system which I am struggling to overcome.

Thanks,
Dan
profile picture

Eugene

#4
Clarification needed:
QUOTE:
The reason for this is my indicator as all indicators has a lag so I want to update my signal to occur at the latest bar and not some bar in the past after the fact.

Many indicators have a lag by design so what's the problem. In other words, what is so unique about your algorithm that it requires two trading loops and all these complications? I don't get it.
profile picture

thetraderman

#5
At the time of the design I was unaware that I couldn't use two loops. Now that I have the thing written it is way too much work to change the architecture especially at this point. As a result, I'm trying to get what I have working. Any suggestions to the question above?
profile picture

Eugene

#6
No suggestions from me as I give up understanding this construct in lack of details. However, when I faced shortcomings before due to my own poor initial design, I took some time to rewrite the whole thing or refactor the most problematic zones. This way I avoided ending up knee deep in unreadable code that needs more and more crutches to maintain.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).