[英]How to find the highest and lowest value of a range
The code is working, but I would like to know how to find the highest and lowest value of the last three bars in the range after the "breakout bar" has appeared.代码正在运行,但我想知道如何在“突破柱”出现后找到范围内最后三个柱的最高值和最低值。
In the example below, the value is 2.在下面的示例中,该值为 2。
protected override void OnBarUpdate()
{
if (CurrentBar < 3)
{
Value[0] = 0;
}
else if((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Close[0] > High[1]))
{
Value[0] = 2;
}
else if ((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Close[0] < Low[1]))
{
Value[0] = -2;
} else if ((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Close[0] > Close[1]))
{
Value[0] = 1;
} else if ((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Close[0] < Close[1]))
{
Value[0] = -1;
}
else
{
Value[0] = 0;
}
}
I used the MAX and MIN function as @kirodge recommended and it worked.我按照@kirodge 的建议使用了 MAX 和 MIN function 并且效果很好。 Here is the solution.
这是解决方案。
protected override void OnBarUpdate()
{
{
if (CurrentBar < 3)
{
Value[0] = 0;
}
else if((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Low[0] < Low[3] && Close[0] > MAX(High, 3)[1]))
{
Value[0] = 2;
}
else if ((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Low[0] < Low[3] && Close[0] < MIN(Low, 3)[1]))
{
Value[0] = -2;
} else if ((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Low[0] < Low[3] && Close[0] > Open[1]))
{
Value[0] = 1;
} else if ((High[0] > High[1] && High[0] > High[2] && High[0] > High[3] && Low[0] < Low[1] && Low[0] < Low[2] && Low[0] < Low[3] && Close[0] < Open[1]))
{
Value[0] = -1;
}
else {
Value[0] = 0;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.