Need help in Amibroker AFL code when I hard code previous days to scan it works fine but when I get it by a function it gives wrong result

  amibroker, c++

Below is the code for high low till innerCandle

I am trying to get the High and Low for N number of days where N is the days when InnerCandle formed.
from that day to till day High Low.

Code works fine when I put Days hardcoded but when I get it by function, it returns all bars High Low.

chart

_SECTION_BEGIN("N_Day_HiLo");

YDayH = TimeFrameGetPrice("H", inDaily, -1);  // yesterdays high
YDayL = TimeFrameGetPrice("L", inDaily, -1);  //  low
YDayC = TimeFrameGetPrice("C", inDaily, -1);  //  close
DayO = TimeFrameGetPrice("O", inDaily);  // current day open
////////////////////////////////////////////////////////////////////////////////////////////////////////
Y2DayH = TimeFrameGetPrice("H", inDaily, -2);  // day before yesterdays high
Y2DayL = TimeFrameGetPrice("L", inDaily, -2);  //  day before low
Y2DayC = TimeFrameGetPrice("C", inDaily, -2);  //  day before close
////////////////////////////////////////////////////////////////////////////////////////////////////////

 
 PlotShapes(IIf(YDayH<Y2DayH AND YDayH>Y2DayL AND YDayL>Y2DayL AND YDayL<Y2DayH, shapeSquare, shapeNone),colorWhite, 0, H, Offset=55);

 
 PlotShapes(IIf(Ref(H<YDayH AND H>YDayL AND L>YDayL AND L<YDayH,1), shapeHollowCircle, shapeNone) , colorRed, 0,H, Offset=90);
 
lookBackDays = Param("Look Back", 10, 1, 60, 1);


 function getInnerOuterCandleLocation(lookBackDays){
 position=0;
 if( lookBackDays <= BarCount ){
  innerCandleFromedPosition = 0;
  
  for(i = BarCount-1; i > BarCount-lookBackDays-1; i--)
  {

cond1 = YDayH[i]<Y2DayH[i];
cond2 = YDayH[i]>Y2DayL[i];
cond3 = YDayL[i]>Y2DayL[i];
cond4 = YDayL[i]<Y2DayH[i];

cond = cond1 AND cond2 AND cond3 AND cond4;

  if(cond){
      innerCandleFromedPosition=i;
      break;
    }
  }
  
  position = 200-innerCandleFromedPosition;
  }
  else {
  position = 0;
  }
  printf("day to inner candle %g", position);
  return position;
}
 





// Set chart display parameters
// Chart background is Black,
// Date Axis displayed,
// Long titles wrapped to next line
 
SetChartOptions(0, chartShowDates | chartWrapTitle);
SetChartBkColor(colorBlack);
 
// Locate Highest HIGH and Lowest LOW in last N days
 
N = getInnerOuterCandleLocation(lookBackDays); //daysback; // i am getting problem here if i put number hard coded it works fine

PriceStyle = ParamStyle("Chart Type", styleCandle, maskPrice);
LineStyle = ParamStyle("Line Style");
 
NDayHi = LastValue(HHV(H,N));// H[BarCount - 1 - N];
NDayLo = LastValue(llV(L,N)); //L[BarCount - 1 - N];

 
for(i = BarCount - 1 - N; i < BarCount - 1; i++)
{
if(H[i] > NDayHi)
{
NDayHi = H[i];
//XH = i;
}
if(L[i] < NDayLo)
{
NDayLo = L[i];
//XL = i;
}
}
 
 
 Filter = 1;
 
AddColumn(NDayHi,"High");
AddColumn(NDayLo,"Low");


 
// Define the Lines to be drawn
 
HLine = LineArray(BarCount - 1 - N, NDayHi, BarCount - 2, NDayHi);
LLine = LineArray(BarCount - 1 - N, NDayLo, BarCount - 2, NDayLo);
 
// Plot chart
 
_N(Title = StrFormat("{{NAME}} ({{INTERVAL}}) {{DATE}} {{OHLCX}} Vol=%1.0fn{{VALUES}}", V));
 
Plot(C, "", colorGrey50, PriceStyle);
Plot(Hline, WriteVal(N, 1.0) + " Day Hi", colorBrightGreen, LineStyle);
Plot(LLine, WriteVal(N, 1.0) + " Day Lo", colorYellow, LineStyle);
 
_SECTION_END();

N = getInnerOuterCandleLocation(lookBackDays); //daysback; // i am getting problem here if i put number hard coded it works fine

Source: Windows Questions C++

LEAVE A COMMENT