简体   繁体   中英

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.

在此处输入图像描述

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. 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;
    }
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM