HiMay be this will help you
_SECTION_BEGIN("INIT");
        SetChartOptions(0,chartShowArrows|chartShowDates);      ScanLookBack = 
Param("Scan Lookback", 2, 1, 25 );       fraction= IIf(StrRight(Name(),3) == 
"", 3.2, 3.2);
_SECTION_END();
_SECTION_BEGIN("Price");        
SetChartOptions(0,chartShowArrows|chartShowDates);      _N(Title = 
StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g,Close %g 
(%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C,SelectedValue( 
ROC( C, 1 )) ));             Plot( C, _DEFAULT_NAME(), 
IIf(Close>Open,colorBrightGreen,colorRed) , styleNoTitle | ParamStyle("Style") 
|GetPriceStyle() ); _SECTION_END();
_SECTION_BEGIN("Up Trend Line");                
UTValue1=LastValue(Trough(L,0.5,2));    UTValue2=LastValue(Trough(L,0.5,1));    
UTBar1=BarCount - 1 - LastValue(TroughBars(L,0.5 ,2));  UTBar2=BarCount - 1 - 
LastValue(TroughBars(L,0.5 ,1));          UpTrendLine = LineArray( UTBar1, 
UTValue1, UTBar2,UTValue2, 1 );        UTLine = LineArray( UTBar1, UTValue1, 
UTBar2,UTValue2, 0 );     Plot( UpTrendLine , _DEFAULT_NAME(), 
colorGreen,styleLine | styleNoTitle |styleNoLabel);        Plot( UTLine , 
_DEFAULT_NAME(), colorGreen,styleLine | styleNoTitle |styleNoLabel); 
_SECTION_END();

_SECTION_BEGIN("Down Trend Line");
        DTValue1=LastValue(Peak(H,0.5 ,2));     DTValue2=LastValue(Peak(H,0.5 
,1));     DTBar1=BarCount - 1 - LastValue(PeakBars(H,0.5 ,2));            
DTBar2=BarCount - 1 - LastValue(PeakBars(H,0.5 ,1));    DownTrendLine = 
LineArray( DTBar1, DTValue1, DTBar2,DTValue2, 1 );      DTLine = LineArray( 
DTBar1, DTValue1, DTBar2,DTValue2, 0 );
        Plot( DownTrendLine ,_DEFAULT_NAME(), colorRed,styleLine | styleNoTitle 
|styleNoLabel);         Plot( DTLine ,_DEFAULT_NAME(), colorRed,styleLine | 
styleNoTitle |styleNoLabel);                PlotText("PV = " + 
WriteVal(DTValue2 ,fraction), LastValue(BarIndex())+2,(DTValue2 ), colorRed);   
     PlotText("TV = " + WriteVal(UTValue2,fraction), 
LastValue(BarIndex())+2,UTValue2, colorGreen);  PlotOHLC( UpTrendLine , 
UpTrendLine , DownTrendLine , DownTrendLine , "",ColorBlend( colorGreen, 
colorLightYellow, 0.9 ), styleCloud | styleNoRescale);         Plot(LineArray( 
DTBar2, DTValue2, BarCount,DTValue2, 0 ),"",colorRed);  Plot(LineArray( UTBar2, 
UTValue2, BarCount,UTValue2, 0 ),"",colorGreen);
_SECTION_END();
_SECTION_BEGIN("Pivot");
        YH = TimeFrameGetPrice("H", inDaily, -1);               // yesterdays 
high      YL = TimeFrameGetPrice("L", inDaily, -1);               //            
                  low     YC = TimeFrameGetPrice("C", inDaily, -1);             
  //                              close   TO = TimeFrameGetPrice("O", inDaily); 
                  // current day open
        //Normal Pivot  PP = (YH + YL + YC) / 3;        R1 = (2 * PP) - YL;     
