How to find high and low between ema cross overs

hello,
i want to find high and low between ema cross overs. if i use highest since or lowest since with 1 occurance its not giving desired results, as range need to be defined from positive to negative cross. and then applying highest (array) fuction. But how to define this range .need help

TimeFrameSet(in1Minute*240);
EMA94h=EMA(C,9);
EMA214h=EMA(C,15);//15used for study purpose//
positive4hr=Cross(EMA94h,EMA214h);
negative4hr=Cross(EMA214h,EMA94h);
TimeFrameRestore();

facebook

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 

ema1 = EMA(C, 5);
ema2 = EMA(C, 30); 

rngH = LastValue( ValueWhen( Cross( ema2, ema1 ), HighestSince( Cross( ema1, ema2 ), H ) ));
rngL = LastValue( ValueWhen( Cross( ema2, ema1 ), LowestSince ( Cross( ema1, ema2 ), L ) ));

_TRACEF("%.2f %.2f ", LastValue( rngH ), LastValue( rngL ));

Plot(ema1,"ema1",colorAqua);
Plot(ema2,"ema2",colorYellow);

It's your lucky day :slight_smile:

1 Like

Also, I just realized going by your Thread topic that the bars marked on the chart are not correct.

A crossover as a pair, will be one +ve crossover and one -ve crossover, and the period between those two events will be considered for computation.

From your partial code, you have defined a +ve cross with the faster MA crossing over the slower one.

Thanks for your reply tavick ..and pointing error :slight_smile:
yes u got it right what i need to say high or low between this pair of cross
plotting your will come back to u
Thanks

You can hit the like button and mark that post as solution if it suits your need.

Not working travick travick

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
TimeFrameSet(in1Minute*240);
ema1 = EMA(C, 9);
ema2 = EMA(C, 21);
TimeFrameRestore();

rngH = LastValue( ValueWhen( Cross( ema2, ema1 ), HighestSince( Cross( ema1, ema2 ), H ) ));
rngL = LastValue( ValueWhen( Cross( ema2, ema1 ), LowestSince ( Cross( ema1, ema2 ), L ) ));

PlotShapes( IIf(rngh,shapeSmallUpTriangle + shapePositionAbove, shapeNone ), colorGreen );
PlotShapes( IIf(rngl,shapeSmallDownTriangle + shapePositionAbove, shapeNone ), colorRed );

//_TRACEF("%.2f %.2f ", LastValue( rngH ), LastValue( rngL ));

Plot(ema1,"ema1",colorAqua);
Plot(ema2,"ema2",colorYellow);

continues markings are coming because we havent defined any range ..that whats my doubt is how to define positive cross to negative cross region ..if we define that array we can use just highest(array) fuction so it will display only highest value in that array .
Thanks

Don't blame the code snippet if it is not working when you have modified the code in an inappropriate way.

You have used TimeFrame Functions incorrectly. Study here (Don't just read it).
https://www.amibroker.com/guide/h_timeframe.html

rngH and rngL are variables that hold the Price values.

Using them "IIf(rngh" is completely absurd when trying to Plot on a specific bar.

And yeah, it's working at my end.
image

appreciate your quick response
but the image u posted is showing shape plotted at the crossing which is not the doubt sir..
challange is to identify high between positive and negative cross ..travick1 Am not blaming code ..trying to learn with your guidance

Its very much possible, and its not difficult at all.

You have still not addressed the issue of incorrectly using the TF variables.
Also, the Plotshapes codes aren't correct. ShapePositionAbove, is misplaced and a lot more like the Y-axis parameter is missing.
Doesn't give a good impression.

If you are going to plot or reference a future value, you need to define the condition accordingly.

1 Like

thanks for some more correction ..m reading timeframe section from help editor.
can you please guide how its possible to get high between those ema cross over.

@sudarshanagni How about this ?

image

2 Likes

exactly sir superr....:heart_eyes:

1 high should be marked on extreme left and one low on extreme right ....got correct sir i was trying to plot auto fib by using such high and low on 4 hr timeframe and take trade on 5 min time fram when price comes near support of 4hr timefram fib. possible?

Here is code solution

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


tmfrm = in1Minute*240;
TimeFrameSet(tmfrm);
ema1 = EMA(C, 9);
ema2 = EMA(C, 21);
TimeFrameRestore();

ema1 = TimeFrameExpand(ema1, tmfrm, expandmode = expandLast);
ema2 = TimeFrameExpand(ema2, tmfrm, expandmode);

Plot(ema1,"ema1",colorAqua);
Plot(ema2,"ema2",colorYellow);

/// Plot HHV and LLV of upcross/dncross
/// @link https://forum.amibroker.com/t/how-to-find-high-and-low-between-ema-cross-overs/8685/18
upcrss = Cross( ema1, ema2 );
dncrss = Cross( ema2, ema1 );
is_lastbar = BarIndex() == LastValue(BarIndex());

/// Don't use for Backtesting!!!!
HHVup = Valuewhen(dncrss OR is_lastbar, HighestSince(upcrss, H), 0);
LLVup = Valuewhen(upcrss OR is_lastbar, LowestSince(dncrss, L), 0);

//Plot( IIf(ema1 > ema2, HHVup, Null), "Price", colorGreen );
//Plot( IIf(ema1 < ema2, LLVup, Null), "Price", colorRed );

Plot( C, "Price", colorDefault, styleCandle );
PlotShapes( (H == HHVup) * shapeSmallSquare, colorGreen, layer = 0, y = H, dist=12 );
PlotShapes( (L == LLVup) * shapeSmallSquare, colorRed, layer, y = L, -dist );

@sudarshanagni
Applying code tags is mandatory in this forum. Don't be lazy!
Read here https://forum.amibroker.com/t/how-to-use-this-site/

523

6 Likes