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

[amibroker] Trendlines on PnF charts



PureBytes Links

Trading Reference Links

Let me try this again as this ended up in the wrong thread...

My drawings on PnF charts move to the left every day (daily data) while
the actual PnF chart does not. What would be a good way to stop this
from happening?

Attached find the code. If you put it into replay mode , draw a trend 
line, or just click somewhere on the PnF chart (which will auto draw a 
trendline), you will see what I mean.


Thanks,

Anthony

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

GraphXSpace = 5;

SetChartBkColor(ParamColor("BackGroundColor",  colorBlueGrey));
GraphColor =  ParamColor("GraphColor",colorLightGrey);
GridColor = ParamColor("GridColor", colorLightBlue);//ColorRGB(39,49, 67) );

Scaling = ParamList("Scaling Method", "Traditional|Percentage|AVG True 
Range");

LastClose = LastValue(Close);

if( LastClose < 5) boxsize = 0.10;
else
    if( LastClose >=5 AND LastClose < 10) boxsize = 0.20;
    else
        if( LastClose >=10 AND LastClose < 20) boxsize = 0.50;
        else
            if( LastClose >=20 AND LastClose < 100) boxsize = 1.00;
            else
                if( LastClose >=100 AND LastClose < 200) boxsize = 2.00;
                else
                    if( LastClose >=200 AND LastClose < 500) boxsize = 5.00;
                    else
                        if( LastClose >=500 AND LastClose < 1000) 
boxsize = 10.00;
                        else
                            if( LastClose >=1000 AND LastClose < 2000) 
boxsize = 20.00;
                            else
                                if( LastClose >=2000 AND LastClose < 
5000) boxsize = 50.00;

if( scaling == "Traditional")      Box = boxsize; //Param("Box", 1, 0.2, 
10, 0.1);
else
if( scaling == "Percentage")      Box = boxsize/100 * 
LastValue(C);//Param("Box", 1, 0.2, 10, 0.1)/100 * LastValue(C);
else
if( scaling == "AVG True Range")  Box = noxsize * 
LastValue(ATR(20));//Param("Box", 1, 0.3, 5, 0.1) * LastValue( ATR (20));



shiftChart =0;
shiftLastClose =1;
shiftGrid =7;
shiftPriceAxis = 2;


Reverse = Param("Reverse", 3, 1, 5);
j = 0;
PFL[0] = Box * ceil(Low[0]/Box) + Box;
PFH[0] = Box * floor(High[0]/Box);
direction = 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);

}
}
}
}
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", "Yes|No", 1);



//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;  

    }  
//}


LineUp = LineArray( SelectedValue(BarIndex()), SelectedValue(L), 
SelectedValue(BarIndex())+1, SelectedValue(L)+box, 1, 0 );
Linedown = LineArray( SelectedValue(BarIndex()), SelectedValue(H), 
SelectedValue(BarIndex())+1, SelectedValue(H)-box, 1, 0 );

LineUp1 = LineArray( SelectedValue(BarIndex()), SelectedValue(Lo), 
SelectedValue(BarIndex())+1, SelectedValue(Lo)+box, 1, 0 );
Linedown1 = LineArray( SelectedValue(BarIndex()), SelectedValue(Hi), 
SelectedValue(BarIndex())+1, SelectedValue(Hi)-box, 1, 0 );

Plot(Lineup1, "Line", colorGreen, styleLine + styleNoLabel + 
styleNoRescale);
Plot(LineDown1, "Line", colorBrown, styleLine + styleNoLabel + 
styleNoRescale);

//Plot(IIf(SelectedValue(Cl=Lo),Lineup,Null), "Line", colorGreen, 
styleLine + styleNoLabel + styleNoRescale);
//Plot(IIf(SelectedValue(CL=Hi),Linedown,Null), "Line", colorBrown, 
styleLine + styleNoLabel + styleNoRescale);

}


//---------------------------------------------------------------------
//    TITLE
//----------------------------------------------------------------------

Title = "\n" +
" Instrument : " + Name() +  FullName()+"\n " +
"Formula : " + " PF StockChart" + "\n " +
"Box  : " +  box + "     " +
"Reverse : " +  reverse + "\n " +
"ATR : " + LastValue(ATR(20)) + "\n" +
"Date :" + Date();

_SECTION_END();


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

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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

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/