Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Pair Trading for Amibroker (AFL)
whoami
almost 10 years ago
Amibroker (AFL)

Rating:
3 / 5 (Votes 6)
Tags:
trading system, amibroker, resistance

Best Suitable for Pair Trading But you need confirm Signal Before Making trade.

Attached is modified Afl from some Source, But we need to fix more in it..

problem..

Signal are not Static.

I need to make them Static or fixed, anyone having time, please do changes.

Screenshots

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Colored Bollinger Bands");
Bg = ParamToggle(" Bollinger göster ","hide|show",0);
pr=Param( "Period",20,0,100,1);
P = ParamField("Price field",-1);
Style = ParamStyle("Style") | styleNoRescale | styleNoLabel |styleDashed;
 
if(Bg)
{
BBT=BBandTop(P,pr,2);
BBB=BBandBot(P,pr,2);
topcond = (Cross(BBT,C)OR C>BBT)AND Ref(C, -1)> BBT;
botcond = ( Cross(C,BBB))AND Ref(C, -1 < BBB);
bbtcolor = IIf( BBT> Ref (BBT, -1), colorDarkGreen,colorYellow );
bbbcolor = IIf( BBB > Ref (BBB, -1), colorDarkGreen,colorYellow );
PlotOHLC(O, H, L, C, "Data", colorWhite, styleBar | styleThick); 
Plot( BBT, "BBTop" + _PARAM_VALUES(), bbtcolor, styleLine|styleThick); 
Plot( BBB, "BBBot" + _PARAM_VALUES(), bbbcolor, styleLine|styleThick ); 
Buy=botcond;
Sell=topcond ;

}
_SECTION_END();
 
_SECTION_BEGIN("Hurst Cycle");

EnableScript("VBScript");

<%
function Gaussian_Elimination (GE_Order, GE_N, GE_SumXn, GE_SumYXn)
    Dim b(10, 10)
    Dim w(10)
    Dim Coeff(10)

    for i = 1 To 10
        Coeff(i) = 0
    next

    n = GE_Order + 1

    for i = 1 to n
        for j = 1 to  n
            if i = 1 AND j = 1 then
                b(i, j) = cDBL(GE_N)
            else
                b(i, j) = cDbl(GE_SumXn(i + j - 2))
            end if
        next      
        w(i) = cDbl(GE_SumYXn(i))
    next

    n1 = n - 1
    for i = 1 to n1
        big = cDbl(abs(b(i, i)))
        q = i
        i1 = i + 1

        for j = i1 to n
            ab = cDbl(abs(b(j, i)))
            if (ab >= big) then
                big = ab
                q = j
            end if
        next

        if (big <> 0.0) then
            if (q <> i) then
                for j = 1 to n
                    Temp = cDbl(b(q, j))
                    b(q, j) = b(i, j)
                    b(i, j) = Temp
                next
                Temp = w(i)
                w(i) = w(q)
                w(q) = Temp
            end if
        end if

        for j = i1 to n
            t = cDbl(b(j, i) / b(i, i))
            for k = i1 to n
                b(j, k) = b(j, k) - t * b(i, k)
            next         
            w(j) = w(j) - t * w(i)
        next      
    next

    if (b(n, n) <> 0.0) then

        Coeff(n) = w(n) / b(n, n)
        i = n - 1

        while i > 0
            SumY = cDbl(0)
            i1 = i + 1
            for j = i1 to n
                SumY = SumY + b(i, j) * Coeff(j)
            next
            Coeff(i) = (w(i) - SumY) / b(i, i)
            i = i - 1
        wend   

        Gaussian_Elimination = Coeff

    end if
end function
%>

// *********************************************************
// *
// * AFL Function for nth Order Polynomial Fit
// *     Calls Gaussian_Elimination ( VBS )
// *
// *     Y      = The array to Fit 
// *     BegBar = Beg Bar in range to fit
// *     EndBar = End Bar in range to fit
// *     Order  = 1 - 8 = Order of Poly Fit (Integer)
// *     ExtraB = Number of Bars to Extrapolate (Backward)
// *     ExtraF = Number of Bars to Extrapolate (Forward)
// *
// *********************************************************
 
function PolyFit(GE_Y, GE_BegBar, GE_EndBar, GE_Order, GE_ExtraB, GE_ExtraF)
{
    BI        = BarIndex();

    GE_N      = GE_EndBar - GE_BegBar + 1;
    GE_XBegin = -(GE_N - 1) / 2;
    GE_X      = IIf(BI < GE_BegBar, 0, IIf(BI > GE_EndBar, 0, (GE_XBegin + BI - GE_BegBar)));

    GE_X_Max  = LastValue(Highest(GE_X));

    GE_X      = GE_X / GE_X_Max;

    X1 = GE_X;
    AddColumn(X1, "X1", 1.9);

    GE_Y      = IIf(BI < GE_BegBar, 0, IIf(BI > GE_EndBar, 0, GE_Y));

    GE_SumXn  = Cum(0);
                                 GE_SumXn[1]   = LastValue(Cum(GE_X)); 
    GE_X2     = GE_X * GE_X;     GE_SumXn[2]   = LastValue(Cum(GE_X2));
    GE_X3     = GE_X * GE_X2;    GE_SumXn[3]   = LastValue(Cum(GE_X3)); 
    GE_X4     = GE_X * GE_X3;    GE_SumXn[4]   = LastValue(Cum(GE_X4)); 
    GE_X5     = GE_X * GE_X4;    GE_SumXn[5]   = LastValue(Cum(GE_X5)); 
    GE_X6     = GE_X * GE_X5;    GE_SumXn[6]   = LastValue(Cum(GE_X6)); 
    GE_X7     = GE_X * GE_X6;    GE_SumXn[7]   = LastValue(Cum(GE_X7)); 
    GE_X8     = GE_X * GE_X7;    GE_SumXn[8]   = LastValue(Cum(GE_X8)); 
    GE_X9     = GE_X * GE_X8;    GE_SumXn[9]   = LastValue(Cum(GE_X9)); 
    GE_X10    = GE_X * GE_X9;    GE_SumXn[10]  = LastValue(Cum(GE_X10)); 
    GE_X11    = GE_X * GE_X10;   GE_SumXn[11]  = LastValue(Cum(GE_X11)); 
    GE_X12    = GE_X * GE_X11;   GE_SumXn[12]  = LastValue(Cum(GE_X12)); 
    GE_X13    = GE_X * GE_X12;   GE_SumXn[13]  = LastValue(Cum(GE_X13)); 
    GE_X14    = GE_X * GE_X13;   GE_SumXn[14]  = LastValue(Cum(GE_X14)); 
    GE_X15    = GE_X * GE_X14;   GE_SumXn[15]  = LastValue(Cum(GE_X15)); 
    GE_X16    = GE_X * GE_X15;   GE_SumXn[16]  = LastValue(Cum(GE_X16)); 

    GE_SumYXn = Cum(0);
                                 GE_SumYXn[1]  = LastValue(Cum(GE_Y));
    GE_YX     = GE_Y    * GE_X;  GE_SumYXn[2]  = LastValue(Cum(GE_YX));
    GE_YX2    = GE_YX   * GE_X;  GE_SumYXn[3]  = LastValue(Cum(GE_YX2)); 
    GE_YX3    = GE_YX2  * GE_X;  GE_SumYXn[4]  = LastValue(Cum(GE_YX3));
    GE_YX4    = GE_YX3  * GE_X;  GE_SumYXn[5]  = LastValue(Cum(GE_YX4));
    GE_YX5    = GE_YX4  * GE_X;  GE_SumYXn[6]  = LastValue(Cum(GE_YX5));
    GE_YX6    = GE_YX5  * GE_X;  GE_SumYXn[7]  = LastValue(Cum(GE_YX6));
    GE_YX7    = GE_YX6  * GE_X;  GE_SumYXn[8]  = LastValue(Cum(GE_YX7));
    GE_YX8    = GE_YX7  * GE_X;  GE_SumYXn[9]  = LastValue(Cum(GE_YX8));

    GE_Coeff  = Cum(0);

    GE_VBS    = GetScriptObject();
    GE_Coeff  = GE_VBS.Gaussian_Elimination(GE_Order, GE_N, GE_SumXn, GE_SumYXn);

    for (i = 1; i <= GE_Order + 1; i++)
        printf(NumToStr(i, 1.0) + " = " + NumToStr(GE_Coeff[i], 1.9) + "\n");

    GE_X   = IIf(BI < GE_BegBar - GE_ExtraB - GE_ExtraF, 0, IIf(BI > GE_EndBar, 0, (GE_XBegin + BI - GE_BegBar + GE_ExtraF) / GE_X_Max));

    GE_X2  = GE_X   * GE_X; GE_X3  = GE_X2  * GE_X; GE_X4  = GE_X3  * GE_X; GE_X5  = GE_X4  * GE_X; GE_X6  = GE_X5  * GE_X;
    GE_X7  = GE_X6  * GE_X; GE_X8  = GE_X7  * GE_X; GE_X9  = GE_X8  * GE_X; GE_X10 = GE_X9  * GE_X; GE_X11 = GE_X10 * GE_X; 
    GE_X12 = GE_X11 * GE_X; GE_X13 = GE_X12 * GE_X; GE_X14 = GE_X13 * GE_X; GE_X15 = GE_X14 * GE_X; GE_X16 = GE_X15 * GE_X; 

    GE_Yn = IIf(BI < GE_BegBar - GE_ExtraB - GE_ExtraF, -1e10, IIf(BI > GE_EndBar, -1e10, 
            GE_Coeff[1]  + 
            GE_Coeff[2]  * GE_X   + GE_Coeff[3]  * GE_X2  + GE_Coeff[4]  * GE_X3  + GE_Coeff[5]  * GE_X4  + GE_Coeff[6]  * GE_X5  +
            GE_Coeff[7]  * GE_X6  + GE_Coeff[8]  * GE_X7  + GE_Coeff[9]  * GE_X8));

    return GE_Yn;
}

p1 = Param("CMA Period 1", 13, 0, 999, 1);
p2 = Param("CMA Period 2", 25, 0, 999, 1);
p3 = Param("CMA Period 3", 50, 0, 999, 1);
p4 = Param("CMA Period 4", 100, 0, 999, 1);
p5 = Param("CMA Period 5", 200, 0, 999, 1);
p6 = Param("CMA Period 6", 600, 0, 999, 1);
BType = ParamList("Band Type", "Percent|Amount");
Pct1 = Param("Pct or Amt 1", 1.6, 0, 33, 0.05);
Pct2 = Param("Pct or Amt 2", 2.4, 0, 33, 0.05);
Pct3 = Param("Pct or Amt 3", 3.6, 0, 33, 0.05);
Pct4 = Param("Pct or Amt 4", 5.4, 0, 33, 0.05);
Pct5 = Param("Pct or Amt 5", 8.1, 0, 33, 0.05);
Pct6 = Param("Pct or Amt 6",12.0, 0, 33, 0.05);
ePFac = Param("Extrapolation Period Factor", 0.35, 0.10, 5.00, 0.05);
ePOrd = Param("Extrapolation PolyFit Order", 2, 1, 8, 1);
eAuto = Param("Extrapolation Auto Fixup Passes", 5, 0, 9, 1); 
eLFac = Param("Extrapolation AF Lag Factor", 0.33, 0, 1, 0.01);
eFFac = Param("Extrapolation AF Factor", 0.25, 0, 1, 0.01);
eFLen = Param("Extrapolation Future Length", 0, 0, 10, 1);
HT = ParamToggle("Hurst Cycle Göstermek ","hide|show",0);
BI = BarIndex();
SVBI = SelectedValue(BI);
LVBI = LastValue(BI);
Data = (H + L) / 2;
Title = EncodeColor(colorWhite) + " Hurst / Millard DE " +
EncodeColor(colorDefault) + " - BI = " + NumToStr(BI, 1.0) + " - CMA Periods =
";
 
 
GraphXSpace = 5;
 
 
 
function CMA_DE(Period, Percent, Red, Green, Blue)
{
Pm = int(Period * 2 / 3);
if (Pm % 2 == 0)
Pm = Pm + 1;
Pn = Period - Pm;
if (Pn < 3) 
Pn = 3;
if (Pm <= Pn)
Pm = Pn + 2;
if (Pn % 2 == 0)
Pn = Pn + 1;
if (SVBI - (Pm + Pn) * (1 + eLFac + 0.02) > 0)
{
Lag = (Pm - 1) / 2 + (Pn - 1) / 2;
ExtraF = Lag + eFLen;
CMA = Ref(MA(MA(Data, Pm), Pn), Lag);
EndBar = SVBI - Lag;
BegBar = EndBar - round(Period * ePFac) + 1;
if (EndBar - BegBar < 2)
BegBar = EndBar - 2;
CMA = IIf(BI <= SVBI - Lag, CMA, -1e10);
if (BType == "Amount")
{
UBIS = CMA + Percent;
LBIS = CMA - Percent;
}
else
if (BType == "Percent")
{
UBIS = CMA * (1 + Percent / 100);
LBIS = CMA * (1 - Percent / 100);
}
Plot(UBIS, "", ColorRGB(Red, Green, Blue), styleThick);
Plot(LBIS, "", ColorRGB(Red, Green, Blue), styleThick);
if (Red > 0) Red = 254;
if (Green > 0) Green = 254;
if (Blue > 0) Blue = 254;
CMAx = PolyFit(CMA, BegBar, EndBar, ePOrd, 0, ExtraF);
CMAx = IIf(BI >= SVBI - Lag - ExtraF, CMAx, -1e10);
if (BType == "Amount")
{
CMAx = CMAx + CMA[SVBI - Lag] - CMAx[SVBI - Lag - ExtraF];
UBOS = CMAx + Percent; 
LBOS = CMAx - Percent;
}
else
{
CMAx = CMAx * CMA[SVBI - Lag] / CMAx[SVBI - Lag - ExtraF];
UBOS = CMAx * (1 + Percent / 100); 
LBOS = CMAx * (1 - Percent / 100); 
}
k = 0;
for (j = 1; j <= eAuto; j++)
{ 
k = j;
AdjBar = 0;
for (i = SVBI - ExtraF; i >= SVBI - ExtraF - Lag * eLFac; i--)
{ 
if (i + ExtraF <= LVBI) 
{ 
if (UBOS[i] < (H[i + ExtraF] + L[i + ExtraF]) / 2)
{ 
AdjBar = i + ExtraF;
Target = CMAx[i] + (C[i + ExtraF] - CMAx[i]) * eFFac;
} 
if (LBOS[i] > (H[i + ExtraF] + L[i + ExtraF]) / 2)
{ 
AdjBar = i + ExtraF;
Target = CMAx[i] - (CMAx[i] - C[i + ExtraF]) * eFFac;
} 
if (AdjBar > 0)
i = 0;
} 
}
if (AdjBar > 0)
{
ExtraB = AdjBar - EndBar;
ExtraF = ExtraF - ExtraB;
EndBar = EndBar + ExtraB;
StepSize = (Target - CMA[SVBI - Lag]) / (EndBar - (SVBI -
Lag));
CMA = IIf(BI <= SVBI - Lag, CMA, 0);
for (i = SVBI - Lag + 1; i <= EndBar; i++)
{
CMA[i] = CMA[i - 1] + StepSize;
}
CMAx = PolyFit(CMA, BegBar, EndBar, ePOrd, 0, ExtraF);
CMAx = IIf(BI >= SVBI - Lag - ExtraF, CMAx, -1e10);
if (BType == "Amount")
{
CMAx = CMAx + CMA[SVBI - Lag] - CMAx[SVBI - Lag - ExtraF];
UBOS = CMAx + Percent; 
LBOS = CMAx - Percent;
}
else
{
CMAx = CMAx * CMA[SVBI - Lag] / CMAx[SVBI - Lag - ExtraF];
UBOS = CMAx * (1 + Percent / 100); 
LBOS = CMAx * (1 - Percent / 100); 
}
}
else
j = 999;
}
k = k - 1;
Plot(UBOS, "", ColorRGB(Red, Green, Blue), styleThick, Null, Null,
ExtraF);
Plot(LBOS, "", ColorRGB(Red, Green, Blue), styleThick, Null, Null,
ExtraF);
Title = Title + EncodeColor(ColorRGB(Red, Green, Blue)) +
NumToStr(Period, 1.0) + " (" + NumToStr(Pm, 1.0) + "/" + NumToStr(Pn, 1.0) + ")
" + NumToStr(k, 1.0) + " ";
PlotShapes((BI == SVBI - Lag) * shapeSmallUpTriangle, ColorRGB(Red,
Green, Blue), 0, CMA * (1 - Percent / 100), -15); 
PlotShapes((BI == SVBI - Lag) * shapeSmallDownTriangle, ColorRGB(Red,
Green, Blue), 0, CMA * (1 + Percent / 100), -15); 
} 
return;
}
if(HT)
{
PlotOHLC(O, H, L, C, "Data", colorWhite, styleBar | styleThick); 
if (p1 > 0)
CMA_DE(p1, Pct1, 000, 160, 000);
if (p2 > 0)
CMA_DE(p2, Pct2, 160, 112, 000);
if (p3 > 0)
CMA_DE(p3, Pct3, 160, 000, 000);
if (p4 > 0)
CMA_DE(p4, Pct4, 160, 000, 160);
if (p5 > 0)
CMA_DE(p5, Pct5, 000, 000, 160);
if (p6 > 0)
CMA_DE(p6, Pct6, 0, 160, 160);
}
_SECTION_END();
_SECTION_BEGIN(" DESTEK DI.RENÇ");
DDG = ParamToggle("Destek Direnç Göstermek ","hide|show",1);
chartflag = ParamToggle("Heikin Ashi","show|hide",0);
xx = Cum(1);
nbar = Param("nbar",5,2,50,1); 
if(DDG)
{
PHigh = H > Ref(HHV(H,nbar),-1) AND Ref(HHV(H,nbar),nbar) <= H;
PHighPrice = ValueWhen(PHigh,H);
PLow = L < Ref(LLV(L,nbar),-1) AND Ref(LLV(L,nbar),nbar) >= L;
PLowPrice = ValueWhen(PLow,L); 
startval_L = ValueWhen(PLow,L,1); 
endval_L = ValueWhen(PLow,L,0); 
startbar_L = ValueWhen(PLow,xx,1); 
endbar_L = ValueWhen(PLow,xx,0); 
aa_L = (endval_L-startval_L)/(endbar_L-startbar_L);
bb_L = startval_L;
trendline_L = aa_L * (xx - startbar_L) + bb_L;
dtrendline_L = trendline_L - Ref(trendline_L,-1);
startval_L_extend = ValueWhen(PLow,L,2); 
endval_L_extend = ValueWhen(PLow,L,1); 
startbar_L_extend = ValueWhen(PLow,xx,2); 
endbar_L_extend = ValueWhen(PLow,xx,1); 
aa_L_extend = (endval_L_extend-startval_L_extend)/(endbar_L_extend-startbar_L_extend);
bb_L_extend = startval_L;
trendline_L_extend = aa_L_extend * (xx - startbar_L) + endval_L_extend; 
dtrendline_L_extend = trendline_L_extend - Ref(trendline_L_extend,-1);
dtrendline_L_extend = IIf(PLow,Ref(dtrendline_L,-1),dtrendline_L_extend);
startval_L_extend2 = ValueWhen(PLow,L,3); 
endval_L_extend2 = ValueWhen(PLow,L,2); 
startbar_L_extend2 = ValueWhen(PLow,xx,3); 
endbar_L_extend2 = ValueWhen(PLow,xx,2); 
aa_L_extend2 = (endval_L_extend2-startval_L_extend2)/(endbar_L_extend2-startbar_L_extend2);
bb_L_extend2 = endval_L_extend2;
trendline_L_extend2 = aa_L_extend2 * (xx - endbar_L_extend2) + endval_L_extend2; 
dtrendline_L_extend2 = trendline_L_extend2 - Ref(trendline_L_extend2,-1);
dtrendline_L_extend2 = IIf(PLow,Ref(dtrendline_L_extend,-1),dtrendline_L_extend2);
startval_H = ValueWhen(PHigh,H,1); 
endval_H = ValueWhen(PHigh,H,0); 
startbar_H = ValueWhen(PHigh,xx,1); 
endbar_H = ValueWhen(PHigh,xx,0); 
aa_H = (endval_H-startval_H)/(endbar_H-startbar_H);
bb_H = startval_H;
trendline_H = aa_H * (xx - startbar_H) + bb_H; 
dtrendline_H = trendline_H - Ref(trendline_H,-1);
startval_H_extend = ValueWhen(PHigh,H,2); 
endval_H_extend = ValueWhen(PHigh,H,1); 
startbar_H_extend = ValueWhen(PHigh,xx,2); 
endbar_H_extend = ValueWhen(PHigh,xx,1); 
aa_H_extend = (endval_H_extend-startval_H_extend)/(endbar_H_extend-startbar_H_extend);
bb_H_extend = startval_H;
trendline_H_extend = aa_H_extend * (xx - startbar_H) + endval_H_extend; 
dtrendline_H_extend = trendline_H_extend - Ref(trendline_H_extend,-1);
dtrendline_H_extend = IIf(PHigh,Ref(dtrendline_H,-1),dtrendline_H_extend);
startval_H_extend2 = ValueWhen(PHigh,H,3); 
endval_H_extend2 = ValueWhen(PHigh,H,2); 
startbar_H_extend2 = ValueWhen(PHigh,xx,3); 
endbar_H_extend2 = ValueWhen(PHigh,xx,2); 
aa_H_extend2 = (endval_H_extend2-startval_H_extend2)/(endbar_H_extend2-startbar_H_extend2);
bb_H_extend2 = endval_H_extend2;
trendline_H_extend2 = aa_H_extend2 * (xx - endbar_H_extend2) + endval_H_extend2; 
dtrendline_H_extend2 = trendline_H_extend2 - Ref(trendline_H_extend2,-1);
dtrendline_H_extend2 = IIf(PHigh,Ref(dtrendline_H_extend,-1),dtrendline_H_extend2);
tld = ParamToggle("All trendlines","show|hide",1);
if (tld)
{

trendline_L = IIf(dtrendline_L > 0,trendline_L,Null);
trendline_L_extend = IIf(dtrendline_L_extend > 0,trendline_L_extend,Null);
trendline_L_extend2 = IIf(dtrendline_L_extend2 > 0,trendline_L_extend2,Null);
trendline_H = IIf(dtrendline_H < 0,trendline_H,Null);
trendline_H_extend = IIf(dtrendline_H_extend < 0,trendline_H_extend,Null);
trendline_H_extend2 = IIf(dtrendline_H_extend2 < 0,trendline_H_extend2,Null);
}
trendline_L_extend2 = IIf(BarsSince(Plow) <= nbar,trendline_L_extend2,Null);
trendline_H_extend2 = IIf(BarsSince(PHigh) <= nbar,trendline_H_extend2,Null);
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
if (chartFlag)
{
PlotOHLC(O, H, L, C, "Data", colorWhite, styleBar | styleThick); 
} 
else
{
HaClose = (O+H+L+C)/4; 
HaOpen = AMA( Ref( HaClose, -1 ), 0.5 ); 
HaHigh = Max( H, Max( HaClose, HaOpen ) ); 
HaLow = Min( L, Min( HaClose, HaOpen ) ); 
PlotOHLC( HaOpen, HaHigh, HaLow, HaClose, "Modified " + Name(), colorWhite, styleBar); 
}
PlotShapes(shapeUpArrow*PLow,colorGreen,0,L,-20);
PlotShapes(shapeDownArrow*PHigh,colorRed,0,H,-20);
 
Plot(trendline_L, "", colorLime,styleLine|styleThick);
Plot(IIf(BarsSince(Plow) <= nbar,trendline_L_extend,Null), "", colorLightGrey, styleLine | styleThick);
Plot(IIf(BarsSince(Plow) > nbar,trendline_L_extend,Null), "",colorBrightGreen, styleLine | styleThick);
Plot(IIf(BarsSince(Plow) <= nbar,trendline_L_extend2,Null), "",colorDarkGreen, styleLine| styleThick);
Plot(trendline_H, "", colorRed,styleLine|styleThick);
Plot(IIf(BarsSince(PHigh) <= nbar,trendline_H_extend,Null), "", colorLightGrey, styleLine | styleThick);
Plot(IIf(BarsSince(PHigh) > nbar,trendline_H_extend,Null), "",colorOrange, styleLine | styleThick);
Plot(IIf(BarsSince(PHigh) <= nbar,trendline_H_extend2,Null), "",colorOrange, styleLine | styleThick);
 
signalFlag = ParamToggle("Possible Signals","show|hide",1);
if (signalFlag)
{
Buy = (!IsEmpty(trendline_H_extend) AND Cross(C,trendline_H_extend) AND BarsSince(PHigh) > nbar) OR 
(!IsEmpty(trendline_H_extend2) AND Cross(C,trendline_H_extend2) AND !PHigh) OR
(PHigh AND C > trendline_H_extend2 AND Ref(C,-1) < Ref(trendline_H_extend,-1) AND !IsEmpty(trendline_H_extend) AND !IsEmpty(trendline_H_extend2) );
BuyPrice = C;
Short = (!IsEmpty(trendline_L_extend) AND Cross(trendline_L_extend,C) AND BarsSince(PLow) > nbar) OR 
(!IsEmpty(trendline_L_extend2) AND Cross(trendline_L_extend2,C) AND !PLow) OR
(PLow AND C < trendline_L_extend2 AND Ref(C,-1) > Ref(trendline_L_extend,-1) AND !IsEmpty(trendline_L_extend) AND !IsEmpty(trendline_L_extend2)); 
ShortPrice = C;
Sell = 0;
Cover = 0;
 
}
_SECTION_END();
_SECTION_BEGIN(" EXPLORE");
AL=(!IsEmpty(trendline_H_extend) AND Cross(C,trendline_H_extend) AND BarsSince(PHigh) > nbar) OR 
(!IsEmpty(trendline_H_extend2) AND Cross(C,trendline_H_extend2) AND !PHigh) OR
(PHigh AND C > trendline_H_extend2 AND Ref(C,-1) < Ref(trendline_H_extend,-1) AND !IsEmpty(trendline_H_extend) AND !IsEmpty(trendline_H_extend2) );
BuyPrice = C;
SAT=(!IsEmpty(trendline_L_extend) AND Cross(trendline_L_extend,C) AND BarsSince(PLow) > nbar) OR 
(!IsEmpty(trendline_L_extend2) AND Cross(trendline_L_extend2,C) AND !PLow) OR
(PLow AND C < trendline_L_extend2 AND Ref(C,-1) > Ref(trendline_L_extend,-1) AND !IsEmpty(trendline_L_extend) AND !IsEmpty(trendline_L_extend2)); 
ShortPrice = C;
AL_status=WriteIf(AL,"Al?s, Yap"," ");
SAT_status=WriteIf(SAT,"Sat?s, Yap"," ");
AL_col=IIf(AL, colorDarkGreen , colorWhite);
SAT_col=IIf(SAT, colorRed,colorWhite);
 
Filter= AL OR SAT;
AddColumn(C, "KAPANIS,", 1.2, IIf(C > Ref(C,-1),colorBlue, colorRed));
AddTextColumn(AL_status, "ALIS,", 1.2, colorWhite, Al_col);
AddTextColumn(SAT_status, "SATIS,", 1.2, colorWhite, SAT_col);
}
_SECTION_END();
_SECTION_BEGIN("Parabolic Sar");
acc=Param("Acceleration factor",0.02,0.01,0.05,0.01);
af_start=Param("Starting AF value",0.02,0.01,0.05,0.01);
af_max=Param("Maximum AF value",0.2,0.1,0.3,0.01);
Ct=Param("Crossover threshold in %",1,0,3,0.5);
PS = ParamToggle(" Parabolic Sar Göstermek ","hide|show",0);
Ct1=Ct/100;
IAF = acc; 
MaxAF = af_max;
psar = Close; 
long = 1;
af = af_start;
ep = Low[ 0 ];
hp = High [ 0 ];
lp = Low [ 0 ];
for( i = 2; i < BarCount; i++ )
{
if ( long )
{
psar [ i ] = psar [ i-1 ] + af * ( hp - psar [ i-1 ] );
}
else
{
psar [ i ] = psar [ i-1 ] + af * ( lp - psar [ i-1 ] );
}
reverse = 0;
if ( long )
{
if ( Low [ i ] < psar [ i ] * (1-Ct1) )
{
long = 0; reverse = 1;
psar [ i ] = hp;
lp = Low [ i ];
af = af_start;
}
}
else
{
if ( High [ i ] > psar [ i ] * (1+Ct1) )
{
long = 1; reverse = 1; 
psar [ i ] = lp;
hp = High [ i ];
af = af_start;
}
}
if ( reverse == 0 )
{
if ( long )
{
if ( High [ i ] > hp ) 
{
hp = High [ i ]; 
af = af + IAF; 
if( af > MaxAF ) af = MaxAF; 
}

if( Low[ i - 1 ] < psar[ i ] ) psar[ i ] = Low[ i - 1 ];
if( Low[ i - 2 ] < psar[ i ] ) psar[ i ] = Low[ i - 2 ];
}
else
{
if ( Low [ i ] < lp ) 
{ 
lp = Low [ i ]; 
af = af + IAF; 
if( af > MaxAF ) af = MaxAF; 
} 

if( High[ i - 1 ] > psar[ i ] ) psar[ i ] = High[ i - 1 ];
if( High[ i - 2 ] > psar[ i ] ) psar[ i ] = High[ i - 2 ];
}
}
}
if(PS)
{
Plot( psar, _DEFAULT_NAME(), ParamColor( "Color", colorYellow), styleDots | styleNoLine | styleThick ); 
PlotOHLC(O, H, L, C, "Data", colorWhite, styleBar | styleThick); 
}
_SECTION_END(); 

4 comments

1. uvrajwell

How do we enter 2 different scripts to pair in this AFL? Please help.

2. amol6985

Thank You…

3. whoami

please check below link about pair trading & understand.

http://en.wikipedia.org/wiki/Pairs_trade

its not meant for pairing two Scripts..

4. XUseMan

Thank you…

Leave Comment

Please login here to leave a comment.

Back