But it does not
2. paint in the subwindow nor display data in the data window
1. complile correctly. it keeps using input in the 2 pole calculation
Code: Select all
//+------------------------------------------------------------------+
//| tpsvw_rsx-ecog.mq4 |
//| Copyright 2023, simon_n3z |
//| https://www.forex-station.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, simon_n3z"
#property link "https://www.forex-station.com"
#property version "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue
#define MathPI 3.14159265358979323846
double TPSVM_RSX_ECG[];
double Trigger[];
extern int Length = 10;
extern int RSX_Period = 14; // RSX period for smoothing
extern double RSX_Alpha = 0.07; // RSX smoothing factor
int buffers = 0;
int drawBegin = 0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init() {
drawBegin = Length;
initBuffer(TPSVM_RSX_ECG, "TPSVM_RSX_ECG", DRAW_LINE);
initBuffer(Trigger, "Trigger", DRAW_LINE);
IndicatorBuffers(buffers);
IndicatorShortName("TPSVM_RSX_ECG [" + Length + "]");
return (0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start() {
int counted_bars = IndicatorCounted();
if (counted_bars < 0)
return (-1);
if (counted_bars > 0)
counted_bars--;
int limit = Bars - counted_bars;
if (counted_bars == 0)
limit -= 1 + Length;
for (int s = limit; s >= 0; s--) {
double Num = 0.0;
double Denom = 0.0;
for (int count = 0; count < Length; count++) {
Num += (1.0 + count) * VolumeWeightedPrice(s + count);
Denom += iVolume(NULL, 0, s + count);
}
double VWMA = (Denom != 0) ? Num / Denom : 0.0;
double RSX = CalculateRSX(VWMA, RSX_Period, RSX_Alpha);
double smoothedRSX = SmoothedTwoPoleRSX(RSX, Length);
if (Denom != 0) {
double COG = -smoothedRSX + (Length + 1.0) / 2.0;
double smoothedCOG = SmoothedTwoPole(COG, Length);
TPSVM_RSX_ECG[s] = smoothedCOG;
} else {
TPSVM_RSX_ECG[s] = 0;
}
Trigger[s] = TPSVM_RSX_ECG[s + 1];
}
return (0);
}
//+------------------------------------------------------------------+
//| Volume Weighted Price Calculation |
//+------------------------------------------------------------------+
double VolumeWeightedPrice(int index) {
return ((High[index] + Low[index] + Close[index]) / 3.0) * iVolume(NULL, 0, index);
}
//+------------------------------------------------------------------+
//| RSX Calculation |
//+------------------------------------------------------------------+
double CalculateRSX(double price, int period, double alpha) {
double rsxValue = 0.0;
for (int i = 1; i < period; i++) {
double delta = price - rsxValue;
rsxValue += alpha * delta * delta;
}
return MathSqrt(rsxValue / period);
}
//+------------------------------------------------------------------+
//| RSX Smoothing |
//+------------------------------------------------------------------+
double SmoothedTwoPoleRSX(double rsxValue, int period) {
double smoothingAlpha = 1 - MathCos(2 * MathPI / period);
double smoothingAlpha1 = 1 - MathCos(2 * MathPI / (period / 2));
double emaValue1 = rsxValue;
double emaValue2 = rsxValue;
for (int i = 1; i < period; i++) {
emaValue1 = (1 - smoothingAlpha) * rsxValue + smoothingAlpha * emaValue1;
}
for (int i = 1; i < period / 2; i++) {
emaValue2 = (1 - smoothingAlpha1) * emaValue1 + smoothingAlpha1 * emaValue2;
}
return emaValue2;
}
//+------------------------------------------------------------------+
//| Smoothing function (Two-Pole Smoother) |
//+------------------------------------------------------------------+
double SmoothedTwoPole(double input, int period) {
double smoothingAlpha = 1 - MathCos(2 * MathPI / period);
double smoothingAlpha1 = 1 - MathCos(2 * MathPI / (period / 2));
double emaValue1 = input;
double emaValue2 = input;
for (int i = 1; i < period; i++) {
emaValue1 = (1 - smoothingAlpha) * input + smoothingAlpha * emaValue1;
}
for (int i = 1; i < period / 2; i++) {
emaValue2 = (1 - smoothingAlpha1) * emaValue1 + smoothingAlpha1 * emaValue2;
}
return emaValue2;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void initBuffer(double& array[], string label = "", int type = DRAW_NONE, int arrow = 0, int style = EMPTY, int width = EMPTY, color clr = CLR_NONE) {
SetIndexBuffer(buffers, array);
SetIndexLabel(buffers, label);
SetIndexEmptyValue(buffers, EMPTY_VALUE);
SetIndexDrawBegin(buffers, drawBegin);
SetIndexShift(buffers, 0);
SetIndexStyle(buffers, type, style, width);
SetIndexArrow(buffers, arrow);
buffers++;
}
WHAT IS MY MAJOR MALFUNCTION ?
Plz help a brother out *nudge nudge *
Thank you in advance
-simon