Creator Message:
Interpreting Elder-Ray Indicator, according to Dr . Alexander Elder
Bull Power should remain positive in normal circumstances, while Bear Power should remain negative in normal circumstances. In case the Bull Power indicator enters into negative territory, this implies that sellers have overcome buyers and control the market. In case the Bear Power indicator enters into positive territory, this indicates that buyers have overcome sellers and control the market. A trader should not go long at times when the Bear Power indicator is positive and he/she should not go short at times when the Bull Power indicator is negative.
13-period EMAs slope can be used in order to identify the direction of the major trend. According to Elder, the most reliable buy signals are generated, when there is a bullish divergence between the Bear Power indicator and the price (Bear Power forms higher lows, while the market forms lower lows). The most reliable sell signals are generated, when there is a bearish divergence between the Bull Power indicator and the price (Bull Power forms lower highs, while the market forms higher highs).
There are four basic conditions, required to go long or short, with the use of the Elder-Ray method alone.
In order to go long:
1. The market is in a bull trend, as indicated by the 13-period EMA
2. Bear Power is in negative territory, but increasing
3. The most recent Bull Power top is higher than its prior top
4. Bear Power is going up from a bullish divergence
The last two conditions are optional that fine-tune the buying decision
In order to go short:
1. The market is in a bear trend, as indicated by the 13-period EMA
2. Bull Power is in positive territory, but falling
3. The most recent Bear Power bottom is lower than its prior bottom
4. Bull Power is falling from a bearish divergence
The last two conditions are optional, they provide a stronger signal for shorting but they are not absolutely essential
If a trader is willing to add to his/her position, he/she needs to:
1. add to his/her long position, when the Bear Power falls below zero and then climbs back into positive territory
2. add to his/her short position, when the Bull Power increases above zero and then drops back into negative territory.
Trading success is all about following your trading strategy and the indicators should fit within your trading strategy, and not to be traded upon solely
Disclaimer: The script is for informational and educational purposes only. Use of the script does not constitute professional and/or financial advice. You alone have the sole responsibility of evaluating the script output and risks associated with the use of the script.
CODE:
CSS:
#//# * Study : Bull vs Bear Power
#//# * Author : © dgtrd
#https://www.tradingview.com/v/fadiBynQ/
#indicator('Bull vs Bear Power by DGT', 'ARENA ?? DGT ??', max_bars_back=500)
# Converted by Sam4Cok@Samer800 - 03/2023
declare lower;
#// -Input ================== //
input length = 13; # 'Exponential Moving Average Length'
input PlotAsSumOfBullAndBearPower = no; # 'Plot as Sum of Bull and Bear Power'
input DisplayAs = {default "Histogram", "Line", "Band"}; # 'Display as'
input ReverseBearPowerPlotting = no; # 'Reverse Bear Power Plotting'
input barColor = no; # 'Apply Bull Bear Power Color to Bars'
input SmoothingLength = 1; # 'Smoothing Length'
input DisplayAdxColoredDmiLineAnd = {default "ADX Colored DMI Line, Alone", "Price Divergence/Convergence", "Least Squares of Price Divergence/Convergence", "None"}; # 'ADX Colored DMI Line, and'
input hideTrendLabel = no; # 'Hide Statistical Label'
input hideVolumeLabel = no; # 'Hide Statistical Label'
input histLabel = 0; # 'Historical Label Readings'
input TrendLinePlace = 2.75;
def na = Double.NaN;
def dispBbp = PlotAsSumOfBullAndBearPower;
def revBear = ReverseBearPowerPlotting;
def DisHist = DisplayAs == DisplayAs."Histogram";
def DisLine = DisplayAs == DisplayAs."Line";
def DisBand = DisplayAs == DisplayAs."Band";
def DivConv = DisplayAdxColoredDmiLineAnd == DisplayAdxColoredDmiLineAnd."Price Divergence/Convergence";
def LeastSquare = DisplayAdxColoredDmiLineAnd == DisplayAdxColoredDmiLineAnd."Least Squares of Price Divergence/Convergence";
def none = DisplayAdxColoredDmiLineAnd == DisplayAdxColoredDmiLineAnd."None";
#------ Colors
DefineGlobalColor("green" , CreateColor(76,175,80));
DefineGlobalColor("dgreen" , CreateColor(0,100,0));
DefineGlobalColor("red" , CreateColor(255,82,82));
DefineGlobalColor("dred" , CreateColor(145,0,0));
DefineGlobalColor("yellow" , CreateColor(255,235,59));
DefineGlobalColor("dyellow", CreateColor(255,196,12));
DefineGlobalColor("black" , CreateColor(54,58,69));
DefineGlobalColor("gray" , CreateColor(120,123,134));
DefineGlobalColor("white" , Color.WHITE);
#// -Calculation ====================================================== //
def O = open;
def H = high;
def L = low;
def C = close;
def V = Volume;
def maClose = ExpAverage(C, length);
def hh = Highest(H, length);
def ll = Lowest(L, length);
def hlAvg = (hh + ll) / 2;
def srcAvg = (maClose + hlAvg) / 2;
def bull = ExpAverage((H - maClose), SmoothingLength);
def bear = ExpAverage((L - maClose), SmoothingLength);
def bbp = ExpAverage(bull + bear, SmoothingLength);
def indicator_1 = if DivConv then C - srcAvg else
if LeastSquare then Inertia(C - srcAvg, length) else indicator_1[1];
def diplus = DMI(LENGTH = 14)."DI+";
def diminus = DMI(LENGTH = 14)."DI-";
def adxValue = DMI(LENGTH = 14).ADX;
def nzVolume = if IsNaN(V) then nzVolume[1] else V;
def vAvg = Average(nzVolume, length);
def B = nzVolume * (C - L) / (H - L);
def S = nzVolume * (H - C) / (H - L);
#// Label
#/ -Color ============================================= //
def bullColor = (bull - bull[1]) <= 0;
def bearColor = (bear - bear[1]) <= 0;
def bbpColor = if bbp >= 0 then if bbp[1] < bbp then 1 else 2 else
if bbp[1] < bbp then -2 else -1;
def dmiColor = if diplus >= diminus and adxValue >= 25 then if adxValue > adxValue[1] then 4 else 5 else
if diplus < diminus and adxValue >= 25 then if adxValue > adxValue[1] then -4 else -5 else
if adxValue < 25 and adxValue > 17 then if adxValue > adxValue[1] then -2 else -3 else
if adxValue > adxValue[1] then 2 else 3;
#// -Plot ============================== //
plot ZeroLine = if isNaN(C) then na else 0; # 'Middle Line'
ZeroLine.SetDefaultColor(GlobalColor("gray"));
ZeroLine.SetStyle(Curve.SHORT_DASH);
#/ Additional Indicator
plot AddIndicator = if indicator_1 then indicator_1 else na; # 'Additional Indicator'
AddIndicator.SetDefaultColor(GlobalColor("white"));
AddIndicator.SetLineWeight(2);
plot NegBullHistDn = if disHist and !dispBbp and bull < 0 and revBear then bull else na;#, 'Bull Power Histogram', color=bullColor, style=plot.style_columns, editable=false)
plot NegBearHistUp = if disHist and !dispBbp and -bear >= 0 and revBear then -bear else na;#, 'Bear Power Histogram', color=bearColor, style=plot.style_columns, editable=false)
plot NegBullHistUp = if disHist and !dispBbp and bull >= 0 and revBear then bull else na;#, 'Bull Power Histogram', color=bullColor, style=plot.style_columns, editable=false)
plot NegBearHistDn = if disHist and !dispBbp and -bear < 0 and revBear then -bear else na;#, 'Bear Power Histogram', color=bearColor, style=plot.style_columns, editable=false)
plot PosBullHistDn = if disHist and !dispBbp and bull < 0 and !revBear then bull else na;#, 'Bull Power Histogram', color=bullColor, style=plot.style_columns, editable=false)
plot PosBearHistDn = if disHist and !dispBbp and bear < 0 and !revBear then bear else na;#, 'Bear Power Histogram', color=bearColor, style=plot.style_columns, editable=false)
plot PosBearHistUp = if disHist and !dispBbp and bear >= 0 and !revBear then bear else na;#, 'Bear Power Histogram', color=bearColor, style=plot.style_columns, editable=false)
plot PosBullHistUp = if disHist and !dispBbp and bull >= 0 and !revBear then bull else na;#, 'Bull Power Histogram', color=bullColor, style=plot.style_columns, editable=false)
PosBullHistUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PosBearHistUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PosBearHistDn.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PosBullHistDn.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
NegBearHistUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
NegBullHistUp.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
NegBearHistDn.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
NegBullHistDn.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PosBullHistUp.AssignValueColor(if bullColor then GlobalColor("green") else GlobalColor("dgreen"));
PosBearHistUp.AssignValueColor(if bearColor then GlobalColor("dred") else GlobalColor("red"));
PosBearHistDn.AssignValueColor(if bearColor then GlobalColor("dred") else GlobalColor("red"));
PosBullHistDn.AssignValueColor(if bullColor then GlobalColor("green") else GlobalColor("dgreen"));
NegBullHistUp.AssignValueColor(if bullColor then GlobalColor("green") else GlobalColor("dgreen"));
NegBearHistUp.AssignValueColor(if bearColor then GlobalColor("dred") else GlobalColor("red"));
NegBearHistDn.AssignValueColor(if bearColor then GlobalColor("dred") else GlobalColor("red"));
NegBullHistDn.AssignValueColor(if bullColor then GlobalColor("green") else GlobalColor("dgreen"));
PosBullHistUp.SetLineWeight(3);
PosBearHistUp.SetLineWeight(3);
PosBearHistDn.SetLineWeight(3);
PosBullHistDn.SetLineWeight(3);
NegBearHistUp.SetLineWeight(3);
NegBullHistUp.SetLineWeight(3);
NegBearHistDn.SetLineWeight(3);
NegBullHistDn.SetLineWeight(3);
#--- Line plot
plot BullPline = if disLine and !dispBbp then bull else na; # 'Bull Power Line'
plot BearPline = if disLine and !dispBbp then if revBear then -bear else bear else na; # 'Bear Power Line'
BullPline.AssignValueColor(if bullColor then GlobalColor("green") else GlobalColor("dgreen"));
BearPline.AssignValueColor(if bearColor then GlobalColor("dred") else GlobalColor("red"));
BullPline.SetLineWeight(2);
BearPline.SetLineWeight(2);
#-- Band Plot--
def bullstdv = 0.236 * stdev(bull, length);
def bearstdv = 0.236 * stdev(bear, length);
plot p1 = if disBand and !dispBbp then bull - bullstdv else na; # 'Bull Power Band, Lower Line'
plot p2 = if disBand and !dispBbp then bull + bullstdv else na; # 'Bull Power Band, Upper Line'
AddCloud(if !bullColor then na else p2, p1, GlobalColor("dgreen"));
AddCloud(p2, p1, GlobalColor("dgreen"));
plot p3 = if disBand and !dispBbp then if revBear then -bear + bearstdv else bear - bearstdv else na; #'BearPowerBandLowerLine'
plot p4 = if disBand and !dispBbp then if revBear then -bear - bearstdv else bear + bearstdv else na; #'BearPowerBandUpperLine'
AddCloud(if !bearColor then p4 else na, p3, GlobalColor("dred"));
AddCloud(p4, p3, GlobalColor("dred"));
plot bvbpHist = if disHist and dispBbp then bbp else na; # 'Bull vs Bear Power Histogram'
plot bvbpLine = if disLine and dispBbp then bbp else na; # 'Bull vs Bear Power Line'
bvbpHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
bvbpHist.SetLineWeight(3);
bvbpHist.AssignValueColor(if bbpColor==1 then GlobalColor("dgreen") else
if bbpColor==2 then GlobalColor("green") else
if bbpColor==-2 then GlobalColor("red") else GlobalColor("dred"));
bvbpLine.SetLineWeight(2);
bvbpLine.AssignValueColor(if bbpColor==1 then GlobalColor("dgreen") else
if bbpColor==2 then GlobalColor("green") else
if bbpColor==-2 then GlobalColor("red") else GlobalColor("dred"));
plot p5 = if disBand and dispBbp then bbp - bearstdv else na; # 'Bull vs Bear Power Band, Lower Line'
plot p6 = if disBand and dispBbp then bbp + bearstdv else na; # 'Bull vs Bear Power Band, Upper Line'
AddCloud(if bbpColor>0 then p6 else na, p5, GlobalColor("dgreen"),GlobalColor("dgreen"));
AddCloud(if bbpColor==2 then na else p5, p6, GlobalColor("dgreen"), GlobalColor("dgreen"));
AddCloud(if bbpColor==-2 then p6 else na, p5, GlobalColor("dred"), GlobalColor("dred"));
AddCloud(if bbpColor>0 then p6 else na, p5, GlobalColor("dred"), GlobalColor("dred"));
p1.AssignValueColor(if bullColor then GlobalColor("green") else GlobalColor("dgreen"));
P3.AssignValueColor(if bearColor then GlobalColor("dred") else GlobalColor("red"));
P4.AssignValueColor(if bearColor then GlobalColor("dred") else GlobalColor("red"));
p2.AssignValueColor(if bullColor then GlobalColor("green") else GlobalColor("dgreen"));
p5.AssignValueColor(if bbpColor==1 then GlobalColor("dgreen") else
if bbpColor==2 then GlobalColor("green") else
if bbpColor==-2 then GlobalColor("red") else GlobalColor("dred"));
p6.AssignValueColor(if bbpColor==1 then GlobalColor("dgreen") else
if bbpColor==2 then GlobalColor("green") else
if bbpColor==-2 then GlobalColor("red") else GlobalColor("dred"));
#// Colored DMI
plot AdxUp = if !None and diplus >= diminus then TrendLinePlace else na;
plot AdxDn = if !None and diplus < diminus then TrendLinePlace else na;
AdxUp.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
AdxDn.SetPaintingStrategy(PaintingStrategy.SQUARES);
AdxUp.AssignValueColor(if dmiColor==4 then GlobalColor("dgreen") else
if dmiColor==5 then GlobalColor("green") else
if dmiColor==-4 then GlobalColor("dred") else
if dmiColor==-5 then GlobalColor("red") else
if dmiColor==-2 then GlobalColor("black") else
if dmiColor==-3 then GlobalColor("gray") else
if dmiColor==2 then GlobalColor("dyellow") else GlobalColor("yellow"));
AdxDn.AssignValueColor(if dmiColor==4 then GlobalColor("dgreen") else
if dmiColor==5 then GlobalColor("green") else
if dmiColor==-4 then GlobalColor("dred") else
if dmiColor==-5 then GlobalColor("red") else
if dmiColor==-2 then GlobalColor("black") else
if dmiColor==-3 then GlobalColor("gray") else
if dmiColor==2 then GlobalColor("dyellow") else GlobalColor("yellow"));
#--- BarColor
AssignPriceColor(if !barColor then Color.CURRENT else
if bbpColor==1 then GlobalColor("dgreen") else
if bbpColor==2 then GlobalColor("green") else
if bbpColor==-2 then GlobalColor("red") else GlobalColor("dred"));
#--- LAbels
def dmiText = if diplus >= diminus and adxValue >= 25 then 1 else
if diplus < diminus and adxValue >= 25 then -1 else 0;
def volBuy = Round(B / (B + S) * 100, 2);
def volSel = Round(S / (B + S) * 100, 2);
AddLabel(!hideTrendLabel,if dmiText[histLabel]>0 then "Bull Trend" else
if dmiText[histLabel]<0 then "Bear Trend" else "No Trend",
if dmiColor[histLabel]==4 then GlobalColor("dgreen") else
if dmiColor[histLabel]==5 then GlobalColor("green") else
if dmiColor[histLabel]==-4 then GlobalColor("dred") else
if dmiColor[histLabel]==-5 then GlobalColor("red") else
if dmiColor[histLabel]==-2 then GlobalColor("black") else
if dmiColor[histLabel]==-3 then GlobalColor("gray") else
if dmiColor[histLabel]==2 then GlobalColor("dyellow") else GlobalColor("yellow"));
AddLabel(!hideVolumeLabel, "buying vol %" + volBuy[histLabel], Color.WHITE);
AddLabel(!hideVolumeLabel, "selling vol %" + volSel[histLabel], Color.WHITE);
#--- End Code
Last edited by a moderator: