There are several ways to create rules that detect uptrends and downtrends.
You can for example use the moving average:
uptrend = close > sma(30);
downtrend = close < sma(30);
Or the Adx indicator:
uptrend = adx(10) > 25 and perf(close, 10) > 0;
downtrend = adx(10) > 25 and perf(close, 10) < 0;
ADX Value - Trend Strength
0-25 - Absent or Weak Trend
25-50 - Strong Trend
50-75 - Very Strong Trend
75-100 - Extremely Strong Trend
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.