Miscellaneous
0
Views
0
Downloads
0
Favorites
_NOC
#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
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---