How to get high from 5 and more PIPS help !!

 

Hello .. I want to get maximum of high of 5 or more pips ..

for(i=1;i<=X;i++)

{
if (iHigh(NULL,perioda,i) > max) max=iHigh(NULL,perioda,i);
if (iLow(NULL,perioda,i) < min) min=iLow(NULL,perioda,i);
}

I think its good. Minimum is ok .. its for short positions .. But long position when Close[0]>max never happened.

Can you help me ?


all code here :

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

//extern
extern double StopLoss=30;
extern double TrailingStop=30;
//perioda a vypocet cong
int perioda=PERIOD_H4;
bool congestion=true;
int zaciatokciarka=5;
//vypocet min max
double max;
double min;
//poctiadlo
int i;
//kazdy periodu len 1 obchod
bool kupuj=false;
double akt=0;
//--------------------------------------------------------------------
int init() // Spec. funct. init()
{
Alert ("------------------------------------------ZACIATOK------------------------------------------");// Alert
return; // Exit init()
}
//--------------------------------------------------------------------

int start() // Spec. funct. start()
{ //start
//+------------------- dalsia ciarka
if ( akt!=iOpen(NULL,perioda,0) )
{
kupuj=true;
}
akt=iOpen(NULL,perioda,0);
//+------------------- END dalsia ciarka

//+------------------- je congestion ?
int rozsah=6;
bool zaciatocnepole[40];
for (i=0;i<40;i++) zaciatocnepole[i]=false;
for(zaciatokciarka=5;zaciatokciarka<=rozsah;zaciatokciarka++)
{
congestion=true;
for(i=0;i<zaciatokciarka;i++) //+---je zaciatocna ciarka congestion ?
{
if(
( (iLow(NULL,perioda,zaciatokciarka)<iClose(NULL,perioda,i)) && (iHigh(NULL,perioda,zaciatokciarka)>iClose(NULL,perioda,i)) )
||
( (iLow(NULL,perioda,zaciatokciarka)<iOpen(NULL,perioda,i)) && (iOpen(NULL,perioda,zaciatokciarka)>iClose(NULL,perioda,i)) )
)
i=i; //.nerob nic
else congestion=false;
} //+-------------------------------END je zaciatocna ciarka congestion ?
if (congestion==true) zaciatocnepole[zaciatokciarka]=true;
else zaciatocnepole[zaciatokciarka]=false;
}
//+------------------- END je congestion ?

//+------------------- ktoru zac ciarku vezemem
int pokade=0;
for (i=rozsah;i>=5;i--)
if (zaciatocnepole[i]==true) pokade=i;
//+------------------- END ktoru zac ciarku vezemem

//+------------------- vypocet max min
if (pokade!=0)
{
max=0;
min=1000000;
for(i=1;i<=pokade;i++)
{
if (iHigh(NULL,perioda,i) > max) max=iHigh(NULL,perioda,i);
if (iLow(NULL,perioda,i) < min) min=iLow(NULL,perioda,i);
}
}
//+------------------- END vypocet max min

//+------------------- vstup do trhu
if (pokade!=0)
{
if ( Close[0]>max && kupuj ) //kupuj=bye THIS NEVER HAPPENED .. only LOW
{OrderSend(Symbol(),OP_BUY,1,Ask,1,Ask-StopLoss*Point,0,"countobchodov",234,0,Green); //Ask-StopLoss*Point
kupuj=false;}
if ( Close[0]<min && kupuj ) //calculation for short position is correct
{OrderSend(Symbol(),OP_SELL,1,Bid,1,Bid+StopLoss*Point,0,"countobchodov",234,0,Red); //Bid+StopLoss*Point
kupuj=false;}
}
//+------------------- END vstup do trhu

//+------------------- TrailingStop
TrailingStopProcedure();
//+------------------- EndTrailingStop
return; // Exit start()
}
void TrailingStopProcedure()
{
for(i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) continue;
if(OrderType()==OP_BUY) //buy order
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
return(0);
}
}
}
if(OrderType()==OP_SELL) //sell order
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
//trailing


//--------------------------------------------------------------------
int deinit() // Spec. funct. deinit()
{
Alert ("------------------------------------------KONIEC------------------------------------------"); // Alert
return; // Exit deinit()
}
//--------------------------------------------------------------------