Need help to code strategy

Hi,

I am a new member of Zerodha. I need code for following strategy. Would appreciate if you could help.

Have 50 EMA High and Low band on chart.

Wait for candle to break above High EMA 50 and close above that.

Now this closed candle becomes reference / trigger candle and once price goes above High of this reference candle Go Long.

Same for going Short.

I could make and use code upto reference / trigger candle as follows -

Buy expression: Close > REF(EMA(High,50),1)

Sell expression: Close < REF(EMA(Low,50),1)

This is working fine on Pi

Now I want to code further for going Long if price goes above the closed candle.

Please help !!!

Buy- CLOSE>REF(EMA(HIGH,50),1) AND LAST>REF(CLOSE,1)

Sell- CLOSE<REF(EMA(LOW,50),1) AND LAST<REF(CLOSE,1)

It may give less but more accurate signals

No something is wrong
I tried -
Close > REF(EMA(High,50),2) AND LAST > REF(HIGH,1)
As well as this -
REF(Close,1) > REF(EMA(High,50),2) AND LAST > REF(HIGH,1)
But still Error message is getting generated

what is the error?

I am sorry. I have mis communicated.
Code suggested by you is generating report; but I want to enter trade only if high of reference candle is taken out which is not happening in code suggested by you. So I tried other codes specified by me; and which are giving error.
Pi chart gives following reply upon applying code for back testing
"Your Script generated an error"
"Error:Script generated no trades"
It does not specify area of error in the code
Thanks for feedback.

as per your code, i tried for icici-eq, 1 minute chart., gives backtest results
Buy- Close > REF(EMA(High,50),2) AND LAST > REF(HIGH,1)
Sell- Close < REF(EMA(LOW,50),2) AND LAST < REF(LOW,1)
Buy Exit- 0
Sell EXit- 0
Make sure you are keying in values in all the boxes.

Yes it is generating signals but entry arrow is shown at reference / trigger candle i.e. when candle close is above EMA but not at the candle which exceeds High / Low of the reference candle.
Thanks again.

Hi,
Please try this -
Buy: LAST > REF(HIGH,1) AND REF(CLOSE,1) > REF(EMA(HIGH,50),2)
Sell: LAST < REF(LOW,1) AND REF(CLOSE,1) < REF(EMA(LOW,50),2)
Now entry arrow is shown correctly.
However few minor problems needs to be solved -

  1. Entry and exit prices considered in back testing are closing prices of entry bar and not High / Low exceeding point of previous bar.
  2. If entry bar’s closing price is beyond reference bar closing it is considering that bar as entry bar; and not when it breaches High / Low of previous bar and closes not exceeding closing price of previous bar.
    Please advise if you have got any resolution for above cited issues.
    Thank you Andrewman for giving me correct thinking direction.