Hello shaeffer,
Your logic seems to be on the right track. See Alex's reply for the coding solution.
You're most welcome as always.
When you request .getValue(0) or .getValue(-1), the index value always refers to the bar, not individual ticks. -1 always gives you the previous bar regardless if the formula is processing historical bars or the real time tick data on bar 0. The logic you need to keep track of the previous tick is similar to the color1 and color0 logic Alex pointed you in his reply. Create two global variables (myTick, myTick1). myTick will be immediately assigned with the .getValue(0) method. At the top of main(), or before the .getValue(0) assignment occurs, assign myTick1 with myTick. Now you have two variables that contain the current tick value and the previous tick value that occur on bar 0. Note that this can't be used with setComputeOnClose() as it needs to be evaluated on a tick-by-tick basis.
Correct.
Let me know if my responses above did not answer this question for you. The only difference between local and global variables is the the values assigned to a global variables will remain for the life of the formula. A local variable declared inside main(), or any other user-defined function, will only exist for the single execution of the function. Once the function has executed all of it's contained code, the local variables and the values they were assigned are destroyed, or removed from memory. You won't be able to refer to those values on subsequent calls of main() or other user-defined functions.
No sir, I am not.
Originally posted by shaeffer
Hi Jason,
My reason for painting the historic bars is so I can readily see the 'if condition' associated with the most recent bar, in multiple tiny charts. If I paint the Bg of just the most current bar, it will be too narrow to notice, hence I also repaint the previous 9 bars with the same color as the most recent bar. So I need to check (on every tick) if the most recent tick changes the 'if' condition, in which case all previous 9 bar Bg colors need to change. So I think your BAR_STATE suggestion doesn't apply in this application? (I had asked / hoped for a new setStudyBgColor command (similar to setChartBgColor) that might more efficiently do this, but looks like no luck in the near future).
I'm still thinking that a new if statement within each condition that checks if the current condition is the same as the last tick, and if so then does not repaint the previous bars with the same color they already are, might improve efficiency. But if the current tick did result in a new if condition, then repainting a different color would occur.
Hi Jason,
My reason for painting the historic bars is so I can readily see the 'if condition' associated with the most recent bar, in multiple tiny charts. If I paint the Bg of just the most current bar, it will be too narrow to notice, hence I also repaint the previous 9 bars with the same color as the most recent bar. So I need to check (on every tick) if the most recent tick changes the 'if' condition, in which case all previous 9 bar Bg colors need to change. So I think your BAR_STATE suggestion doesn't apply in this application? (I had asked / hoped for a new setStudyBgColor command (similar to setChartBgColor) that might more efficiently do this, but looks like no luck in the near future).
I'm still thinking that a new if statement within each condition that checks if the current condition is the same as the last tick, and if so then does not repaint the previous bars with the same color they already are, might improve efficiency. But if the current tick did result in a new if condition, then repainting a different color would occur.
I will move the multiple bar index -10 command outside the loop, as you suggested, thanks.
Our previous discussions re built in series objects in main() were for one value being retreived from the series. This time we've got two, the (-1) and the (0) values, so I need to think about how to do this. Since the (0) value in the current tick evaluation becomes the (-1) value in the next tick evaluation, should I create a global variable for the (-1) value and as the last line in main(), make the (0) value = the (-1) value. Then the (-1) value would be known already as the next tick evaluation starts? Is that the idea?
From our previous discussions, I know the entire series is born in the efs engine when the earliest bar is created. And at that time, I beleive all bar index values (associated with the chart interval) are defined within the series. But then in real time, each bar gets 'built', tick by tick. I'm fumbling here..... I see the need for a global variable for the (-1) value. Is there also a need for a global variable for the real time (0) value, or should that only be a local variable?
From our previous discussions, I know the entire series is born in the efs engine when the earliest bar is created. And at that time, I beleive all bar index values (associated with the chart interval) are defined within the series. But then in real time, each bar gets 'built', tick by tick. I'm fumbling here..... I see the need for a global variable for the (-1) value. Is there also a need for a global variable for the real time (0) value, or should that only be a local variable?
PHP Code:
var myTick = null;
var myTick1 = null;
var myStudy = null;
var bInit = false;
function main() {
if (bInit == false) {
myStudy = macdHist(5, 35, 5);
bInit = true;
}
myTick1 = myTick;
myTick = myStudy.getValue(0);
if (myTick == null || myTick1 == null) return; // validate vars before use with
//conditional statements that follow.
}
I will define two local variables so there is only one each .getValue() call. Is it correct though that since I have a string of if/else if statements, they would only be called once for each tick?
-------------------------
I'm still a little confused re: historical bars series (interval) values vs real time (0) and (-1) tick values, relative to use of global vs local variables, but hopefully answers to the above will clarify this for me.
Regards
shaeffer
I'm still a little confused re: historical bars series (interval) values vs real time (0) and (-1) tick values, relative to use of global vs local variables, but hopefully answers to the above will clarify this for me.
Regards
shaeffer
(P.S. are you involved at all in the quote sheet efs formula initiative?)
Comment