Get the high and low EMA on a set of EMA's

Pensar

Well-known member
VIP
@JJP I understand now, but you will need to provide a bit more information. What length are the EMAs? How do you want the information? As a label? A lower indicator? Posting the code you are using as well as a picture would be very helpful as well.
 

JJP

New member
EMA 3,5,8,10,12,15,30,35
(High EMA-Low EMA) /Close price of stock
Show an Arrow or something on the chart if 0 or less.
I also want to be able to scan for stocks in this situation.

Thanks
 

XeoNoX

Well-known member
VIP
I Have 6 EMA, I'm trying to get the highest EMA and Lowest EMA) and subtract the two. Hope this helps you understand better.

Thanks

why dont you just grab the highest MA and lowest MA and use the middle? example 1MA and 100MA so just use the 50MA.
 

Pensar

Well-known member
VIP
@XeoNoX What @JJP wants is a bit different I think, according to what he described.
@JJP Here are indicators and a scan, based on what you described.

Upper arrows -
Code:
input n1 = 3;
input n2 = 35;
def EMAdiff = (ExpAverage(close, n1) - ExpAverage(close, n2)) / close;

plot CrossAbove = EMAdiff crosses above 0;
CrossAbove.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
plot CrossBelow = EMAdiff crosses below 0;
CrossBelow.setpaintingstrategy(paintingstrategy.boolean_arrow_down);

Lower histogram -
Code:
input n1 = 3;
input n2 = 35;
plot EMAdiff = (ExpAverage(close, n1) - ExpAverage(close, n2)) / close;
EMAdiff.AssignValueColor(if EMAdiff > 0 then Color.GREEN else Color.RED);
EMAdiff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

Scan for arrow signal -
Code:
# uncomment the plot you want to scan for

input n1 = 3;
input n2 = 35;
def EMAdiff = (ExpAverage(close, n1) - ExpAverage(close, n2)) / close;

#plot CrossAbove = EMAdiff crosses above 0;
plot CrossBelow = EMAdiff crosses below 0;

Good trading to you!
 

JJP

New member
That's getting pretty close I believe lol, I'm kind of understanding the script. My wording on the EMA may be confusing a little.(maybe a lot)

input n1 = 3
input n1 = 5
input n1 = 8
input n1 = 10
input n1 = 12
input n1 = 15
input n1 = 30
input n1 = 35
I'm trying to get the moving avg with the highest value and the lowest value, not the highest and lowest moving avg if that make sense. What I'm asking for may not be possible or very complicated. I figured I would give it a try.

Hope I'm not working you all to death I wish I was a fast learner.
Please forgive my ignorance,
 

JJP

New member
@generic @Pensar you guys really helped me out. I have one more equation I'm trying to figure out that I failed to mention. I'm trying to take the pressRatio and plot a symbol if the value is the lowest out of the last 4 years, Is this possible?

def pressRatio =(HMA-LMA)/close;
 

JJP

New member
@JJP Don't really understand what plot a symbol means but you can try using lowest() and compare with current value.
This what I have come up with. I'm no pro at this, just a baby trying to learn how to crawl.

Code:
#EMA
declare upper;

PLOT EMA1 = ExpAverage(CLOSE,3);
PLOT EMA2 = ExpAverage(CLOSE,5);
PLOT EMA3 = ExpAverage(CLOSE,8);
PLOT EMA4 = ExpAverage(CLOSE,10);
PLOT EMA5 = ExpAverage(CLOSE,12);
PLOT EMA6 = ExpAverage(CLOSE,15);
PLOT EMA7 = ExpAverage(CLOSE,30);
PLOT EMA8 = ExpAverage(CLOSE,35);
PLOT EMA9 = ExpAverage(CLOSE,40);
PLOT EMA10 = ExpAverage(CLOSE,45);
PLOT EMA11 = ExpAverage(CLOSE,50);
PLOT EMA12 = ExpAverage(CLOSE,60);

# finds max EMA out of the plot
def MAX12 = max(EMA1,EMA2);
def MAX34 = max(EMA3,EMA4);
def MAX56 = max(EMA5,EMA6);
def MAX78 = max(EMA7,EMA8);
def MAX910 = max(EMA9,EMA10);
def MAX1112 = max(EMA11,EMA12);
def MAX1234 = max(MAX12,MAX34);
def MAX5678 = max(MAX56,MAX78);
def MAX9101112 = max(MAX910,MAX1112);
def MAX12345678 = max(MAX1234,MAX5678);
def HMA = max(MAX9101112,MAX12345678);

