Buy sell signal for EMA15 crossover candle above and below

Hi, Please help in getting the correct code. Whenever EMA(15) crosses a candle, I need the buy signal of EMA (15) crossover candle high breaks in next any candle. Also the sell signal when EMA (15) crossover candle low breaks in next any candle.

_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("EMA");

Plot( EMA( C, 15 ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

CBuy = Cross(C, EMA(C,15)); // need signal of buy above CBuy high crossed
CSell = Cross(EMA(C, 15), C); // need signal of sell belolw CSell low crossed
PlotShapes(IIf(CBuy, shapeUpArrow, shapeNone), colorGold, 0, Low, -15);
PlotShapes(IIf(CSell, shapeDownArrow, shapeNone), colorPink, 0, High, 15);

1 Like

Hi adepukisan,

I Think this what you are looking for.

CBuy = Cross(H,Ema(C,15)); 
Csell = Cross(EMA(C,15),L);

C = Close
O = Open
H = High
L = Low

For the next time you ask an question on this forum, please post your code within </> quotes.

1 Like

Hi, Thank you for your response. Tried that way but my requirement is, After EMA 15 crosses the candlestick it should give me buy or sell signal in any next candle after crossing the high or low of the signalled candle. signal

@beppe Kindly please help on the above post

Hi Adepukishan,

I think this is what you are looking for.

With the exploration function you can see what is happening in the used array's.

EMA15	= EMA(C,15);
	
Up  	= Cross(C, EMA15); 
Down 	= Cross(EMA15, C);
State   = Flip(Up, Down);

HighCross  	= ValueWhen(Cross(C,EMA15),H);
LowCross 	= ValueWhen(Cross(EMA15,C),L);

Buy1 = State==1;
Buy2 = C > HighCross;
Buy  = Buy1 AND Buy2;

Sell1 = State==0;
Sell2 = C < LowCross;
Sell  = Sell1 AND Sell2;

Buy  = ExRem(Buy,Sell);
Sell = ExRem (Sell,Buy);

Plot(EMA15,"EMA15", colorYellow);

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone), colorGreen, 0, High);
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone), colorRed, 0, High);


// Use columns for exploration check
Filter=1;
Filter=1;
TextList = "No signal\n Sell Regular exit\n Sell Max. Loss\n Sell Profit Target\n Sell Trailling Stop\n Sell n-bar Stop\n Sell Ruin Stop\n Buy\n Buy and Sell"; 
TextSelector = 1*Sell +7*Buy;
AddMultiTextColumn( TextSelector, TextList, "Which signal", 1, IIf( Buy, colorGreen, IIf( Sell, colorRed, colorBlue)),55,140); 
AddColumn (UP,"Up");
Addcolumn (Down,"Down");
AddColumn (State,"State");
AddColumn (Close,"Close");
AddColumn (LowCross,"LowCross");
AddColumn (HighCross,"HighCross");
AddColumn (Buy,"Buy",1.0,1,IIf(Buy == 1,8,55),45);
AddColumn (Sell,"Sell",1.0,1,IIF(Sell == 1,32,IIf(Sell==4,25,55)),45);

_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", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();
5 Likes

@rola, Thank you for your time and your great effort. Got the output correct.

Kindly please verify License

That's Nice.

Also thanks for the received "Love".

Can anybody of the experts / members help me out with may post of 6 december.

Post: No New Buy after a sell from a trailings stop

I can't find find the cause. See my three questions under the printscreens.