rottentrade
Member
I can use a little help here. Basically I want to incrementally add up points with every bar. So if the first bar went up 3 points, the second up 5 points, and the third down 3 points, it would be 3 + 5 - 3 = 5 points.
I came up with a simple code to do this and it does its job. However, the first bar is not calculating the number correctly, so all the subsequent bars are off as well.
Here's my code and the chart. As you can see, inside the bubble are two numbers. The first one is the BH (body height) and the second is PL (total profit/loss).
To give you an example, consider the SECOND BAR. Here [9.25 : -29.5] means it's body size is 9.25 and the PL is -29.5 (-20.25 from the prior bar's PL and -9.25 from the current bar). However, the problem is with the FIRST BAR, where it says [4.25 : -20.25]. Here, 4.25 is correct but -20.25 is not. It should be the same for both values, eg [4.25 : 4.25]. I don't know where the -20.25 came from, and because of this all the bars that come after are off (obviously!). Any suggestion to get this fixed???
I came up with a simple code to do this and it does its job. However, the first bar is not calculating the number correctly, so all the subsequent bars are off as well.
Here's my code and the chart. As you can see, inside the bubble are two numbers. The first one is the BH (body height) and the second is PL (total profit/loss).
To give you an example, consider the SECOND BAR. Here [9.25 : -29.5] means it's body size is 9.25 and the PL is -29.5 (-20.25 from the prior bar's PL and -9.25 from the current bar). However, the problem is with the FIRST BAR, where it says [4.25 : -20.25]. Here, 4.25 is correct but -20.25 is not. It should be the same for both values, eg [4.25 : 4.25]. I don't know where the -20.25 came from, and because of this all the bars that come after are off (obviously!). Any suggestion to get this fixed???
Code:
def BH = BodyHeight();
def diff = close - open;
def PL = IF IsNaN(BH[1]) THEN diff ELSE PL[1] + diff; ### Since BH[1] for the first bar will be NaN, Would this not work?
AddChartBubble(high + 0.2, BH + ":" + PL, Color.LIGHT_ORANGE, yes);