Plot Arrow Offset from Current Bar


Category:
0
0

I wrote a script to plot “proper” highs and lows on a chart.  A proper high is defined as a high with two lower bars to the left and two lower bars to the right.  A proper low is a low with two higher bars to the left and two lower bars to the right.   The script appears below, but the offset variable does not appear to be working properly as the arrows plot at the completion of the pattern and not at the true high or low.  Can you help?  Thanks.

#Proper_HiLo

def h_1 = high[4];
def h_2 = high[3];
def h = high[2];
def h1 = high[1];
def h2 = high;

def l_1 = low[4];
def l_2 = low[3];
def l = low[2];
def l1 = low[1];
def l2 = low;
def offset=-2;


def PropHi = h_1 < h and h_2 < h and h1 < h and h2 < h;
def PropLo = l_1 > l and l_2 > l and l1 > l and l2 > l;


plot hi_arrow = if PropHi[offset] then h else double.NaN;
plot lo_arrow = if PropLo [offset] then l else double.NaN;


hi_arrow.AssignValueColor(GetColor(1));
hi_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

lo_arrow.AssignValueColor(GetColor(1));
lo_arrow.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Marked as spam
Posted by (Questions: 2, Answers: 0)
Asked on December 4, 2020 4:39 pm
378 views
0
Private answer

There is no need to try and work this out on your own. The solution is already available as a built-in pattern on Thinkorswim. For details on where to find it and how to load it onto your chart you can check the solution from the following post:

https://www.hahn-tech.com/ans/displaying-values-for-swing-high-and-low-pivots/

Just skip the steps that describe how to change the plots to values.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on December 4, 2020 5:32 pm