Author Message:
Here's how I works : The script tries to determine the overall direction of the market, using smoothed Heiken Ashi candles. The coloring system (using bright and dark colors) is an attempt to detect strong market and weak market conditions. There's also an oscillator within the script, but for now it isn't plotted.
Credits to @jackvmk, I used part of his open-script code in this indicator.\
I have considered using the slope of the indicator plot as a filter for ranging market conditions. The plot goes relatively flat in 'flat' markets. However, I have not done anything about that yet. Maybe some other time.
Here's how I works : The script tries to determine the overall direction of the market, using smoothed Heiken Ashi candles. The coloring system (using bright and dark colors) is an attempt to detect strong market and weak market conditions. There's also an oscillator within the script, but for now it isn't plotted.

Credits to @jackvmk, I used part of his open-script code in this indicator.\
I have considered using the slope of the indicator plot as a filter for ranging market conditions. The plot goes relatively flat in 'flat' markets. However, I have not done anything about that yet. Maybe some other time.
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Professeur_X
#indicator(title='HA Market Bias', shorttitle='HA Market Bias', overlay=true)
# Converted by [email protected] - 01/2023
input show_cloud = yes; # "Show HA Plot/ Market Bias"
input show_HA = yes; # "Show HA Plot/ Market Bias"
input show_Lines = yes; # "Show HA Plot/ Market Bias"
input Period = 60; # 'Period', group="HA Market Bias")
input Smoothing = 10; # 'Smoothing', group="HA Market Bias")
input MovAvg = AverageType.EXPONENTIAL;
input OscillatorPeriod = 7; # "Oscillator Period"
def na = Double.NaN;
#---- Colors
DefineGlobalColor("green1" , CreateColor(33,166,153));
DefineGlobalColor("green2" , CreateColor(24,104,96));
DefineGlobalColor("Red1" , CreateColor(166,38,51));
DefineGlobalColor("Red2" , CreateColor(104,24,32));
#// Calculations {
def o = MovingAverage(MovAvg, open, Period);
def c = MovingAverage(MovAvg, close, Period);
def h = MovingAverage(MovAvg, high, Period);
def l = MovingAverage(MovAvg, low, Period);
def haclose = (o + h + l + c) / 4;
def xhaopen = (o + c) / 2;
def haopen = if IsNaN(xhaopen[1]) then (o + c) / 2 else (xhaopen[1] + haclose[1]) / 2;
def hahigh = Max(h, Max(haopen, haclose));
def halow = Min(l, Min(haopen, haclose));
def o2 = MovingAverage(MovAvg, haopen, Smoothing);
def c2 = MovingAverage(MovAvg, haclose, Smoothing);
def h2 = MovingAverage(MovAvg, hahigh, Smoothing);
def l2 = MovingAverage(MovAvg, halow, Smoothing);
def ha_avg = (h2 + l2) / 2;
#// Oscillator {
def osc_bias = 100 *(c2 - o2);
def osc_smooth = MovingAverage(MovAvg, osc_bias, OscillatorPeriod);
def sigcolor =
if (osc_bias > 0) and (osc_bias >= osc_smooth) then 2 else
if (osc_bias > 0) and (osc_bias < osc_smooth) then 1 else
if (osc_bias < 0) and (osc_bias <= osc_smooth) then -2 else
if (osc_bias < 0) and (osc_bias > osc_smooth) then -1 else 0;
#// Plots {
plot p_h = if !show_Lines then na else h2;#, "Bias High", color=color(na), display=display.none, editable=false)
p_h.AssignValueColor(if sigcolor==2 then GlobalColor("green1") else
if sigcolor==1 then GlobalColor("green2") else
if sigcolor==-2 then GlobalColor("Red1") else
if sigcolor==-1 then GlobalColor("Red2") else Color.GRAY);
plot p_l = if !show_Lines then na else l2;#, "Bias Low", color=color(na), display=display.none, editable=false)
p_l.AssignValueColor(if sigcolor==2 then GlobalColor("green1") else
if sigcolor==1 then GlobalColor("green2") else
if sigcolor==-2 then GlobalColor("Red1") else
if sigcolor==-1 then GlobalColor("Red2") else Color.GRAY);
plot p_avg = if !show_Lines then na else ha_avg;#, "Bias Avergae", color=color(na), display=display.none, editable=false)
p_avg.AssignValueColor(if sigcolor==2 then GlobalColor("green1") else
if sigcolor==1 then GlobalColor("green2") else
if sigcolor==-2 then GlobalColor("Red1") else
if sigcolor==-1 then GlobalColor("Red2") else Color.GRAY);
AddCloud (if show_cloud and sigcolor==2 then h2 else na, l2, GlobalColor("green1"));
AddCloud (if show_cloud and sigcolor>0 then h2 else na, l2, GlobalColor("green2"));
AddCloud (if show_cloud and sigcolor==-2 then h2 else na, l2, GlobalColor("Red1"));
AddCloud (if show_cloud and sigcolor<0 then h2 else na, l2, GlobalColor("Red2"));
# Plot the new Chart
def col = if show_HA then o2 > c2 else na;
AddChart(high = if col then na else h2, low = if col then na else l2 , open = if col then na else c2, close = if col then na else o2,
type = ChartType.CANDLE, growcolor = CreateColor(38,166,154));
AddChart(high = if !col then na else h2, low = if !col then na else l2 , open = if !col then na else o2, close = if !col then na else c2,
type = ChartType.CANDLE, growcolor = CreateColor(239,83,80));
# --- END CODE
Last edited by a moderator: