Thank you for your response.
In essence, you are saying that I cannot use Tsokakis example
(and many others from the Amibroker and Metastock libraries)
without a significant rewriting.

I am new to Amibroker. I was looking for a good trendline recognition script 
and stumbled on Amibroker. So, I downloaded a trial version to quickly test 
these scripts.

So, I need to decide whether it is worse the effort to rewrite these scripts 
for Amibroker or go back to Wealth-Lab, which I was using before.

I am surprised that PeakBars and TroughBars are looking into the future in 
Amibroker.
It is not the case in WL. These are pretty simple functions - they just need to 
find min or max before a reversal.
Why would Amibroker look into the future in this case?

Now about replacing SelectedValue/LastValue.

I tried to fix "Historical Trendlines and Breakouts" script
by wrapping part of the script in for(i = 0; i < BarCount; i++) loop and then 
replacing:

...
pS = TroughBars( s1, per, 1 ) == 0;
endt=SelectedValue(ValueWhen( pS, x ,1));
startt=SelectedValue(ValueWhen( pS, x ,2));
dtS =endt-startt;
endS = SelectedValue((ValueWhen( pS, s1,1) ));
startS = SelectedValue(( ValueWhen( pS, s1 ,2)));
aS = (endS-startS)/dtS;bS = endS;
trendlineS = aS * ( x -endt ) + bS;//SUPPORT LINE
...
Plot(IIf(x>=first -d AND x<=Last+d,trendlineS,- 
1e10),"Support",colorBrightGreen,1);

by

pS = TroughBars( s1, per, 1 ) == 0;
troughBarIdxLast         = ValueWhen( pS, x ,1);
troughBarIdxBeforeLast   = ValueWhen( pS, x ,2);
troughBarValueLast       = ValueWhen( pS, s1, 1);
troughBarValueBeforeLast = ValueWhen( pS, s1, 2);
...
for(i = startBar; i < lastBar; i++)
{
    endt= troughBarIdxLast[i];
    startt = troughBarIdxBeforeLast[i];
    if(prevEndTrendlineS != endt)
    {
        prevEndTrendlineS = endt;

        dtS = endt - startt;

        endS = troughBarValueLast[i];
        startS = troughBarValueBeforeLast[i];
        aS = (endS - startS) / dtS;
        bS = endS;

        trendlineS = aS * ( x - endt ) + bS;//SUPPORT LINE 
        Plot(IIf(x >= startt - d AND x <= endt + d, trendlineS, -1e10), 
"Support", colorBrightGreen, 1);
    }
...
}

Is it the right approach to rewriting SelectedValue or LastValue scripts for a 
continuous drawing or backtesting?
(Below is the entire rewritten script).

Thank you
John

x = Cum(1);
per = 3;// CALIBRATE THE ZIG() SENSITIVITY
s1=L;
s11=H;

pS = TroughBars( s1, per, 1 ) == 0;
troughBarIdxLast         = ValueWhen( pS, x ,1);
troughBarIdxBeforeLast   = ValueWhen( pS, x ,2);
troughBarValueLast       = ValueWhen( pS, s1, 1);
troughBarValueBeforeLast = ValueWhen( pS, s1, 2);

pR = PeakBars( s11, per, 1 ) == 0;
peakBarIdxLast           = ValueWhen( pR, x, 1);
peakBarIdxBeforeLast     = ValueWhen( pR, x, 2);
peakBarValueLast         = ValueWhen( pR, s11, 1);
peakBarValueBeforeLast   = ValueWhen( pR, s11, 2);

startBar = Status("FirstVisibleBar"); 
lastBar = Status("LastVisibleBar");

_TRACE("Startbar:"+startBar);
_TRACE("Lastbar:"+lastBar);

prevEndTrendlineS = -1;
prevEndTrendlineR = -1;

d=10;// INCREASE d TO EXTEND THE LINES

Years=Year();
Months=Month();
Days=Day();

//color = 
for(i = startBar; i < lastBar; i++)
{
    color[i] = colorBlack;
}

for(i = startBar; i < lastBar; i++)
{
    endt= troughBarIdxLast[i];
    startt = troughBarIdxBeforeLast[i];
    if(prevEndTrendlineS != endt)
    {
        prevEndTrendlineS = endt;
        dtS = endt - startt;
        endS = troughBarValueLast[i];
        startS = troughBarValueBeforeLast[i];
        aS = (endS - startS) / dtS;
        bS = endS;

        trendlineS = aS * ( x - endt ) + bS;//SUPPORT LINE 
        bearishbreakout = x > endt AND x < endt + d AND Cross(trendlineS, C);
        color = IIf (bearishbreakout,colorRed,color);
        Plot(IIf(x >= startt - d AND x <= endt + d, trendlineS, -1e10), 
"Support", colorBrightGreen, 1);
    }

    endt1 = peakBarIdxLast[i];
    startt1 = peakBarIdxBeforeLast[i];
    if(prevEndTrendlineR != endt1)
    {
        prevEndTrendlineR = endt1;
        dtR =endt1-startt1;
        endR = peakBarValueLast[i];
        startR = peakBarValueBeforeLast[i];
        aR = (endR-startR)/dtR;
        bR = endR;

        trendlineR = aR * ( x -endt1 ) + bR;//RESISTANCE LINE
        bullishbreakout = x > endt1 AND x < endt1 + d AND Cross(C,trendlineR);
        color = IIf (bullishbreakout,colorGreen,color);
        Plot(IIf(x >= startt1 - d AND x <= endt1 + d, trendlineR, -1e10), 
"Resistance", colorRed, 1);
    }
}// for(i = startBar; i < lastBar; i++)
Plot(C,"Close",color,64);


Reply via email to