Signal for second time testing same level

I am trying to get a signal if price attempts to cross yesterday high "second" time

Yhighcross = cross ( C, yHigh) ;  // this to check price crossing yesterday high 

Not sure how to define first cross or second cross . Appreciate anyone help

image

Use Sum() Function

Yhighcross = cross ( C, yHigh );

barS = BarsSince( Day() != Ref( Day(), -1) ); // Assuming intraday TF, bars from Open

doubleCross = Sum( Yhighcross, barS + 1) >= 2;    // Two or more
1 Like

Thanks a lot for quick response

for first cross i am getting like this


Yhighcross = cross (  yHigh  , C);
PlotShapes(Yhighcross * shapeDownArrow, colorWhite, 0, H);

image

but for the second cross i am getting all over the bars


Yhighcross = cross (  yHigh  , C);

PlotShapes(Yhighcross * shapeDownArrow, colorWhite, 0, H);

doubleCross = Sum( Yhighcross , barS + 1) >= 2;    // Two or more
PlotShapes(doubleCross * shapeDownArrow, colorYellow, 0, H);


image

How do i fix this . Thanks again for your time and help

Did you check the >= operator and what it means?
It will count for two or more.
If you want exactly 2, it should be ==

Also, dont directly use

PlotShapes( doubleCross …

This is incorrect because Array state will always be 2 or more because Sum() holds the existing count for each bar, not a True/False state.

doubleCross = Sum( Yhighcross , barS + 1) == 2;
doubleCross = ExRem( doubleCross, -1);

Then use the doubleCross Array.

1 Like

Thanks a lot ...Implemented your idea . I am getting like this. Its showing on all bars after second cross . would like to have it only on signal bar only .. Seems like Exrem is not helping or i am doing still some mistake . Appreciate your help

Yhighcross = cross (  yHigh  , C);

PlotShapes(Yhighcross * shapeDownArrow, colorWhite, 0, H);

doubleCross = Sum( Yhighcross , barS + 1)== 2;    // Second time crossing 
doubleCross = ExRem( doubleCross, -1);
PlotShapes(doubleCross * shapeDownArrow, colorYellow, 0, H);

image

Firstly, my bad for using -1 it should be 0 or you can use keyword False

Secondly, ExRem will work, provided you make sure that previous days don't match or create false positives.

To check this, do

doubleCross = Sum( Yhighcross, barS + 1) == 2;
doubleCross = ExRem( doubleCross, 0);

realC = Cum( doubleCross ); // Make sure this value is 2, ie. 1 + 1

previous matches will return a large value in my case around 30.

To ensure that I was testing the current Day, I modified by Day check like this

barS = BarsSince( Day() != Ref( Day(), -1) AND LastValue(Day()) == Day() AND LastValue(Month()) == Month() );

There might be a better way to check, but my goal for now was to check why ExRem isn't working but its actually working fine.

2 Likes

image
I have used a slightly different condition, that is, when prices Closes above previous close.

Top image is condition true == 1
Bottom image is condition true == 2

2 Likes

All you have to do is this

/// @link https://forum.amibroker.com/t/signal-for-second-time-testing-same-level/8755/8
yhigh = TimeFrameGetPrice( "H", inDaily, -1 );

// all crosses from below
Yhighcross = Cross(C, yHigh);
PlotShapes(Yhighcross * shapeDownArrow, colorWhite, 0, H);

// 2nd cross from below
dn = DateNum();
doubleCross = Yhighcross AND SumSince(dn != Ref(dn, -1), Yhighcross) == 2;   
PlotShapes(doubleCross * shapeDownArrow, colorYellow, 0, H);

Plot( C, "Price", colorDefault, styleCandle );
Plot( yhigh, "yHigh", colorWhite, styleStaircase );// yesterday high
3 Likes

Thank you @travick and @fxshrat . Appreciate your help

image

1 Like