【发布时间】:2015-02-20 09:22:59
【问题描述】:
我正在尝试遍历数组和i。我需要 MAX 前 10 个值的值。
所以if i= 20,我需要math.max i-10, i-9, i-8... 等等。但我正在努力让它发挥作用。
static public void TA(DateTime[] datePrice, double[] openPrice, double[] highPrice, double[] lowPrice, double[] closePrice)
{
#region declare variables
int outBegIdx;
int outNbElement;
int SmaPeriod = 20;
int TOTAL_PERIODS = closePrice.Length;
double[] outputSma = new double[closePrice.Length];
double[] outputStdDev = new double[closePrice.Length];
int[] outputShootingStar = new int[closePrice.Length];
int[] outputHangingMan = new int[closePrice.Length];
int[] outputEngulf = new int[closePrice.Length];
int[] outputMaxIndex = new int[closePrice.Length];
double[] outputTrueRange = new double[closePrice.Length];
double accProfit = 0;
int position = 0;
double openPosPrice = 0;
double profit = 0;
#endregion
#region not sure what this code is for
//for (int i = 0; i < closePrice.Length-TOTAL_PERIODS; i++) //had to change from -1 to -TOTAL_PERIODS
//{
// openPrice[i] = (double)i;
// highPrice[i] = (double)i;
// lowPrice[i] = (double)i;
// closePrice[i] = (double)i;
//}
#endregion
#region Technical Libary
TicTacTec.TA.Library.Core.RetCode Sma = Core.Sma(0, closePrice.Length - 1, closePrice, SmaPeriod, out outBegIdx, out outNbElement, outputSma);
TicTacTec.TA.Library.Core.RetCode StdDev = Core.StdDev(0, closePrice.Length - 1, closePrice, closePrice.Length, 1, out outBegIdx, out outNbElement, outputStdDev);
TicTacTec.TA.Library.Core.RetCode ShootingStar = Core.CdlShootingStar(0, closePrice.Length - 1, openPrice, highPrice, lowPrice, closePrice, out outBegIdx, out outNbElement, outputShootingStar);
TicTacTec.TA.Library.Core.RetCode HangingMan = Core.CdlHangingMan(0, closePrice.Length - 1, openPrice, highPrice, lowPrice, closePrice, out outBegIdx, out outNbElement, outputHangingMan);
TicTacTec.TA.Library.Core.RetCode BullIngulf = Core.CdlEngulfing(0, closePrice.Length - 1, openPrice, highPrice, lowPrice, closePrice, out outBegIdx, out outNbElement, outputEngulf);
TicTacTec.TA.Library.Core.RetCode TrueRange = Core.TrueRange(0, closePrice.Length - 1, highPrice, lowPrice, closePrice, out outBegIdx, out outNbElement, outputTrueRange);
//TicTacTec.TA.Library.Core.RetCode xx = Core.bu
//TicTacTec.TA.Library.Core.RetCode MaxIndex = Core.MaxIndex(0, closePrice.Length - 1, highPrice, 20, out outBegIdx, out outNbElement, outputMaxIndex);
#endregion
for (int i = 20; i < closePrice.Length - 1; i++)
{
for (int j = 0; j < 10; j--)
{
}
}
}
【问题讨论】:
-
贴一些你目前写的代码
-
您现有的代码将帮助我们理解您的错误:)
-
那么你需要n个最大值吗?还是什么?
-
您想要最多十个先前的元素?第一个元素的输出应该是什么?