Plotting Fibonnacci Lines automatically(TS2000i)

Discussion in 'Strategy Building' started by Jana, Jan 18, 2003.

  1. Jana

    Jana

    Hi,
    i`m looking for the ELA to plot the fibo-lines automatically.
    e.g. of the high/low of the last 60 minutes.
    I have only the formular to plot it, if you input every time the high/low. Can someone modify it?
    Thanks

    Fibtool
    input: PvtsID("ab"), Fib1(1), Fib2(.382), Fib3(.50), Fib4(.618), Fib5(.787), Fib6(0), BaseColor(999);

    { Note: if Fibx <> 999, then show the line; if BaseColr = 999 then set the FibColors below }

    var: ShoPrice(true), { Show the calculated Fib price }
    ShoDiag(true), { Show the Diagonal line }
    tlsize(0), { Width of the Fib lines }
    extend(true); { Extend Fib lines to the right }

    { Note: JGW - 12/26/02 - I used Clyde Lee's ellipse code (which ironically was
    based on my Andrews Pitchfork), and coerced it to draw Fib lines instead of
    ellipses. Removed some obvious vestigial code, but didn't pretty it up.}

    var: fib(0), FirstTime(true); { JGW }
    Array: Fibs[10](999), FibColors[10](cyan); { JGW }

    var: date1(0),time1(0),price1(0),date2(0),time2(0),price2(0);
    var: ii(0), ok2draw(true);
    var: handl(0), ss("");
    var: han(0),IPass(0);
    var: AryCount(0);

    Arrays: DateAry[10000](0), TimeAry[10000](0);
    Arrays: Dates[26](0), Times[26](0), Chars[26](""), Comp[26](2);
    Arrays: PriceC[26](0), PriceH[26](0), PriceL[26](0), Abars[26](0);
    Vars: CharKnt(0);


    AryCount=AryCount+1;
    DateAry[AryCount]=Date;
    TimeAry[AryCount]=Time;
    If AryCount>9999 then begin
    ok2draw = false;
    AryCount=9999;
    End;

    if currentbar = 1 then begin
    {find out how many we are looking for}
    CharKnt=strlen(PvtsID);
    For Value1=1 to CharKnt begin
    Chars[Value1]=UpperStr(midstr(PvtsID,Value1,1));
    End;
    handl = text_getfirst(2);
    Value9=0;
    while handl >= 0 begin
    ss = text_getstring(handl);
    ss = UpperStr(ss);
    For Value1=1 to CharKnt begin
    if LeftStr(ss,1) = Chars[Value1] then begin
    Dates[Value1] = text_getdate(handl);
    Times[Value1] = text_gettime(handl);
    PriceC[Value1]= Text_GetValue(handl);
    If strlen(ss)>1
    then Comp[Value1]=StrToNum(MidStr(ss,2,Strlen(ss)-1))
    else Comp[Value1]=1;
    end;
    end;
    Value9=Value9+1;
    handl = text_getnext(handl,2); { IMPORTANT -- infinite loop if this is missing! }
    end;
    {Check to see we have them all and good dates/times}
    For Value1=1 to CharKnt-1 begin
    For Value2=Value1+1 to CharKnt begin
    If Dates[Value2] and Times[Value2] Value3=Dates[Value2];Dates[Value2]=Dates[Value1];Dates[Value1]=value3;
    Value3=Times[Value2];Times[Value2]=Times[Value1];Times[Value1]=value3;
    Value3=PriceC[Value2];PriceC[Value2]=PriceC[Value1];PriceC[Value1]=value3;
    End;
    End;
    end;
    Value3=0;
    For Value1=1 to CharKnt-1 begin
    If Date[Value1]=0 or Time[Value1]=0 then Value3=Value3+1;
    End;
    If Value3<>0 then begin
    CharKnt=CharKnt-Value3;
    For Value1=1 to CharKnt begin
    Dates[Value1]=Dates[Value1+Value3];
    Times[Value1]=Times[Value1+Value3];
    PriceC[Value1]=PriceC[Value1+Value3];
    End;
    End;
    {Have Stuff in arrays and sorted by D+T -- Now Scan dates for bars/price}

    { JGW }
    Fibs[1] = Fib1;
    Fibs[2] = Fib2;
    Fibs[3] = Fib3;
    Fibs[4] = Fib4;
    Fibs[5] = Fib5;
    Fibs[6] = Fib6;
    if BaseColor = 999 then begin
    FibColors[1] = cyan;
    FibColors[2] = green;
    FibColors[3] = white;
    FibColors[4] = red;
    FibColors[5] = green;
    FibColors[6] = cyan;
    end else begin
    FibColors[1] = BaseColor;
    FibColors[2] = BaseColor;
    FibColors[3] = BaseColor;
    FibColors[4] = BaseColor;
    FibColors[5] = BaseColor;
    FibColors[6] = BaseColor;
    end;
    end;


    If IPass if date = dates[Ipass+1] and time = times[Ipass+1] then begin
    IPass=IPass+1;
    PriceH[IPass] = h;
    PriceL[IPass] = l;
    ABars[IPass] = CurrentBar;
    { plot1(h,"",cyan,default,5);} { JGW - uncomment to show the selected point }
    end;
    end;

    if FirstTime then { JGW - prevent redraw on each new bar }
    if lastbaronchart then begin
    FirstTime = false;
    If IPass<>CharKnt then begin
    If PriceC[Ipass+1]<>0 then begin
    Ipass=Ipass+1;
    PriceH[IPass] = PriceC[IPass];
    PriceL[IPass] = PriceC[IPass];
    Value1=Round((DateToJulian(Dates[IPass])-DateToJulian(date))*5/7,0);
    ABars[IPass] = CurrentBar+Value1;
    For Value1=1 to 100 begin
    Value2=BarsToDate_Time(0, Value1, Value3, Value4);
    AryCount=AryCount+1;
    DateAry[AryCount]=Value3;
    TimeAry[AryCount]=Value4;
    If AryCount>9999 then begin
    ok2draw = false;
    AryCount=9999;
    End;
    End;
    End;
    End;

    If IPass<>CharKnt or ok2draw=false or CharKnt <> 2 then begin
    Value1 = text_new(date,time,c,"Missing Label/Or too many "+NumToStr(AryCount,0));
    text_setstyle(Value1,1,1);
    End
    Else begin
    FOR IPASS=1 TO CHARKNT-1 BEGIN {start of plotting loop}
    Date1 = Dates[Ipass];
    Time1 = Times[Ipass];
    Date2 = Dates[Ipass+1];
    Time2 = Times[Ipass+1];

    { JGW - Fib code }
    if PriceC[IPass] < PriceC[IPass+1] then begin
    Price1 = PriceL[IPass];
    Price2 = PriceH[IPass+1];
    end else begin
    Price1 = PriceH[IPass];
    Price2 = PriceL[IPass+1];
    end;
    if ShoDiag then begin
    han = tl_new(date1,time1,price1,date2,time2,price2);
    tl_setcolor(han,fibcolors[ii]);
    tl_setextleft(han,false);
    tl_setextright(han,false);
    tl_setsize(han,0);
    end;
    for ii = 1 to 6 begin
    if fibs[ii] <> 999 then begin
    if fibs[ii] > 1 then fib = price1 + fibs[ii] * (price2 - price1)
    else fib = price1 + (1 - fibs[ii]) * (price2 - price1);
    han = tl_new(date1,time1,fib,date2,time2,fib);
    tl_setcolor(han,fibcolors[ii]);
    tl_setextleft(han,false);
    tl_setextright(han,extend);
    tl_setsize(han,tlsize);
    if ShoPrice then begin
    ss = " ("+NumToStr(fibs[ii],3)+")"+spaces(2)+
    NumToStr(round(fib,1),2)+spaces(2);
    han = text_new(date2,time2,fib,ss);
    text_setcolor(han,fibcolors[ii]);
    text_setstyle(han,1,2);
    end;
    end;
    end; { end of Fib code }
    End; {end IPASS loop}
    End; {end of the for valid NChars loop}
    END; {End last bar test}

    if false then begin
    plot1(0,"");
    plot2(0,"");
    plot3(0,"");
    plot4(0,"");
    end;