## finds min EMA out of the plot
def MIN12 = min(EMA1,EMA2);
def MIN34 = min(EMA3,EMA4);
def MIN56 = min(EMA5,EMA6);
def MIN78 = min(EMA7,EMA8);
def MIN910 = min(EMA9,EMA10);
def MIN1112 = min(EMA11,EMA12);
def MIN1234 = min(MIN12,MIN34);
def MIN5678 = min(MIN56, MIN78);
def MIN9101112 = min(MIN910,MIN1112);
def MIN12345678 = min(MIN1234,MIN5678);
def LMA = min(MIN9101112,MIN12345678);

# Calculate the Compression Ratio
def pressRatio =(HMA-LMA)/close;

#Finds Lowest pressRatio over last 1008 days
input length = 1008;
def lowpressRatio = GetMinValueOffset (pressRatio, length);

# If lowpressRatio lowest out of 1008 show symbol
plot FourYearLow = lowpressRatio is true;
FourYearLow.setpaintingstrategy(paintingstrategy.boolean_arrow_up);
 

SleepyZ

Well-known member
This revises your max/min definitions. Included is a 'show_debug' input to help test this code. Also, added is code to use varying lengths or when there are not enough bars on the chart for the length, in which case it should use all of the bars.
Code:
#PressRatio
#Joriginal by JP-modified by Sleepyz

declare upper;

#EMA
def EMA1 = ExpAverage(close, 3);
def EMA2 = ExpAverage(close, 5);
def EMA3 = ExpAverage(close, 8);
def EMA4 = ExpAverage(close, 10);
def EMA5 = ExpAverage(close, 12);
def EMA6 = ExpAverage(close, 15);
def EMA7 = ExpAverage(close, 30);
def EMA8 = ExpAverage(close, 35);
def EMA9 = ExpAverage(close, 40);
def EMA10 = ExpAverage(close, 45);
def EMA11 = ExpAverage(close, 50);
def EMA12 = ExpAverage(close, 60);

# finds max EMA out of the plot
def HMA = Max(EMA1, Max(EMA2, Max(EMA3, Max(EMA4, Max(EMA5, Max(EMA6, Max(EMA7, Max(EMA8, Max(EMA9, Max(EMA10, Max(EMA11, EMA12)))))))))));
## finds min EMA out of the plot
def LMA = Min(EMA1, Min(EMA2, Min(EMA3, Min(EMA4, Min(EMA5, Min(EMA6, Min(EMA7, Min(EMA8, Min(EMA9, Min(EMA10, Min(EMA11, EMA12)))))))))));

input show_debug = yes;
AddLabel(show_debug, "HMA: " + HMA);
AddLabel(show_debug, "LMA: " + LMA);
AddLabel(show_debug, "EMAs: " + EMA1 + " " + EMA2 + " " + EMA3 + " " + EMA4 + " " + EMA5 + " " + EMA6 + " " + EMA7 + " " + EMA8 + " " + EMA9 + " " + EMA10 + " " + EMA11 + " " + EMA12);

# Calculate the Compression Ratio
def pressRatio = (HMA - LMA) / close;

#Finds Lowest pressRatio over last 1008 days or length
input length = 1008;
def lastbar  = (if !isnan(close) and IsNaN(close[-1]) then BarNumber() else Double.NaN);
AddLabel(show_debug, lastbar + " " + (HighestAll(lastbar)-length));
def lowpressRatio = compoundvalue(1, if barnumber()<HighestAll(lastbar) - length then double.nan else if barnumber()>=HighestAll(lastbar) - length then pressRatio else if !isnan(lowpressratio[1]) and pressRatio < lowpressRatio[1] then pressRatio else lowpressRatio[1], pressratio);


# If lowpressRatio lowest out of 1008 or length
plot FourYearLow = pressRatio == LowestAll(lowpressRatio) ;
FourYearLow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
 

JJP

New member
@JJP Did you want help with the code or are you posting it so other people can use it?
Both, but Looks like sleepyz fix all the bugs and it's working correctly now. Now I'm going to have to study "#Finds Lowest pressRatio over last 1008 days or length" so I can understand what's going on in the code. Thanks you all for helping me out.
 

Similar threads

Top