#===================================================
# Credits
#===================================================
#Median, SMA, MODE support calculation
#Copyright (c) 2021 Jonathan Phillips, TrendTradez - http://www.trendtradez.com
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
#OTHER DEALINGS IN THE SOFTWARE.
#
#Requirements:
# * ThinkorSwim version xx or above
#
#Installation: you should know
declare upper;
#===================================================
# INPUTS AND GLOBAL VARIABLES
#===================================================
def _BN = BarNumber();
def _nan = Double.NaN;
def _L = low;
def _H = high;
def _O = open;
def _C = close;
input price = close;
input displace = 30;
input period = 180;
input SMA_Lower_Limit = 50;
#median
def _median = (highestall(_C) - Lowestall(_c)) / 2;
plot median = _median;
median.setpaintingStrategy(PaintingStrategy.LINE);
median.setdefaultcolor(color.light_green);
plot SMA = SimpleMovingAvg(length=SMA_Lower_Limit);
sma.setdefaultcolor(color.cyan);
sma.SetPaintingStrategy(PaintingStrategy.line);
sma.hide();
#Mode
def _M = MedianPrice();
def _NewMode;
def _S;
_S =
(
fold i = displace to period
with c
do c +
if
_L > SMA and
_H < _Median and
GetValue(_H, i) > _M and
GetValue(_L, i) < _M
then 1 else 0
);
_NewMode = if
_S > _S[1]
then _M else _NewMode[1];
plot Mode = _newmode;
#===================================================
# HINTS
#===================================================
#hint price: the price to use to calculate SMA lower limit. close is default.
#hint displace: the number of bars to eliminate from MODE/support calculation. i.e. don't inlclude the most recetn xx bars in calculation (gives better true support). 30 is default.
#hint period: How many bars to use in factoring the MODE/support. 180 is Default
#hint SMA_Lower_Limit: Data will only be factored if ABOVE this SMA. 50 is default is 50