Prosperity
New member
I am working on a script to plot a trendline based on the following 5 conditions. I've made some progress but I am stuck on getting a conditional expression to work. Any help is appreciated.
CODE:
This code works and I am able to plot trend lines, except on inside or outside days.
The next step in the process requires an "if-else" conditional expression. Specifically, on an inside day (ID), if the previous day were a "plot up" day (meaning the trendline connects to the high of the previous day), the inside day would be a "plot down" day (line connects to the low of the ID). On the other hand, if the last day were a "plot down" day (meaning the line connects to the low of the previous day), the inside day would be a "plot up" day (trend line connects to the ID's high). I am struggling to find a way to define the previous day as either "plot up" or "plot down." I am also unsure which syntax to use to extend the trend line. For example, can one study have multiple conditions to draw the line, or is it better to do separate studies for each condition since they should all connect in theory?
CODE:
Code:
#Trend Line
#Higher Highs, Higher Lows
def HH = high[0]>high[1] AND low[0]>=low[1];
#Lower Highs, Lower Lows
def LL = high[0]<=high[1] AND low[0]<low[1];
#Inside Day
def ID = high[0]<=high[1] AND low[0]>=low[1];
#Outside Day Up
def ODU=high[0]>high[1] AND low[0]<low[1] AND close[0]>open[0];
#Outside Day Down
def ODD=high[0]>high[1] AND low[0]<low[1] AND close[0]<open[0];
#higher highs higher lows
plot up = if HH then high else double.NaN;
#lower highs lower lows
plot down = if LL then high else double.NaN;
This code works and I am able to plot trend lines, except on inside or outside days.
The next step in the process requires an "if-else" conditional expression. Specifically, on an inside day (ID), if the previous day were a "plot up" day (meaning the trendline connects to the high of the previous day), the inside day would be a "plot down" day (line connects to the low of the ID). On the other hand, if the last day were a "plot down" day (meaning the line connects to the low of the previous day), the inside day would be a "plot up" day (trend line connects to the ID's high). I am struggling to find a way to define the previous day as either "plot up" or "plot down." I am also unsure which syntax to use to extend the trend line. For example, can one study have multiple conditions to draw the line, or is it better to do separate studies for each condition since they should all connect in theory?
Last edited: