gravityflyer
New member
Hi all,
I just wanted to share my first thinkScript indicator and kindly seeking your assistance in refining the code.
In short, the indicator works as I intended. Yay for me! That said, the presentation needs more refinement. Some issues I'm having:
I just wanted to share my first thinkScript indicator and kindly seeking your assistance in refining the code.
Code:
# Potential Breakout (PBO) indicator
# gravityflyer
# v1.0 - 2021.04.05
declare lower;
declare real_size;
#Input Price Line
input priceType = PriceType.LAST;
plot LastPrice = close(priceType = priceType);
LastPrice.SetDefaultColor(GetColor(7));
#Input Bolinger Band Width
input averageType = AverageType.Simple;
input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -1.0;
input Num_Dev_Up = 1.0;
input BulgeLength = 150;
input SqueezeLength = 150;
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).LowerBand;
def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_Up, averageType).MidLine;
plot Bandwidth = (upperBand - lowerBand) / midLine * 100;
Bandwidth.SetDefaultColor(Color.WHITE);
#Painting Strategy
LastPrice.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
LastPrice.DefineColor("Normal", Color.GRAY);
LastPrice.DefineColor("BuySignal", Color.GREEN);
LastPrice.DefineColor("SellSignal", Color.RED);
LastPrice.AssignValueColor(if LastPrice > upperBand then LastPrice.Color("BuySignal") else if LastPrice < lowerBand then LastPrice.Color("SellSignal") else LastPrice.Color("Normal"));
#Input Reference Line
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(8));
ZeroLine.setStyle(Curve.SHORT_DASH);
In short, the indicator works as I intended. Yay for me! That said, the presentation needs more refinement. Some issues I'm having:
- The scale is obviously not consistent with the price/BB superimposed. I thought "declare real_size" would fix the issue?
- How do I fill the upper and lower bands with a color, ideally with a lower opacity? Would that be with the "Add.Cloud" code? As indicated by the code, buy/sell signals would occur above/below such values.
- In terms of painting strategy, you'll notice it's painting the LastPrice and thus the signal is slightly delayed (see pic below). Is there a way to repaint on the current price or should I not worry about it?
- Finally, how can I add buy/sell signals at the bottom of the indicator below the 0 reference line?