I'm trying to use chatgpt to code because I'm illiterate basically when it comes to coding. But If i can get this going that would be amazing and I'll post my VSA code that is working really well. I'm trying to get a tradingview indicator by lonesomeblue consolidation box live to convert:
The script is also capable of identifying three potential directions that the price may move after breaking out of the consolidation zone. These directions are:
- Moving outside the consolidation zone above or below the high or low of the consolidation box area and then reversing back the entire distance of the box in the opposite direction.
- Moving outside the consolidation zone and continuing to go up with a lot of momentum.
- Reversing to the median price point after going up and then coming down.
If the price bounces off the median price line, the script labels the trend direction it will be going with momentum or breaking out. The same goes for when the price does not reverse outside the consolidation box.
input prd = 10;
input conslen = 5;
input paintcons = yes;
input zonecol = color.blue;
def hb_ = highestbars(prd) == 0 ? high : Double.NaN;
def lb_ = lowestbars(prd) == 0 ? low : Double.NaN;
def dir = 0;
def zz = Double.NaN;
def pp = Double.NaN;
dir = if (hb_ and !isNaN(lb_)) then 1
else if (lb_ and !isNaN(hb_)) then -1
else dir;
if (hb_ and lb_) {
if (dir == 1) {
zz = hb_;
} else {
zz = lb_;
}
} else {
zz = if (hb_) then hb_
else if (lb_) then lb_
else Double.NaN;
}
def condhigh = if (dir == 1) then highest(conslen) else Double.NaN;
def condlow = if (dir == -1) then lowest(conslen) else Double.NaN;
def consArea = if (paintcons) then zonecol else color.white;
AddCloud(condhigh, condlow, consArea);
def breakoutup = if high > condhigh and low > condlow then yes else no;
def breakoutdown = if low < condlow and high < condhigh then yes else no;
def upmomentum = if high > condhigh and low <= condhigh then yes else no;
def downmomentum = if low < condlow and high >= condlow then yes else no;
Alert(breakoutup, "Breakout Up", Alert.BAR, Sound.Ding);
Alert(breakoutdown, "Breakout Down", Alert.BAR, Sound.Ding);
Alert(upmomentum, "Up Momentum", Alert.BAR, Sound.Chimes);
Alert(downmomentum, "Down Momentum", Alert.BAR, Sound.Chimes);