R2 = PP + (YH - YL);    R3 = YH + 2*(PP-YL);    S1 = (2 * PP) - YH;     S2 = PP 
- (YH - YL);    S3 = YL - 2*(YH - PP) ; _SECTION_END();
_SECTION_BEGIN("Title");
Title = EncodeColor(colorWhite)+ Date() + "   Close = " + 
EncodeColor(colorRed)+Close +         EncodeColor(colorWhite) + "     Open = " 
+ EncodeColor(colorWhite) + O +                EncodeColor(colorWhite) + "     
High = " + EncodeColor(5) + H +         EncodeColor(colorWhite) + "      Low = 
" + EncodeColor(colorRed) + L +          EncodeColor(colorWhite) + "     Volume 
= " + EncodeColor(colorWhite) + V +"\n\n"+               
EncodeColor(colorWhite) + "Pivot Point= " + EncodeColor(colorWhite) + PP +      
        EncodeColor(colorWhite) + "     Day's Open= " + EncodeColor(colorWhite) 
+ TO+"\n\n"+            EncodeColor(colorGreen) + "If days open is greater than 
Pivot Point, marketis in uptrend AND \n"+EncodeColor(colorRed)+"if days Open is 
less than PivotPoint, market is in downtrend" +"\n\n"+          
EncodeColor(colorRed) + "R1= " + EncodeColor(colorWhite) + R1 +         
EncodeColor(colorRed) + "  R2= " + EncodeColor(colorWhite) + R2 +               
EncodeColor(colorRed) + "  R3= " + EncodeColor(colorWhite) + R3 +"\n"+  
        EncodeColor(colorGreen) + "S1= " + EncodeColor(colorWhite) + S1 +       
        EncodeColor(colorGreen) + "  S2= " + EncodeColor(colorWhite) + S2 +     
        EncodeColor(colorGreen) + "  S3= " + EncodeColor(colorWhite) + S3 
+"\n"+                EncodeColor( colorWhite) +"____  _____  _______  _______  
_______"+"\n"; _SECTION_END();
_SECTION_BEGIN("Target"); 
        CBuy = Cross(C,DownTrendLine);  CSell = Cross(UpTrendLine ,C);
        baratbuy = ValueWhen(CBuy ,BarIndex()) ;        baratsell = 
ValueWhen(CSell ,BarIndex()) ;
        PlotShapes(shapeUpTriangle* CBuy ,colorBlue,O,L);       
PlotShapes(shapeDownTriangle * CSell ,colorRed,O,H);

_SECTION_END();
_SECTION_BEGIN("Auto");

        Buy  = ( CBuy ) AND  ( (BarCount - baratbuy )<=ScanLookBack );  Sell = 
( CSell ) AND  ( (BarCount - baratsell )<=ScanLookBack  ) ;
        price = C[BarCount-1];
        AlertIf(Buy,"","Buy @"+C+"  Price @ Trigger="+price,1); 
AlertIf(Sell,"","Sell @"+C+"  Price @ Trigger="+price,2);
        Filter =  Buy OR Sell ;
        Var = WriteIf(Buy,"BUY",WriteIf(Sell,"SELL",""));
        AddTextColumn( Var , "Buy/Sell", 1.2 , colorWhite, IIf( Buy, 
colorLime,IIf(Sell,colorOrange,colorWhite) ));             AddColumn(price 
,"Price",1.2,colorWhite, IIf( Buy, colorLime,IIf(Sell,colorOrange,colorWhite) 
));       AddColumn(C ,"Price @ Trigger",1.2,colorWhite, IIf( Buy, 
colorLime,IIf(Sell,colorOrange,colorWhite) ));
        stoploss = IIf(Buy, (price  * (1-0.01)) , IIf(Sell, (price  * 
(1+0.01)),0));    target1per = IIf(Buy, (price  * (1+0.01)) , IIf(Sell, (price  
*(1-0.01)),0));   target15per = IIf(Buy, (price  * (1+0.015)) , IIf(Sell, 
(price *(1-0.015)),0)); target2per = IIf(Buy, (price  * (1+0.02)) , IIf(Sell, 
(price  *(1-0.02)),0));           AddColumn(stoploss ,"Stop 
Loss",1.2,colorWhite, IIf( Buy, colorLime,IIf(Sell,colorOrange,colorWhite) ));  
      AddColumn(target1per ,"1% Target",1.2,colorWhite, IIf( Buy, 
colorLime,IIf(Sell,colorOrange,colorWhite) ));      AddColumn(target15per 
,"1.5% Target",1.2,colorWhite, IIf( Buy, 
colorLime,IIf(Sell,colorOrange,colorWhite) ));   AddColumn(target2per ,"2% 
Target",1.2,colorWhite, IIf( Buy, colorLime,IIf(Sell,colorOrange,colorWhite) 
));      AddColumn(V ,"Volume",1.2,colorWhite, IIf( Buy, 
colorLime,IIf(Sell,colorOrange,colorWhite) ));          bardiff = BarCount - 
IIf(Buy,baratbuy,IIf(Sell,baratsell,0));   AddColumn(bardiff  ,"Bar 
Diff",1.2,colorWhite, IIf( Buy,
 colorLime,IIf(Sell,colorOrange,colorWhite) ));

