Help advice and tips CODE - EMA support and resistance

 

write this post to have some advise how i can code this idea:

i read the lesson post on babypips forum about the ema like dynapic support and resitance; and that is what i want to code:

esample : i have 5 ema 20/50/100/150/200 the price go down , before the brake down for example the 150 ema is the resistance and the 50 the support

how can write a code that recognizing which is the latest ema lower that acted as resistance and one that acted as support .I thought to find the bar that breaks and save index from that analyze the future to determine the new dynamic support , analizando instead by the bar break the bars past which is the ema which was the resistance (esample: After the last break for ema which the price was always below , if the price was alway's belove 100/150/200 the las t resistenze min was the 100 ema period).

this is my question wixh is the best way to realize that :

thanks for info of any example of code

sorry for my english