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.
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
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);
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);
# 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;
This what I have come up with. I'm no pro at this, just a baby trying to learn how to crawl.@JJP Don't really understand what plot a symbol means but you can try using lowest() and compare with current value.
#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);
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);
It just another way to find a squeeze.looks pretty good, i dont know what your doing but looks good
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.@JJP Did you want help with the code or are you posting it so other people can use it?
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
G | How to plot HIGH/LOW of recent monthly EMA crossover | Questions | 8 | |
C | High / Low horizontal lines | Questions | 2 | |
I | 50% Retracement From Daily High/Low | Questions | 1 | |
J | Implied Volatility High & Low | Questions | 2 | |
Mobile Prior Daily Open High Low | Questions | 1 |