Need script for exit long script

Can some one help me to get the exit long script.
Condition is when first red candle open and close below ema of 50 days

Which algo trding platform use the same coding as back testing cods of PI.