My best shot is the following. However, I Believe there must be a must easier way to do whatever you want to do with the MA variation.
Besides, your example case does nothing if the variation is negative.
#define MAXDEV 0.00250 #define MAXRANGE 3 if(MAVariation >= 0) { double dev = (MAVariation * (MAXRANGE+1) / MAXDEV) - 1; } else { // Do here whatever you do if variation is negative }
double MAtoSTDmult(double ma){ // 0.00000 (flat) to 0.00250 (steep) and output a value ranging from 2 to -1 #define MaFlat 0.0 #define MaSteep 0.0025 #define SdFlat 2.0 #define SdSteep -1.0 if (ma < MaFlat) ma = MaFlat; // Handle out of else if (ma > MaSteep) ma = MaSteep; // range inputs. double fraction = (ma - MaFlat) / (MaSteep - MaFlat), // Reduce MA to 0 .. 1. output = fraction * (SdSteep - SdFlat) + SdFlat; // Map fraction to 2 .. -1, // mapping assumed linear. return(output); }not compiled or tested
I'm writing an indicator where the "angle" (price change overtime) of a moving average is a multiplier for a standard deviation line.
I'm looking for help with the mathematical formula that will take a moving average input ranging from 0.00000 (flat) to 0.00250 (steep) and output a value ranging from 2 to -1 that I will use for the standard deviation.
If anybody can that he can help me with the mathematical formula I would appreciate it.
So you want 0.0000 to be 2 and 0.00250 to be -1 ? or the other way around ?
Right -
0.0000 to be 2 and 0.00250 to be -1. Meaning, an input ranging from 0.00000 to 0.00250 will deliver an output ranging from 2 to -1.
How I am going to use this:
When a moving average is relatively flat (0.00000), a standard deviation line with a multiple of 2 tends to show the peaks in price. However, when you have a moderate trend, a standard deviation line with a multiple of 1 is needed to show the peaks in price. And if the trend is extremely steep (0.00250) then a standard deviation line of -1 is needed to show peaks in price.
I just can't wrap my head around what the mathematical formula should look like.
( Thanks to everyone else for your ideas I'll check your recommendations. )
#define x1 0.00000 #define x2 0.00250 #define y1 2.0 #define y2 -1.0 // x1 x2 and y1 y2 are two separate data ranges & could be beyond above defined limits, as you like them, you can call them x scale and y scale // any value of x will be converted into its y counterpart obeying scale conversion logic given below...which is simply based on equation of straight line... // input your 'x'...and following code line will deliver you 'y'. double y, x; y = x * (( y1 - y2 ) / ( x1 - x2 )) + y1 - x1 * (( y1 - y2 ) / ( x1 - x2 )); //I am new here..first time registered today..but I have been reading this forum since last 2 years & you are really genius brains here..like WHRoeder, dabbler, danjp, //RuptorUK, ubzen, Phy, gordon, Rashid Umar, zzeugg, flaab... I have learnt a lot from their postings on this forum... Regards
I am new here..first time registered today..
Well, I am glad you replied. I am happy to hear from you and this looks like the solution. I will plug it in later today.
A big thanks to you!
Scott
Based on your submission to RuporUK's interpretation of your need, I gave you the right formula.....I have checked myself its result on Excel spreadsheet & it is correct...For your further confirmation..I advise you google on how to convert Celcius degree Temperature to Foeinheit degree Temperature.... I have used the same Logic with Modified parameters.....Regards, T
Cool - the formula really works! I used Tasleem's equation. Have you ever heard of this one before? A trading program based on the conversion rate of Celsius to Fahrenheit. ;-)
It is interesting to note that an Indicator program can handle variable values to drive a standard deviation line or moving average line. You don't need to use just one set value for these lines.
Well, it looks good looking backward in time. Now see how it works for trading looking forward in time.
Thanks again.
Cool - the formula really works! I used Tasleem's equation. Have you ever heard of this one before? A trading program based on the conversion rate of Celsius to Fahrenheit. ;-)
It is interesting to note that an Indicator program can handle variable values to drive a standard deviation line or moving average line. You don't need to use just one set value for these lines.
Well, it looks good looking backward in time. Now see how it works for trading looking forward in time.
Thanks again.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm writing an indicator where the "angle" (price change overtime) of a moving average is a multiplier for a standard deviation line.
I'm looking for help with the mathematical formula that will take a moving average input ranging from 0.00000 (flat) to 0.00250 (steep) and output a value ranging from 2 to -1 that I will use for the standard deviation.
If anybody can that he can help me with the mathematical formula I would appreciate it.