# 2. 交易趨勢預測的程式設計

## # 題目要看清楚...

```csharp
Console.WriteLine("最高價:");
var highest = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
Console.WriteLine("收盤價:");
var close = Console.ReadLine().Split(' ').Select(double.Parse).ToList();
Console.WriteLine("最低價:");
var lowest = Console.ReadLine().Split(' ').Select(double.Parse).ToList();

double adxFirst = 0;
List<double> adx = new List<double>();
for (int i = 19; i < highest.Count; i++)
{
    double dxAvg = 0;
    for (int k = i - 10 + 1; k <= i; k++)
    {
        Console.WriteLine(k);
        double pdmAvg = 0;
        double mdmAvg = 0;
        double trAvg = 0;
        for (int j = k - 10 + 1; j <= k; j++) // 10, 20
        {
            double pdm = Math.Max(highest[j] - highest[j - 1], 0);
            double mdm = Math.Max(lowest[j - 1] - lowest[j], 0);

            if (pdm == mdm)
            {
                pdm = 0;
                mdm = 0;
            }
            else if (pdm > mdm) mdm = 0;
            else pdm = 0;

            pdmAvg += pdm;
            mdmAvg += mdm;


            double tr = Math.Max(Math.Max(
                    Math.Abs(highest[j] - lowest[j]),
                    Math.Abs(highest[j] - close[j - 1])
                    ), Math.Abs(lowest[j] - close[j - 1]));
            trAvg += tr;
        }
        pdmAvg /= 10;
        mdmAvg /= 10;
        trAvg /= 10;

        double pdi = pdmAvg / trAvg;
        double mdi = mdmAvg / trAvg;

        dxAvg += 100 * Math.Abs(pdi - mdi) / (pdi + mdi);
    }
    dxAvg /= 10;
    if (i == 19) adxFirst = dxAvg;
    else
        adx.Add(dxAvg);
}

Console.Write("ADX : ");
foreach (var item in adx)
{
    Console.Write($"{item:0.00}\t");
}
Console.Write("\n預測: \t");
adx.Insert(0, adxFirst);
for (int i = 1; i < adx.Count; i++)
{
    Console.Write($"{(adx[i] >= adx[i - 1] ? "1" : "0")}\t");
}
```