_SECTION_END();


--- On Tue, 8/17/10, ford7k <[email protected]> wrote:

From: ford7k <[email protected]>
Subject: [amibroker] Req  please help by correcting bar count error in the afl
To: [email protected]
Date: Tuesday, August 17, 2010, 4:35 AM















 
 



  


    
      
      
      

Hi seniors and afl experts,



Here is an afl with barcount error.



Becoz of error,I am not able to run it.



please,fix the error and post corrected afl.



thanks



best regards



ford



----------



afl code



------------------



PIVOTFINDER BY MARK

//Code to automatically identify pivots



/*********************************** */



// -- what will be our lookback range for the hh and ll?

farback=Param("How Far back to go",100,50,5000,10);

nBars = Param("Number of bars", 12, 5, 40);



// -- Title.



Title = Name() + " (" + StrLeft(FullName(), 15) + ") O: " + Open + ",



H: " + High + ", L: " + Low + ", C: " + Close;



// -- Plot basic candle chart



PlotOHLC(Open, High, Low, Close,



"BIdx = " + BarIndex() +



"\n" + "O = " + O + "\n"+"H = "+ H + "\n"+"L = " + L



+ "\n"+"C ",



colorBlack, styleCandle);



GraphXSpace=7;



// -- Create 0-initialized arrays the size of barcount



aHPivs = H - H;



aLPivs = L - L;



// -- More for future use, not necessary for basic plotting



aHPivHighs = H - H;



aLPivLows = L - L;



aHPivIdxs = H - H;



aLPivIdxs = L - L;



nHPivs = 0;



nLPivs = 0;



lastHPIdx = 0;



lastLPIdx = 0;



lastHPH = 0;



lastLPL = 0;



curPivBarIdx = 0;



// -- looking back from the current bar, how many bars



// back were the hhv and llv values of the previous



// n bars, etc.?



aHHVBars = HHVBars(H, nBars);



aLLVBars = LLVBars(L, nBars);



aHHV = HHV(H, nBars);



aLLV = LLV(L, nBars);



// -- Would like to set this up so pivots are calculated back from



// last visible bar to make it easy to "go back" and see the pivots



// this code would find. However, the first instance of



// _Trace output will show a value of 0



aVisBars = Status("barvisible");



nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));



_TRACE("Last visible bar: " + nLastVisBar);



// -- Initialize value of curTrend



curBar = (BarCount-1);



curTrend = "";



if (aLLVBars[curBar] <



aHHVBars[curBar]) {



curTrend = "D";



}



else {



curTrend = "U";



}



// -- Loop through bars. Search for



// entirely array-based approach



// in future version



for (i=0; i<farback; i++) {



//curBar = (BarCount - 1) - i;

curBar = (BarCount - 0) ;



// -- Have we identified a pivot? If trend is down...



//if (aLLVBars[curBar] < aHHVBars[curBar]) {

for( bar = 0; bar < BarCount; bar++ )

{

    if( bar > 0 )

        a[ bar ] = C[ bar - 1 ];   // only access C[ i - 1 ] when i is

greater than zero

    else

        a[ bar ] = C[ 0 ];

}



// ... and had been up, this is a trend change



if (curTrend == "U") {



curTrend = "D";



// -- Capture pivot information



curPivBarIdx = curBar - aLLVBars[curBar];



aLPivs[curPivBarIdx] = 1;



aLPivLows[nLPivs] = L[curPivBarIdx];



aLPivIdxs[nLPivs] = curPivBarIdx;



nLPivs++;



}



// -- or current trend is up



} //else {



