open order with first candle close

 

hello,

i want to know the code that allow me to go long or short with the first candle close only, for example the first close above the EMA

and another requset plz, i want to put some condition after the order get profit such as switch the order from buy to sell, how can i do that

thank you

 
please any body answer my questions