_NOC
Download scriptThis tool functions as a specialized technical indicator designed to measure and visualize price momentum and "positional bias" within a specific timeframe on your trading chart. Rather than simply looking at where the price is currently moving, it analyzes how the price is distributed relative to its highs and lows over a set interval.
Core Logic and Methodology
The script operates through three primary stages of calculation:
1. Range Assessment The indicator looks back at a defined number of bars (the observation window) to identify the highest and lowest prices reached. It then checks if the volatility—the distance between that high and low—meets a specific minimum threshold. This ensures that the data being analyzed is significant enough to provide a meaningful reading, filtering out periods of extremely stagnant price action.
2. Positional Calculation Once the range is established, the tool calculates where the closing price sits within that space. It essentially asks: "Is the price leaning closer to the top of the range or the bottom?"
- By comparing the distance from the Low to the Close against the distance from the High to the Close, it determines a balance score.
- This score is then normalized into a visual scale (typically centered around a midpoint). If the price is aggressively pushing toward the highs of its recent range, the indicator reflects a stronger upward bias; if it is lingering near the lows, it shows a downward bias.
3. Smoothing and Trend Identification To prevent the visual data from appearing "choppy" or over-reactive to minor price fluctuations, the script applies an Exponential Moving Average (EMA) calculation to the final result. This smoothing process helps highlight the underlying trend of the positional bias, making it easier for a trader to see whether the momentum is steadily shifting or remaining stable.
Visual Representation
The indicator appears in a separate window below your main price chart. It produces a continuous line that moves between a defined range. By observing the path of this line, you can identify shifts in market sentiment: a rising line suggests increasing strength toward the upper bounds of recent volatility, while a falling line suggests a retreat toward the lower bounds.
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_minimum 0
#property indicator_maximum 1
// indicator parameters
// To do: read parameters, including weights, from a description file
int nNocInterval = 12;
double dNocRange = 0.012;
int nNocMa = 5;
int nOutLag = 2;
int nRemoveFirst = 200;
// indicator buffers
double arrNocBuffer[];
int nExtCountedBars = 0;
////////////////////////
int init()
{
// drawing settings
SetIndexStyle(0, DRAW_LINE);
SetIndexShift(0, 0);
SetIndexEmptyValue(0, 0.0);
IndicatorDigits(4);
string strIndicatorShortName = "NOC";
IndicatorShortName(strIndicatorShortName);
// indicator buffers mapping
SetIndexBuffer(0, arrNocBuffer);
return(0);
}
////////////////////
int start()
{
nExtCountedBars = IndicatorCounted();
if(nExtCountedBars < 0)
return(-1);
// last counted bar will be recounted
if(nExtCountedBars > 0)
nExtCountedBars--;
Noc();
return(0);
}
///////////////////
// For the selected period:
// CLV = ((Close - Low) - (High - Close)) / (High - Low)
void Noc()
{
int nPos = Bars - nExtCountedBars;
while(nPos > 0)
{
if(nPos > Bars - nRemoveFirst)
{
arrNocBuffer[nPos] = 0.5;
nPos--;
continue;
}
double dClose = Close[nPos];
double dLow = Low[ArrayMinimum(Low, nNocInterval, nPos)];
double dHigh = High[ArrayMaximum(High, nNocInterval, nPos)];
arrNocBuffer[nPos] = 0.1;
if(dHigh - dLow > dNocRange)
arrNocBuffer[nPos] = (((dClose - dLow) - (dHigh - dClose))
/ (dHigh - dLow)) / 2 + 0.5;
else
arrNocBuffer[nPos] = (((dClose - dLow) - (dHigh - dClose))
/ dNocRange) / 2 + 0.5;
nPos--;
}
if(nNocMa > 1)
Ema(arrNocBuffer);
}
///////////////////
void Ema(double& arr[])
{
double dPr = 2.0 / (nNocMa + 1);
int nPos = Bars - nExtCountedBars;
while(nPos > 0)
{
if(nPos == Bars - 2)
arrNocBuffer[nPos + 1] = arr[nPos + 1];
arrNocBuffer[nPos] = arr[nPos] * dPr + arrNocBuffer[nPos + 1]
* (1 - dPr);
nPos--;
}
}
Comments