♥ 0 |
I tried to display a bubble at the mid point of a plot. Tried in two ways. (1) One show at the mid point of the chart excluding expansion area on the right. (1) Second at Mid point of the chart including expansion area. First one does not work. But Second one works. My code is as follows (with comments next to the code) declare lower; Plot Line1=1; def lastBar = if IsNaN(close())then double.Nan else barNumber() ; #(last bar was at 61) def TotBars = HighestAll(BarNumber()); #(including 10 bar expansion, total bars=71) AddLabel( yes, Concat(lastBar, TotBars), Color.RED ); * shows correctly 61 and 71 AddChartBubble( barNumber() ==lastBar/ 2 or barNumber() == ((lastBar / 2) + .5), 1, concat(barnumber(), lastBar ) , Color.YELLOW, yes); #prints at bar#1 and shows LastBar=1 AddChartBubble( barNumber() == TotBars / 2 or barNumber() == ((TotBars / 2) + .5), 0, Concat(barnumber(), totBars) , Color.YELLOW, yes); #prints correctly at bar 36 shows totBars=71 I feel I do not understand how Thinkscript variables work (or made some stupid error!~). I am confused why the value of totbars remained unchanged at 71 while Lastbar was changed to 1 and did not remain at 61. Also note that lastBar was not set to 2, 3 at each bar but stopped at 1. Thanks
Marked as spam
|
Please log in to post questions.
The code I posted produced same issue on any chart of any period. Could not post another screenshot in this comments section but the one I posted was for stock symbol MU, a 3 Month daily chart as of 4/1/2018 with 61 closed bars and a 10 bar right expansion area. I tried to show the bubble at the point corresponding to bar 31 (the middle of closed bars). That did not work. It displayed at Bar #1. Still learning programming and wanted to see if you could help resolve my confusion as to why a variable (Last Bar which was 61 in Add Label is getting reset later. I tried the other variable including expansion area just to see a what-happens-if-I-did-that. I really can work without displaying any bubble at all on the chart.. this exercise is just is to learn thinkscript from my mistakes.
BTW The OR statement is to get the “mid” point of total bars depending on whether the total bars are even or odd. Putting parentheses around the statement with the OR condition did not change the result