ValueWhen to display value at point of an EMA crossover

I am trying to get my exploration to show the value at the cross of 2 EMA lines to display in a column, the number returned in the column does not look to be the point of Cross.

EMA_column=ValueWhen( Cross( EMA( Close, 20), EMA( Close, 50 ) ),C);

AddColumn(EMA_column,"EMA Cross",1.2);

Thoughts appreciated.

@brownbench it looks like it is OK to me.

BTW, welcome to the forum but try to use the proper code tags when posting code.

You may want to look over this type of Exploration to see if the Close on the bar that the moving averages crossover is correctly identified.

EMA20 = EMA( C, 20 );
EMA50 = EMA( C, 50 );

EMA_column = ValueWhen( Cross(EMA20, EMA50), C );

Filter = 1; // all bars and all symbols
ColorCross = IIf( Cross( EMA20, EMA50 ), colorGreen, IIf( Cross( EMA50, EMA20 ), colorRed, colorDefault ) );
AddColumn( C, "Close" );
AddColumn( EMA20, "EMA20" );
AddColumn( EMA50, "EMA50" );
AddColumn( EMA_column, "EMA Cross", 1.2,  colorDefault, ColorCross );
4 Likes

Thank you portfoliobuilder this looks to work for me.