That title probably sounds confusing. This seems simple, but I can't seem to get it.
This code is set to the SMA. It simply counts how many consecutive bars have passes where the current SMA is greater than the previous SMA. If the current SMA is less than the previous, it resets to 0. I then create a label to see the value.
def trend = if SMA > SMA[1] then trend[1] + 1 else 0;
AddLabel(showTrendLabel, length + " SMA trend: " + trend, if trend >= minimumTrendLength then Color.GREEN else Color.RED);
With that I get what I want. Trend is the number of consecutive bars the current SMA was greater than the previous. Now, I simply want to plot one arrow at the beginning of the latest trend.
I thought it would be as easy as plotting an arrow at Close[trend]. But that would only work if it plotted the arrow after the SMA finished plotting. Also, it appears you can't use a variable in this context as the index number. I keep getting an error saying it expects a constant.
So, basically, I know how many bars I want to go back from the last bar and plot an arrow, but I don't know how to make that work.
This code is set to the SMA. It simply counts how many consecutive bars have passes where the current SMA is greater than the previous SMA. If the current SMA is less than the previous, it resets to 0. I then create a label to see the value.
def trend = if SMA > SMA[1] then trend[1] + 1 else 0;
AddLabel(showTrendLabel, length + " SMA trend: " + trend, if trend >= minimumTrendLength then Color.GREEN else Color.RED);
With that I get what I want. Trend is the number of consecutive bars the current SMA was greater than the previous. Now, I simply want to plot one arrow at the beginning of the latest trend.
I thought it would be as easy as plotting an arrow at Close[trend]. But that would only work if it plotted the arrow after the SMA finished plotting. Also, it appears you can't use a variable in this context as the index number. I keep getting an error saying it expects a constant.
So, basically, I know how many bars I want to go back from the last bar and plot an arrow, but I don't know how to make that work.