Hello everyone as the subject says am trying to code or customise a moving average and display it in the subwindow ive tried several ways to tuckle the challenge without success as i show in the image below the yellow ma i placed manually and is the desirable output the red ma is however what my code is producing after ive tried to put its values on 0-100 scale , its not properly scaling the subwindow need help suggestions solutions or possible alternative to achieve this goal . I must also state as in the window the desrired output has a larger value than the scale we put in i want to achieve such but be able to dynamically scale it to the the define 0-100 scale source code below, your help will be greatly appreciated
sourrce code
with a first glance :
double min_val = -100000.0; // Large initial value double max_val = 100000.0; // Large initial value
switch those around , the min val should be huge at first so new minimums can be captured
i use min=INT_MAX and max=INT_MINYou can't properly normalize a moving average because of the fact that the magnitude of prices can vary a lot over time (the same way a price chart does). So why in Gods name do you need to normalize the moving average from 0 to 100? A moving average isn't an oscillator, as it doesn't have a fixed range. There was however some scientific codes which create an oscillator based on a moving average, one comes to mind called "Angle of averages"
You can't properly normalize a moving average because of the fact that the magnitude of prices can vary a lot over time (the same way a price chart does). So why in Gods name do you need to normalize the moving average from 0 to 100? A moving average isn't an oscillator, it doesn't have a fixed range. There was however some scientific codes which create an oscillator based on a moving average, one comes to mind called "Angle of averages"
perhaps he could measure the delta of a fast and slow ma divided by the atr but still he'd have to limit it.
I decided to do a raw min/max normalization like he was trying to do, I seem to get it working, but looks a bit odd. Added the dynamic levels as well
the levels correspond to 80 and 20 of the normalized plot, as the levels mark 20% above the minimum and 20% below the maximum
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { ArrayResize(MinBuffer, rates_total); ArrayResize(MaxBuffer, rates_total); if (rates_total < InpMAPeriod - 1) return (0); int limit; if (prev_calculated == 0) { ArrayInitialize(NormalizedBuffer, 0); limit = prev_calculated; } else{ limit = prev_calculated - 1; } switch (InpMAMethod) { case MODE_EMA: CalculateEMA(rates_total, prev_calculated, 1, close); break; case MODE_LWMA: CalculateLWMA(rates_total, prev_calculated, 1, close); break; case MODE_SMMA: CalculateSmoothedMA(rates_total, prev_calculated, 1, close); break; case MODE_SMA: CalculateSimpleMA(rates_total, prev_calculated, 1, close); break; } int baseline = 20; int scaling_factor = 50; int lookback = 50; // window size for (int i = limit; i < rates_total; i++) { double min_val = DBL_MAX; double max_val = -DBL_MAX; int start = MathMax(0, i - lookback + 1); // Find min/max within the rolling window for (int j = start; j <= i; j++) { if (ExtLineBuffer[j] < min_val) min_val = ExtLineBuffer[j]; // update var if (ExtLineBuffer[j] > max_val) max_val = ExtLineBuffer[j]; // update var } MinBuffer[i] = min_val; MaxBuffer[i] = max_val; // NormalizedBuffer[i] = ((ExtLineBuffer[i] - min_val) / (max_val - min_val)) * 100; NormalizedBuffer[i] = baseline + (((ExtLineBuffer[i] - min_val) / (max_val - min_val)) * scaling_factor); } static double max_normalized = -DBL_MAX; static double min_normalized = DBL_MAX; for (int i = limit; i < rates_total; i++) { if (NormalizedBuffer[i] < min_normalized) min_normalized = NormalizedBuffer[i]; if (NormalizedBuffer[i] > max_normalized) max_normalized = NormalizedBuffer[i]; } // calculate range double range = max_normalized - min_normalized; // dynamic levels double level20 = min_normalized + (range * 0.2); // 20% above min double level80 = max_normalized - (range * 0.2); // 20% below max // Set levels IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, level80); IndicatorSetDouble(INDICATOR_LEVELVALUE, 1, level20); // Print min and max values for debugging // Print("Min MA value: ", smoothed_min, ", Max MA value: ", smoothed_max); return (rates_total); }
this is for science only. If you would say that a moving average by itself has a 50% win rate, then normalizing it might bring the win rate down to 30% because of confusing slopes
I decided to do a raw min/max normalization like he was trying to do, I seem to get it working, but looks a bit odd. Added the dynamic levels as well
the levels correspond to 80 and 20 of the normalized plot, as the levels mark 20% above the minimum and 20% below the maximum
this is for science only. If you would say that a moving average by itself has a 50% win rate, then normalizing it might bring the win rate down to 30% because of confusing slopes
i guess you are right so ive opted to use a template since its once placed manually you got no such problems just have to retreive existing indicators from the chart
LoadTemplates1(BaseTemplateName,LowerTemplateName,BaseTimeframe,Symbol());
Now the idea here is to just retain the original values place manually
but as in the image above the the desired ma14 has a larger buffer values 20445.03712 which makes it kind of hard to pin point when it is above the 80 level or below the 20level which is the new problem or what i was trying to avoid but is my best channce to achieve the objective
You can't do that.
but as in the image above the the desired ma14 has a larger buffer values 20445.03712 which makes it kind of hard to pin point when it is above the 80 level or below the 20level which is the new problem or what i was trying to avoid but is my best channce to achieve the objective

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello everyone as the subject says am trying to code or customise a moving average and display it in the subwindow ive tried several ways to tuckle the challenge without success as i show in the image below the yellow ma i placed manually and is the desirable output the red ma is however what my code is producing after ive tried to put its values on 0-100 scale , its not properly scaling the subwindow need help suggestions solutions or possible alternative to achieve this goal . I must also state as in the window the desrired output has a larger value than the scale we put in i want to achieve such but be able to dynamically scale it to the the define 0-100 scale source code below, your help will be greatly appreciated
sourrce code