当我前几天硬编码扫描它时需要 Amibroker AFL 代码的帮助它工作正常但是当我通过函数获取它时它给出错误的结果
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
我正在尝试获取 N 天的最高价和最低价,其中 N 是 InnerCandle 形成的天数。
从那天到今天 High Low.
当我将 Days 硬编码时代码工作正常,但是当我通过函数获取它时,它 returns 所有柱高低。
下面是高低到 innerCandle 的代码
_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);
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;
}
lookBackDays = Param("Look Back", 10, 1, 60, 1);
// 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.0f\n{{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; //
如果我将数字硬编码,它就可以正常工作
对我来说有点太多了,但也许这会对你有所帮助。
您可以使用 Amibrokers Inside() 函数轻松找到内部柱线的位置,该函数 returns 当柱线是内部柱线时布尔数组为真,否则为假。
IsBarInside = Inside(); // Array. True/1 if the bar is an inside bar.
IsNextBarInside = Ref(IsBarInside, 1); // Shift the array by +1 so that the next bar is aligned.
IsLastBarInside = Ref(IsBarInside, -1); // Shift the array by -1 so that we are looking at the last bars value.
PlotShapes(IIf(IsLastBarInside, shapeSquare, shapeNone), colorWhite, 0, H, Offset=55);
PlotShapes(IIf(IsNextBarInside, shapeHollowCircle, shapeNone), colorRed, 0, H, Offset=55);
我正在尝试获取 N 天的最高价和最低价,其中 N 是 InnerCandle 形成的天数。 从那天到今天 High Low.
当我将 Days 硬编码时代码工作正常,但是当我通过函数获取它时,它 returns 所有柱高低。
下面是高低到 innerCandle 的代码
_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);
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;
}
lookBackDays = Param("Look Back", 10, 1, 60, 1);
// 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.0f\n{{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; //
如果我将数字硬编码,它就可以正常工作
对我来说有点太多了,但也许这会对你有所帮助。
您可以使用 Amibrokers Inside() 函数轻松找到内部柱线的位置,该函数 returns 当柱线是内部柱线时布尔数组为真,否则为假。
IsBarInside = Inside(); // Array. True/1 if the bar is an inside bar.
IsNextBarInside = Ref(IsBarInside, 1); // Shift the array by +1 so that the next bar is aligned.
IsLastBarInside = Ref(IsBarInside, -1); // Shift the array by -1 so that we are looking at the last bars value.
PlotShapes(IIf(IsLastBarInside, shapeSquare, shapeNone), colorWhite, 0, H, Offset=55);
PlotShapes(IIf(IsNextBarInside, shapeHollowCircle, shapeNone), colorRed, 0, H, Offset=55);