I have an indicator written in Pine Script where I measure volume flow with two lines with different length. I noticed when two lines run in sync and go through the middle, it's the position where I can potentially open longs/shorts (please, check the screenshot below, red lines for shorts and green lines for longs). The second indicator is the mirrored version of the original one.
Now I want to write a code to understand whether white and green line go in sync. By saying that they go in sync, I mean two lines go in the same direction at almost the same angle (please, check the screenshots below). I drew kinda linear regression lines on the indicator graph to show the direction of the lines.
the same situation, but smaller scale
Could you say how to understand that the lines are going in sync and what's the idea for Pine Script for this?
I tried this code. vfinal is the white line with shorter length and vfinal2 is the green line with longer length.
var int mode = 0
if (vfinal2 > 6 and mode == 0) // whether the green line went upwards
mode := 1
lab = label.new(x = bar_index, y = 0, yloc = yloc.belowbar, style = label.style_label_up, text = "Mode1", textcolor = color.white, size = size.normal, color = color.green)
if (mode == 1 and vfinal[1] > 0 and vfinal < 0 and (abs(vfinal2 - vfinal) < 1.5 or abs(vfinal - vfinal2) < 1.5)) // Sell
lab = label.new(x = bar_index, y = 0, yloc = yloc.abovebar, style = label.style_label_down, text = "Sell", textcolor = color.white, size = size.normal, color = color.blue)
mode := 0
if (vfinal2[1] > -1 and vfinal2 < -1) // mode := 0
mode := 0
The idea was to identify when green line went upwards and gets value more than 6 (to exclude situations when lines go back and forth through the middle). Then, when we get there, we check whether the white line went through the middle and whether both lines were near each other. If yes, then we Sell. If the green line went through -1, then we stop waiting for short position.