* This is a momentum not trend indicator. I added cloud color and dynamic threshold option
Author Message:
Background
Momentum effect is generally called "inertia effect". Momentum effect was proposed by Jegadeesh and Titman (1993), which refers to the tendency of the return rate of the stock to continue the original direction of movement, that is, the return rate of the stock with a higher return rate in the past period will still be higher than the return rate in the past low-yielding stocks.
Function
The Bullish and Bearish Momentum Technical Indicator is a strategy for buying and selling by analyzing the strength and weakness of recent price trends. Traders seek to take advantage of the rising or falling trend of stock prices. When this technical indicator indicates that the stock is entering a strong upward trend, the trader will buy the stock; Will choose to short the stock.
In short, momentum trading is trading with the trend. Momentum trading is based on the idea that if there is enough momentum behind the current price action, it will continue to move in the same direction. When an asset reaches a higher price, it usually attracts more investor attention, driving up the market price. The price rise continues until sellers start to enter the market consistently, and once sellers slowly outpace buyers, momentum weakens and the trend may reverse.
I have not marked special tags for this indicator usage. Users are expected to define according to their own understanding. On the whole, the basic usage is to start long positions when the first green column appears; when the first red column appears, close long positions or open short positions.
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#// © blackcat1402
#study("[blackcat] L2 Bull-Bear Momentum","L2 Bull-Bear Momentum", overlay=false, max_bars_back=5000, max_labels_count =500)
# Converted by Sam4Cok@Samer800 - 12/2022
declare lower;
declare zerobase;
#//input
input ShowCloud = yes;
input scaler = 1.0;
input DynamicThreshold = yes;
input ManualThreshold = 1.0;
input periodForDynamicThreshold = 100;
#--Calc
def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def h = high; def l = low; def c = close; def o =open;
script dev {
input source = close;
input length = 14;
def mean = Average(source, length);
def sum;
sum = fold i = 0 to length - 1 with p do
p + AbsValue(source[i] - mean);
def dev = sum/length;
plot retutn = dev;
}
#//algo
def var1c = ExpAverage(100 * (c - Lowest(l[1], 100)) / (Highest(h[1], 100) - Lowest(l[1], 100)), 13) / 4 * scaler;
def var1d = ExpAverage(c, 2) - ExpAverage(c, 89) * scaler;
def var1e = ExpAverage(var1d, 30) * scaler;
def var1f = 2 * (var1d - var1e) * 10 * scaler;
def var20 = Power(var1f, 3) * 0.1 + Power(var1f, 2) * scaler;
def var21 = Sqrt(Sqrt(l * h * o * c));
def var22 = ExpAverage(var21 * 0.97, 3) * scaler;
def var23 = (h + l + c) / 3 * scaler;
def var24 = (var23 - Average(var23, 14)) / (0.015 * dev(var23, 14)) * scaler;
def var25 = If(var1f > 0.015, var20, 0) / 45 * scaler;
def yz = var25 / 10;
def var26 = ExpAverage(c, 2) - ExpAverage(c, 150);
def var27 = ExpAverage(var26, 100);
def var28 = 2 * (var26 - var27);
def var29 = Power(var28, 3) * 0.1 + Power(var28, 1);
def var2a = Sqrt(Sqrt(l * h * o * c));
def var2b = ExpAverage(var2a * 0.97, 3);
def var2c = (h + l + c) / 3;
def var2d = (var2c - Average(var2c, 14)) / (0.015 * dev(var2c, 14));
def zl = If(var28 > 0.1, var29, 0) * 5 / 10;
def bear = ExpAverage((zl + yz), 22);
def bull = If(bear > bear[1], bear, na);
#//plots
def avgBear = stdev(bear,20);
def DynLine = if !DynamicThreshold then na else highest(avgBear, periodForDynamicThreshold);
plot DynamicLine = DynLine;
DynamicLine.SetDefaultColor(Color.ORANGE);
plot thresholdLine = if isNaN(c) or DynamicThreshold then na else ManualThreshold;
thresholdLine.SetDefaultColor(Color.ORANGE);
thresholdLine.SetStyle(Curve.LONG_DASH);
def thresh = if DynamicThreshold then DynamicLine else thresholdLine;
plot bullHist = bull;
bullHist.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
bullHist.AssignValueColor(if thresh>bullHist then CreateColor(143,255,143) else Color.DARK_GREEN);
plot bearHist = if !isNaN(bull) then na else bear;
bearHist.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
bearHist.AssignValueColor(if thresh>bearHist then CreateColor(255,143,143) else Color.DARK_RED);
#--- cloud Color
AddCloud(if !ShowCloud then na else if !isNaN(bearHist) then if thresh<bearHist then pos else neg else na,if thresh<bearHist then neg else pos, Color.DARK_RED, CreateColor(255,143,143));
AddCloud(if !ShowCloud then na else if isNaN(bearHist) then if thresh<bullHist then pos else neg else na, if thresh<bullHist then neg else pos, Color.DARK_GREEN, CreateColor(143,255,143));
#--- END Code
Last edited by a moderator: