Standardized Median Proximity For ThinkOrSwim

eagle_ai

Member
Author states:
Standardized Median Proximity by AlgoAlpha ๐Ÿš€๐Ÿ“Š โ€“ a dynamic tool designed to enhance your trading strategy by analyzing price fluctuations relative to the median value. This indicator is built to provide clear visual cues on the price deviation from its median, allowing for a nuanced understanding of market trends and potential reversals.

y7tNwYV.png


https://www.tradingview.com/script/xv5kGVOP-Standardized-Median-Proximity-AlgoAlpha/

Please kindly convert this to TOS. Thank you.
 
Last edited by a moderator:
Standardized Median Proximity by AlgoAlpha ๐Ÿš€๐Ÿ“Š โ€“ a dynamic tool designed to enhance your trading strategy by analyzing price fluctuations relative to the median value. This indicator is built to provide clear visual cues on the price deviation from its median, allowing for a nuanced understanding of market trends and potential reversals.

https://www.tradingview.com/script/xv5kGVOP-Standardized-Median-Proximity-AlgoAlpha/

Please kindly convert this to TOS. Thank you.
check the below:

CSS:
#// This Pine Scriptโ„ข code is subject to the terms of the Mozilla Public License 2.0 at https:/
#// ยฉ AlgoAlpha
#indicator("Standardized Median Proximity [AlgoAlpha]", "AlgoAlpha - ๐“ข๐“ฝ๐“ช๐“ท๐“ญ๐“ช๐“ป๐“ญ๐“ฒ๐”ƒ๐“ฎ๐“ญ ๐“œ๐“ฎ๐“ญ๐“ฒ๐“ช๐“ท ๐“Ÿ๐“ป๐“ธ๐”๐“ฒ๐“ถ๐“ฒ๐“ฝ๐”‚"
# Converted by Sam4Cok@Samer800    - 05/2024
declare lower;

input ColoredBars = yes; #(true, "Colored Bars?")
input timeframe = {default "Chart TF", "Custom TF"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input displayOptions = {default "Standardized Median Proximity", "Median Proximity Percentile"};
input Source = FundamentalType.CLOSE; #(close, "Source")
input lookbackLength = 21; # "Lookback Length"
input NormlizedMovAvgType = AverageType.HULL;
input NormlizedMovAvgLength = 20; #, minval = 1, title = "HMA Lookback Length")
input stdDevMultiplier = 1.0; #, title = "Standard Deviation Multiplier")
input thresholdForStandardizedMp = 1.5; #, title = "Upper Boundary of Deviation Bands")
input ShowNeutralTrendForStandardizedMp = yes; #(true, "Show Neutral Trend?")
input noiseScatterplotForPercentileMp = yes; #, "Noise Scatterplot")

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def last = IsNaN(close);
def Perc = displayOptions == displayOptions."Median Proximity Percentile";
def neut = ShowNeutralTrendForStandardizedMp;
def priceSource;
switch (timeframe) {
case "Custom TF" :
    priceSource = Fundamental(FundamentalType = Source, Period = customTimeframe);
default :
    priceSource = Fundamental(FundamentalType = Source);
}
DefineGlobalColor("extUp", CreateColor(255,172,50));
DefineGlobalColor("extDn", Color.MAGENTA);
DefineGlobalColor("Up", CreateColor(156, 93, 0));
DefineGlobalColor("Dn", Color.PLUM);

DefineGlobalColor("Gr", CreateColor(0, 255, 107)); #Color.GREEN);
DefineGlobalColor("dGr", CreateColor(0, 104, 44)); #Color.DARK_GREEN);
DefineGlobalColor("Re", CreateColor(254, 0, 82)); #Color.RED);
DefineGlobalColor("dRe", CreateColor(130, 0, 42)); #Color.DARK_RED);
#colorUp = input.color(#00ffbb, title = "Up Color")
#colorDown = input.color(#ff1100, title = "Down Color")

#// Calculations
def medianValue = Median(priceSource, lookbackLength);
def priceDeviation = (priceSource - medianValue);
def standardDeviation = StDev(priceDeviation, 45);
def normVal = priceDeviation / (standardDeviation + standardDeviation);

def positiveValues = if normVal > 0 then normVal else 0;
def negativeValues = if normVal < 0 then normVal else 0;
def posBandStdv = StDev(positiveValues, lookbackLength) * stdDevMultiplier;
def negBandStdv = StDev(negativeValues, lookbackLength) * stdDevMultiplier;
def upperBoundary = ExpAverage(positiveValues, lookbackLength) + posBandStdv;
def lowerBoundary = ExpAverage(negativeValues, lookbackLength) - negBandStdv;
def emaValue = MovingAverage(NormLizedMovAvgType, normVal, NormLizedMovAvgLength);


#// Color Conditions
def ColNorm = if normVal > upperBoundary then  2 else
              if normVal < lowerBoundary then -2 else
      if (normVal<0 and normVal < upperBoundary and emaValue > lowerBoundary and normVal > emaValue and neut) or
         (normVal>0 and normVal > lowerBoundary and emaValue < upperBoundary and normVal < emaValue and neut) then 0 else
      if  normVal>0 then 1 else -1;

#// Plots
plot UpBand = if Perc then na else upperBoundary; # "Upper Boundary"
plot LoBand = if Perc then na else lowerBoundary; # "Lower Boundary"
plot normalizedValue = if Perc then na else normVal;
plot SigLine = if Perc then na else emaValue; # "Hull MA"

UpBand.SetDefaultColor(GlobalColor("Re")); #GlobalColor("extDn"));
LoBand.SetDefaultColor(GlobalColor("Gr")); #GlobalColor("extUp"));
SigLine.SetDefaultColor(Color.WHITE);
#normalizedValue.SetLineWeight(3);
normalizedValue.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
normalizedValue.AssignValueColor(if ColNorm ==  2 then GlobalColor("extUp") else
                                 if ColNorm ==  1 then GlobalColor("Up") else
                                 if ColNorm == -2 then GlobalColor("extDn") else
                                 if ColNorm == -1 then GlobalColor("Dn") else Color.GRAY);
#-- OB/OS

AddCloud(2, thresholdForStandardizedMp, GlobalColor("dRe"), GlobalColor("dRe"));
AddCloud(-thresholdForStandardizedMp, -2, GlobalColor("dGr"), GlobalColor("dGr"));
#// ยฉ AlgoAlpha
#indicator("Median Proximity Percentile [AlgoAlpha]", "AlgoAlpha - % Median Proximity Percentile"

def perValue = if !Perc then na else
                      100 * (normVal - lowerBoundary) / (upperBoundary - lowerBoundary) - 50;

def emaPer = MovingAverage(NormLizedMovAvgType, perValue, NormLizedMovAvgLength);
#// Color Conditions
def PerCol = if perValue > 0 then  2 else
             if perValue < 0 then -2 else 0;

#// Plots
def perCrossUp = (emaPer crosses below emaPer[1]);
def perCrossDn = (emaPer[1] crosses below emaPer);

plot bear = if perCrossUp and emaPer[1] > 90 then emaPer + 15 else na; # "Bearish Reversal"
plot bull = if perCrossDn and emaPer[1] < -90 then emaPer - 15 else na; # "Bullish Reversal"
bear.SetLineWeight(2);
bull.SetLineWeight(2);
bear.SetPaintingStrategy(PaintingStrategy.SQUARES);
bull.SetPaintingStrategy(PaintingStrategy.SQUARES);
bear.SetDefaultColor(GlobalColor("Re"));
bull.SetDefaultColor(GlobalColor("Gr"));

plot noiseLine = if noiseScatterplotForPercentileMp and PerCol then perValue else na;
plot zeroLine = if last then na else 0; #, color = plotColor, title = "Zero Line")
zeroLine.SetDefaultColor(Color.DARK_GRAY);
def hmaPlot = emaPer;     # "Hull MA")
def hmaPlot1 = emaPer[1];

zeroLine.SetDefaultColor(Color.GRAY);
noiseLine.SetPaintingStrategy(PaintingStrategy.POINTS);
noiseLine.AssignValueColor(if PerCol > 0 then GlobalColor("Up") else GlobalColor("Dn"));

AddCloud(hmaPlot, hmaPlot1, GlobalColor("extUp"), GlobalColor("extDn"), yes);
AddCloud(hmaPlot, hmaPlot1, GlobalColor("extUp"), GlobalColor("extDn"), yes);

AddCloud(if !last and Perc then  150 else na,  120, Color.DARK_RED);
AddCloud(if !last and Perc then  150 else na,   90, Color.DARK_RED);
AddCloud(if !last and Perc then -120 else na, -150, Color.DARK_GREEN);
AddCloud(if !last and Perc then  -90 else na, -150, Color.DARK_GREEN);

#-- bar color
def col = if Perc then PerCol else ColNorm;

AssignPriceColor(if !ColoredBars then Color.CURRENT else
                 if col == 2 then GlobalColor("extUp") else
                 if col == 1 then GlobalColor("Up") else
                 if col == -2 then GlobalColor("extDn") else
                 if col == -1 then GlobalColor("Dn") else Color.GRAY);

#-- END of CODE
 
check the below:

CSS:
#// This Pine Scriptโ„ข code is subject to the terms of the Mozilla Public License 2.0 at https:/
#// ยฉ AlgoAlpha
#indicator("Standardized Median Proximity [AlgoAlpha]", "AlgoAlpha - ๐“ข๐“ฝ๐“ช๐“ท๐“ญ๐“ช๐“ป๐“ญ๐“ฒ๐”ƒ๐“ฎ๐“ญ ๐“œ๐“ฎ๐“ญ๐“ฒ๐“ช๐“ท ๐“Ÿ๐“ป๐“ธ๐”๐“ฒ๐“ถ๐“ฒ๐“ฝ๐”‚"
# Converted by Sam4Cok@Samer800    - 05/2024
declare lower;

input ColoredBars = yes; #(true, "Colored Bars?")
input timeframe = {default "Chart TF", "Custom TF"};
input customTimeframe = AggregationPeriod.FIFTEEN_MIN;
input displayOptions = {default "Standardized Median Proximity", "Median Proximity Percentile"};
input Source = FundamentalType.CLOSE; #(close, "Source")
input lookbackLength = 21; # "Lookback Length"
input NormlizedMovAvgType = AverageType.HULL;
input NormlizedMovAvgLength = 20; #, minval = 1, title = "HMA Lookback Length")
input stdDevMultiplier = 1.0; #, title = "Standard Deviation Multiplier")
input thresholdForStandardizedMp = 1.5; #, title = "Upper Boundary of Deviation Bands")
input ShowNeutralTrendForStandardizedMp = yes; #(true, "Show Neutral Trend?")
input noiseScatterplotForPercentileMp = yes; #, "Noise Scatterplot")

def na = Double.NaN;
def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def last = IsNaN(close);
def Perc = displayOptions == displayOptions."Median Proximity Percentile";
def neut = ShowNeutralTrendForStandardizedMp;
def priceSource;
switch (timeframe) {
case "Custom TF" :
    priceSource = Fundamental(FundamentalType = Source, Period = customTimeframe);
default :
    priceSource = Fundamental(FundamentalType = Source);
}
DefineGlobalColor("extUp", CreateColor(255,172,50));
DefineGlobalColor("extDn", Color.MAGENTA);
DefineGlobalColor("Up", CreateColor(156, 93, 0));
DefineGlobalColor("Dn", Color.PLUM);

DefineGlobalColor("Gr", CreateColor(0, 255, 107)); #Color.GREEN);
DefineGlobalColor("dGr", CreateColor(0, 104, 44)); #Color.DARK_GREEN);
DefineGlobalColor("Re", CreateColor(254, 0, 82)); #Color.RED);
DefineGlobalColor("dRe", CreateColor(130, 0, 42)); #Color.DARK_RED);
#colorUp = input.color(#00ffbb, title = "Up Color")
#colorDown = input.color(#ff1100, title = "Down Color")

#// Calculations
def medianValue = Median(priceSource, lookbackLength);
def priceDeviation = (priceSource - medianValue);
def standardDeviation = StDev(priceDeviation, 45);
def normVal = priceDeviation / (standardDeviation + standardDeviation);

def positiveValues = if normVal > 0 then normVal else 0;
def negativeValues = if normVal < 0 then normVal else 0;
def posBandStdv = StDev(positiveValues, lookbackLength) * stdDevMultiplier;
def negBandStdv = StDev(negativeValues, lookbackLength) * stdDevMultiplier;
def upperBoundary = ExpAverage(positiveValues, lookbackLength) + posBandStdv;
def lowerBoundary = ExpAverage(negativeValues, lookbackLength) - negBandStdv;
def emaValue = MovingAverage(NormLizedMovAvgType, normVal, NormLizedMovAvgLength);


#// Color Conditions
def ColNorm = if normVal > upperBoundary then  2 else
              if normVal < lowerBoundary then -2 else
      if (normVal<0 and normVal < upperBoundary and emaValue > lowerBoundary and normVal > emaValue and neut) or
         (normVal>0 and normVal > lowerBoundary and emaValue < upperBoundary and normVal < emaValue and neut) then 0 else
      if  normVal>0 then 1 else -1;

#// Plots
plot UpBand = if Perc then na else upperBoundary; # "Upper Boundary"
plot LoBand = if Perc then na else lowerBoundary; # "Lower Boundary"
plot normalizedValue = if Perc then na else normVal;
plot SigLine = if Perc then na else emaValue; # "Hull MA"

UpBand.SetDefaultColor(GlobalColor("Re")); #GlobalColor("extDn"));
LoBand.SetDefaultColor(GlobalColor("Gr")); #GlobalColor("extUp"));
SigLine.SetDefaultColor(Color.WHITE);
#normalizedValue.SetLineWeight(3);
normalizedValue.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
normalizedValue.AssignValueColor(if ColNorm ==  2 then GlobalColor("extUp") else
                                 if ColNorm ==  1 then GlobalColor("Up") else
                                 if ColNorm == -2 then GlobalColor("extDn") else
                                 if ColNorm == -1 then GlobalColor("Dn") else Color.GRAY);
#-- OB/OS

AddCloud(2, thresholdForStandardizedMp, GlobalColor("dRe"), GlobalColor("dRe"));
AddCloud(-thresholdForStandardizedMp, -2, GlobalColor("dGr"), GlobalColor("dGr"));
#// ยฉ AlgoAlpha
#indicator("Median Proximity Percentile [AlgoAlpha]", "AlgoAlpha - % Median Proximity Percentile"

def perValue = if !Perc then na else
                      100 * (normVal - lowerBoundary) / (upperBoundary - lowerBoundary) - 50;

def emaPer = MovingAverage(NormLizedMovAvgType, perValue, NormLizedMovAvgLength);
#// Color Conditions
def PerCol = if perValue > 0 then  2 else
             if perValue < 0 then -2 else 0;

#// Plots
def perCrossUp = (emaPer crosses below emaPer[1]);
def perCrossDn = (emaPer[1] crosses below emaPer);

plot bear = if perCrossUp and emaPer[1] > 90 then emaPer + 15 else na; # "Bearish Reversal"
plot bull = if perCrossDn and emaPer[1] < -90 then emaPer - 15 else na; # "Bullish Reversal"
bear.SetLineWeight(2);
bull.SetLineWeight(2);
bear.SetPaintingStrategy(PaintingStrategy.SQUARES);
bull.SetPaintingStrategy(PaintingStrategy.SQUARES);
bear.SetDefaultColor(GlobalColor("Re"));
bull.SetDefaultColor(GlobalColor("Gr"));

plot noiseLine = if noiseScatterplotForPercentileMp and PerCol then perValue else na;
plot zeroLine = if last then na else 0; #, color = plotColor, title = "Zero Line")
zeroLine.SetDefaultColor(Color.DARK_GRAY);
def hmaPlot = emaPer;     # "Hull MA")
def hmaPlot1 = emaPer[1];

zeroLine.SetDefaultColor(Color.GRAY);
noiseLine.SetPaintingStrategy(PaintingStrategy.POINTS);
noiseLine.AssignValueColor(if PerCol > 0 then GlobalColor("Up") else GlobalColor("Dn"));

AddCloud(hmaPlot, hmaPlot1, GlobalColor("extUp"), GlobalColor("extDn"), yes);
AddCloud(hmaPlot, hmaPlot1, GlobalColor("extUp"), GlobalColor("extDn"), yes);

AddCloud(if !last and Perc then  150 else na,  120, Color.DARK_RED);
AddCloud(if !last and Perc then  150 else na,   90, Color.DARK_RED);
AddCloud(if !last and Perc then -120 else na, -150, Color.DARK_GREEN);
AddCloud(if !last and Perc then  -90 else na, -150, Color.DARK_GREEN);

#-- bar color
def col = if Perc then PerCol else ColNorm;

AssignPriceColor(if !ColoredBars then Color.CURRENT else
                 if col == 2 then GlobalColor("extUp") else
                 if col == 1 then GlobalColor("Up") else
                 if col == -2 then GlobalColor("extDn") else
                 if col == -1 then GlobalColor("Dn") else Color.GRAY);

#-- END of CODE
Thank you.
 
I have been using this for a week on 15 minute. When the white line is at or below the green, go long, and when the white line is at or above the red line, go short. For a paper account, I hit on BCG even thought the market has been down this week big. I will now look for the minimum and the maximum for longs and shorts.
 
Last edited:
I have been using this for two weeks on an one minute which it typically follows the results below. When the white line is at or below the green, go long, and when the white line is at or above the red line, go short. For a paper account, I hit on BCG even thought the market has been down this week big. I will now look for the minimum and the maximum for longs and shorts. For DKS, it did not capture it very well this past week since it had a double rise -- it rose and it immediately rose again. I have adjusted the lines to a five instead of an one so that it is more visible.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
361 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • โ€˜Buy The Dipโ€™ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top