Check previous 10 candles/bars and determine the lowest close price

1
Hi,

How could have a function that checks the previous 10 candles/bars and determine the lowest close price of those candles/bars?I found this for MT4,but I need a function that works with mt5 ...

Code: Select all

double CalcStopLoss()
{
double sl;
double LowestClose = Low[iLowest( NULL, 0, MODE_CLOSE, 10, 1 )];
double HighestClose = Low[iHighest( NULL, 0, MODE_CLOSE, 10, 1 )];
if ( Close[0] < LowestClose ) sl = Ask; //--- Buy Stop Loss
else if ( Close[0] > HighestClose ) sl = Bid; //--- Sell Stop Loss
return( sl );
}
 


Re: Check previous 10 candles/bars and determine the lowest close price

2
I found this, I think that will do the trick.

mt5 code

Code: Select all

double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
  {
   double highest=0;
   double High[];
   ArraySetAsSeries(High,true);
   int copied=CopyHigh(symbol,timeframe,start,count,High);
   int index=ArrayMaximum(High,0,count)+start;
   if(copied>0 && index<copied) highest=High[index];
   return(highest);
  }
double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0)
  {
   double lowest=0;
   double Low[];
   ArraySetAsSeries(Low,true);  
   int copied=CopyLow(symbol,timeframe,start,count,Low);
   int index=ArrayMinimum(Low,0,count)+start;
   if(copied>0 && index<copied) lowest=Low[index];
   return(lowest);
  }

Re: Check previous 10 candles/bars and determine the lowest close price

3
baraozemo wrote:I found this, I think that will do the trick.

mt5 code

Code: Select all

 double Highest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0) { double highest=0; double High[]; ArraySetAsSeries(High,true); int copied=CopyHigh(symbol,timeframe,start,count,High); int index=ArrayMaximum(High,0,count)+start; if(copied>0 && index<copied) highest=High[index]; return(highest); } double Lowest(string symbol,ENUM_TIMEFRAMES timeframe,int count=WHOLE_ARRAY,int start=0) { double lowest=0; double Low[]; ArraySetAsSeries(Low,true); int copied=CopyLow(symbol,timeframe,start,count,Low); int index=ArrayMinimum(Low,0,count)+start; if(copied>0 && index<copied) lowest=Low[index]; return(lowest); } 
For that case you don't need to set the target array as series - it would probably run a bit faster


Who is online

Users browsing this forum: No registered users and 9 guests