Back testing code for the strategy

Hi,

Can anyone help me code the following EMA Crossover strategy in PI for backtesting :

Buy Signal

EMA 13 crosses above EMA 26

Close above crossover of EMA 13 and 26 AND

Volume greater than 10 day average volume AND

MACD relatively making a new high ( or up trend)

Exit buy Signal :

If close is below the low of previous candle

Sell Signal

EMA 13 crosses below EMA 26

Close below crossover of EMA 13 and 26 AND

Volume greater than 10 day average volume AND

MACD relatively making a new low ( or down trend)

Exit sell Signal :

If close is above the low of previous candle

Also , I have noticed that while backtesting, PI immediately generates buys or sells after an exit signal. How to stop PI for generating such signal and wait for a completely new crossover setup?

Thanks in advance :slight_smile:

For the above condition 

Buy Script:

SET A = MACDSignal(13, 26, 9, SIMPLE)
SET B = MACD(13, 26, 9, SIMPLE)
CROSSOVER(EMA(CLOSE,13),EMA(CLOSE,26)) AND VOLUME > AVG(VOLUME, 10) 
AND CROSSOVER(A, B) = TRUE

Sell Script:

SET A = MACDSignal(13, 26, 9, SIMPLE)
SET B = MACD(13, 26, 9, SIMPLE)
CROSSOVER(EMA(CLOSE,26),EMA(CLOSE,13)) AND VOLUME < AVG(VOLUME, 10) 
AND CROSSOVER(B, A) = TRUE