if (curTrend == "D") {



curTrend = "U";



curPivBarIdx = curBar - aHHVBars[curBar];



aHPivs[curPivBarIdx] = 1;



aHPivHighs[nHPivs] = H[curPivBarIdx];



aHPivIdxs[nHPivs] = curPivBarIdx;



nHPivs++;



}



// -- If curTrend is up...else...



}



// -- loop through bars



}



// -- Basic attempt to add a pivot this logic may have missed



// -- OK, now I want to look at last two pivots. If the most



// recent low pivot is after the last high, I could



// still have a high pivot that I didn't catch



// -- Start at last bar



curBar = (BarCount-1);



candIdx = 0;



candPrc = 0;



lastLPIdx = aLPivIdxs[0];



lastLPL = aLPivLows[0];



lastHPIdx = aHPivIdxs[0];



lastHPH = aHPivHighs[0];



if (lastLPIdx > lastHPIdx) {



// -- Bar and price info for candidate pivot



candIdx = curBar - aHHVBars[curBar];



candPrc = aHHV[curBar];



if (



lastHPH < candPrc AND



candIdx > lastLPIdx AND



candIdx < curBar) {



// -- OK, we'll add this as a pivot...



aHPivs[candIdx] = 1;



// ...and then rearrange elements in the



// pivot information arrays



for (j=0; j<nHPivs; j++) {



aHPivHighs[nHPivs-j] = aHPivHighs[nHPivs-



(j+1)];



aHPivIdxs[nHPivs-j] = aHPivIdxs[nHPivs-(j+1)];



}



aHPivHighs[0] = candPrc ;



aHPivIdxs[0] = candIdx;



nHPivs++;



}



} else {



// -- Bar and price info for candidate pivot



candIdx = curBar - aLLVBars[curBar];



candPrc = aLLV[curBar];



if (



lastLPL > candPrc AND



candIdx > lastHPIdx AND



candIdx < curBar) {



// -- OK, we'll add this as a pivot...



aLPivs[candIdx] = 1;



// ...and then rearrange elements in the



// pivot information arrays



for (j=0; j<nLPivs; j++) {



aLPivLows[nLPivs-j] = aLPivLows[nLPivs-(j+1)];



aLPivIdxs[nLPivs-j] = aLPivIdxs[nLPivs-(j+1)];



}



aLPivLows[0] = candPrc;



aLPivIdxs[0] = candIdx;



nLPivs++;



}



}



// -- Dump inventory of high pivots for debugging



/*



for (k=0; k<nHPivs; k++) {



_TRACE("High pivot no. " + k



+ " at barindex: " + aHPivIdxs[k] + ", "



+ WriteVal(ValueWhen(BarIndex()==aHPivIdxs[k],



DateTime(), 1), formatDateTime)



+ ", " + aHPivHighs[k]);



}



*/



// -- OK, let's plot the pivots using arrows



PlotShapes(



IIf(aHPivs==1, shapeDownArrow, shapeNone), colorRed, 0,



High, Offset=-15);



PlotShapes(



IIf(aLPivs==1, shapeUpArrow , shapeNone), colorGreen, 0,



Low, Offset=-15);



Plot(aHHV," HIGH PIVOTS",colorRed,8+16);

Plot(aLLV," LOW PIVOTS",colorBlue,8+16);



//CODE EXPLORE

Filter = aLLV OR aHHV;

AddColumn(aHHV,"aHHV",1.2);

AddColumn(aLLV,"aLLV",1.2);

AddColumn(C, "Close", 1.2);

AddColumn(EMA(C,13), " Ema 13", 1, 3);

AddColumn(EMA(C,21), "EMA 21", 1, 3);

AddColumn(EMA(C,34), "EMA 34", 1, 3);



Plot(aHHV," HIGH PIVOTS",colorRed,8+16);

Plot(aLLV," LOW PIVOTS",colorBlue,8+16);





    
     

    
    


 



  











      

Reply via email to