[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Adding buy & sell to point and figure chart



PureBytes Links

Trading Reference Links

I wanted to apply buys and sells to a nice P&F chart that Graham did 
a while back. I tried to use some of the examples in Howard Bandy's 
book plus other posts on this board to add the buys and sells. At 
this point I am stumped and would really appreciate any help to get 
the code running. It does produce results, but they are wrong.
Thanks
Larry


 
 
GraphXSpace = 5; 
 
SetChartBkColor(ParamColor("BackGroundColor",  colorBlack)); 
GraphColor =  ParamColor("GarphColor",colorLightGrey); 
//GridColor = ParamColor("GridColor", ColorRGB(39,49, 67) ); 
GridColor = ParamColor("GridColor", colorWhite ); 
/* 
Scaling = ParamList("Scaling Method", "Traditional|Percentage|AVG 
True Range"); 
 
if( scaling == "Traditional")      Box = Param("Box", 1, 0.2, 40, 
0.1);  
else 
if( scaling == "Percentage")      Box = Param("Box", 1, 0.2, 40, 
0.1)/100 * LastValue(C);  
else 
if( scaling == "AVG True Range")  Box = Optimize("Box", 1, 0.3, 20, 
1) * LastValue( ATR (20));  
*/ 
//Box = Optimize("Box", 1, 0.3, 20, 1) * LastValue( ATR (20));  
//Box = Optimize("Box", 1.4, 0.2, 10, 0.1)/100 * LastValue(C); 
Box = Optimize("Box", 2., 0.2, 10, 0.1); 
shiftChart =0; 
shiftLastClose =1; 
shiftGrid =7; 
shiftPriceAxis = 2; 
 
 
Reverse = Optimize("Reverse", 2, 1, 10,0.1); 
j = 0; 
PFL[0] = Box * ceil(Low[0]/Box) + Box; 
PFH[0] = Box * floor(High[0]/Box); 
direction = 0; 
Buy = 0; 
Sell = 0; 
entryprice = 0; 
SetBarsRequired(10000,10000); 
BuyPrice=0;  
SellPrice=0; 
 
for( i = 1; i < BarCount; i++ ) 
{ 
if(direction[j] == 0) 
{ 
if(Low[i] <= PFL[j] - Box) 
{ 
PFL[j] = Box * ceil(Low[i]/Box); 
} 
else 
{ 
if(High[i] >= PFL[j] + Reverse*Box) 
{ 
j++; 
direction[j] = 1; 
PFH[j] = Box * floor(High[i]/Box); 
PFL[j] = PFL[j - 1] + Box; 
 
} 
} 
} 
else 
{ 
if(High[i] >= PFH[j] + Box) 
{ 
PFH[j] = Box * floor(High[i]/Box); 
} 
else 
{ 
if( Low[i] <= PFH[j] - Reverse * Box ) 
{ 
j++; 
direction[j] = 0; 
PFH[j] = PFH[j - 1] - Box; 
PFL[j] = Box * ceil(Low[i]/Box); 
 
} 
} 
} 
}
for( i = 1; i < BarCount; i++ )  
{ 
      if(entryprice == 0 AND 
         High[i] >= PFL[j] + Reverse*Box) 
     { 
      Buy[i] = 1;
      BuyPrice[i] = C[i] ;
      entryprice = BuyPrice[i];  
      //Sell[i] = 0; 
     } 
     else 
     {     
      if( entryprice > 0 AND
          Low[i] <= PFH[j] - Reverse * Box )   
     {
      Sell[i] = 1; 
      SellPrice[i] = C[i];  
      entryprice = 0;
     }
    }
}
 
 
delta = BarCount - j -1; 
direction = Ref(direction, - delta); 
Hi = Ref(PFH, -delta) + Box/2; 
Lo = Ref(PFL, -delta)- Box/2; 
Cl = IIf(direction == 1, Hi, Lo); 
Op = IIf(direction == 1, Cl - Box, Cl + Box); 
 
 
 
 
PlotOHLC(Op, Hi, Lo, Cl,"", GraphColor , 
stylePointAndFigure|styleNoLabel, 0, 0 ,shiftChart); 
 
 
 
Last = Ref( LastValue(C), -(BarCount-1)); 
Plot( Last,"", colorRed,styleNoLine|styleDots, 0 , 0, 
shiftLastClose); 
 
// selected value 
Value= IIf(direction>0, SelectedValue(Hi)-box/2, SelectedValue(Lo)
+box/2); 
 
//--------------------------------------------------------------------
--- 
//        GRID CONSTRUCTION 
//--------------------------------------------------------------------
-- 
 
PlotGridLines = ParamToggle("PlotdGrid", "N0|YES", 0); 
 
 
 
if (PlotGridLines) 
{ 
begin = SelectedValue(BarIndex()); 
end = LastValue(BarIndex()); 
period = end-begin +1; 
 
if( begin<end) 
{ 
 
 
ScreenHigh =LastValue( HHV(cl, period )); 
ScreenLow =LastValue( LLV( Cl, period) ); 
 
 
top= LineArray( begin-shiftGrid, screenHigh, end, screenhigh, 0 , 1); 
Bot= LineArray( begin-shiftGrid, screenlow, end, screenLow, 0, 1); 
 
Plot( top, "", gridColor,styleLine|styleNoLabel , 0, 0,shiftGrid); 
//Plot( bot, "", gridColor,styleLine|styleNoLabel,  0 , 0 , 
shiftGrid); 
 
 
VerticalGrid = IIf ( BarIndex() >= begin, IIf(direction==1, 
screenHigh, screenLow), Null); 
 
Plot (VerticalGrid, "", gridColor, styleStaircase|styleNoLabel, 0,0, 
1); 
 
 
    format = 8.2; 
 
 
 
    for  ( n=LastValue(bot); n< LastValue(top) - 0.5*box; n = n+box) 
    { 
         
    Plot(  bot , "", gridColor, styleLine|styleNoLabel, 0, 
0 ,shiftGrid); 
     
     
    text = NumToStr(LastValue(bot) + 0.5*box, format); 
    xposition = BarCount+shiftPriceaxis; 
    yPosition = LastValue(bot)+0.27*box; 
     
    PlotText(text,  xPosition , yPosition, colorWhite); 
    bot = bot + box;     
 
    }     
} 
 
} 
 
 
//--------------------------------------------------------------------
- 
//    TITLE  
//--------------------------------------------------------------------
-- 
 
Title = "\n" +  
" Instrument : " + Name() +  FullName()+"\n " + 
"Formula : " + " PF StockChart" + "\n " + 
"Box  : " +  box + "     " + 
"Reverse : " +  reverse + "\n " + 
"ATR : " + LastValue(ATR(20)); 



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

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/