L

#### lmk99

##### Member

**VIP**

I can't figure out how this could be done: I want to create an index plot that does not include negative values, and works on a scale of 0% to 100% like MoneyFlowIndex. I want the plot to be for the study value (but I'd also like to try doing this for the rate of change of the study value).

The rate of change is normally calculated this way:

Code:

`(price / price[length] - 1) * 100`

The standard code that I found to normalize a plot is this:

Code:

```
script normalizePlot {
input data = close;
input newRngMin = -1;
input newRngMax = 1;
def hhData = HighestAll( data );
def llData = LowestAll( data );
plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}
```

I am plotting normalized FreedomofMovement rate of change like so:

Code:

```
declare lower;
def length = 6;
#Rate of change formula: (price / price[length] - 1) * 100
#index example formula: input movingAvgLength = 1; plot MoneyFlowIndex = Average(moneyflow(high, close, low, volume, length), movingAvgLength);
script normalizePlot {
input data = close;
input newRngMin = -1;
input newRngMax = 1;
def hhData = HighestAll( data );
def llData = LowestAll( data );
plot nr = ((( newRngMax - newRngMin ) * ( data - llData )) / ( hhData - llData )) + newRngMin;
}
#FreedomofMovement
def fomlength = 20;
def numDev = 2.0;
def allowNegativeValues = yes;
def mov = AbsValue(close / close[1] - 1);
def minMov = Lowest(mov, fomlength);
def maxMov = Highest(mov, fomlength);
def nMov = 1 + (mov - minMov) / (maxMov - minMov) * 9;
def vol = (volume - Average(volume, fomlength)) / StDev(volume, fomlength);
def minVol = Lowest(vol, fomlength);
def maxVol = Highest(vol, fomlength);
def nVol = 1 + (vol - minVol) / (maxVol - minVol) * 9;
def vByM = nVol / nMov;
def rawFoM = (vByM - Average(vByM, fomlength)) / StDev(vByM, fomlength);
def FoM = if allowNegativeValues then rawFoM else Max(0, rawFoM);
def StDevLevel = numDev;
def FOMNormalized = normalizePlot(FoM);
plot FOMROC = normalizePlot((FOMNormalized/FOMNormalized[length]-1)*100);
FOMROC.SetDefaultColor(Color.Yellow);
```

What happens when plotting though is that I'm getting an absolute value in some range of oscillations, like -.326 to .145 for example. So even with the normalization script being used, (1) negative values still occur and (2) the scaling will make the plot unusably shrunken in view if also plotting something else normalized that will be in a higher or lower range (such as in a range of -.9 to -.8 or .7 to .9, etc.).

I see that in the case where two studies don't have a scaling problem fitting in a single lower section that uses a y-axis from 0 to 100%, both use average or movingaverage as the function for generating the study value (such as the case for MoneyFlowIndex and SchaffTrendCycle):

Code:

`plot MoneyFlowIndex = Average(moneyflow(high, close, low, volume, length), movingAvgLength);`

Code:

`plot STC = MovingAverage(averageType, fastK2, DPeriod);`

Is there some generic way to convert the FreedomofMovement plot, or any other such plot that can contain negative values normally, into this kind of 0-100% index format? Maybe this is a dumb question, please excuse that, as I don't understand the nuts and bolts of how these calculations work, I just know the format that I want the FreedomofMovement study (and/or a plot for FreedomofMovement rate of change) to use -- i.e. the same format as MoneyFlowIndex. Hoping someone can educate me about whether this is actually possible or has an idea of how it could be done.