#### Topic: Math.Min ,max question

if Today’s low is lower than the previous 15 lows then buy

what is the mistake

``````public override void Calculate(SlotTypes slotType)
{
// Reading the parameters
int iFirstBar = 16;

double[] adUp = new double[Bars];
double[] adDn = new double[Bars];

for (int iBar = 16; iBar < Bars - 1; iBar++)
{
// Long trade
//1. Today’s low is lower than the previous 15 lows.
if (Low[iBar - 15] < Math.Min(Low[iBar - 1], Low[iBar - 15]))
adUp[iBar] = 1;``````

Thanks in advance

#### Re: Math.Min ,max question

You have to loop through all 15 bars to find the low.

I'd do something like this, based on Donchian Channel indi:

``````for (int iBar = iFirstBar; iBar < Bars; iBar++)
{

double dMin = double.MaxValue;
for (int i = 1; i < 16; i++)
{

if (Low[iBar - i]  < dMin) dMin = Low[iBar - i];

}

if (Low[iBar-1] < dMin)
long[iBar]=1;
}``````

#### Re: Math.Min ,max question

thanks footon

So i can write the code for buy setup as follow

``````public override void Calculate(SlotTypes slotType)
{
// Reading the parameters
int iFirstBar = 16;

double[] adUp = new double[Bars];
double[] adDn = new double[Bars];

for (int iBar = 16; iBar < Bars - 1; iBar++)
{
// Long trade
//1. Today’s low is lower than the previous 15 lows.
double dMin = double.MaxValue;
for (int i = 1; i < 16; i++)
{
if (Low[iBar - i] < dMin) dMin = Low[iBar - i];
}

if (Low[iBar - 1] < dMin)
adUp[iBar] = 1;``````

Is that right !!!!!

#### Re: Math.Min ,max question

Seems to be right. Although I would use the main for loop like in my previous post:

``for (int iBar = iFirstBar; iBar < Bars; iBar++)``