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

Re: [amibroker] REQUIRED DIVERGENCE PLOT(MARK) ON THIS INDICATOR


  • Date: Sun, 22 Nov 2009 17:31:56 +0100
  • From: reinsley <reinsley@xxxxxxxx>
  • Subject: Re: [amibroker] REQUIRED DIVERGENCE PLOT(MARK) ON THIS INDICATOR

PureBytes Links

Trading Reference Links

Hi,

Please find two formulas to plot divergences you could adapt.
For a visual check between price and macd.



NB : Capital letters in a post means : to shout at sb


Best regards



// test divergence

// with linearray
// to draw a divergence line on price
// http://www.amibroker.com/guide/afl/afl_view.php?id=250
// adapted by reinsley

y2t=LastValue(Trough(L,0.5,2))-4;
//_TRACE("y2t = "+y2t);
y1t=LastValue(Trough(L,0.5,1))-4;
//_TRACE("y1t = "+y1t);
x2t=BarCount - 1 - LastValue(TroughBars(L,0.5,2));
//_TRACE("x2t = "+x2t);
x1t=BarCount - 1 - LastValue(TroughBars(L,0.5,1));
//_TRACE("x1t = "+x1t);
LineLo = LineArray( x2t, y2t, x1t, y1t, 0 );


// a = ( low2 - low1 ) / ( bars2 - bars1 )
pat = ( y2t - y1t ) / ( x2t - x1t );
//_TRACE("slope price trough = "+pat);

DivColorLo=IIf(pat>=0,27,32);

Plot(C, "Cl", colorBlack, styleCandle);
Plot( LineLo, "TLlo", DivColorLo,styleLine+styleDots+styleThick);
//_TRACE("BC = "+BarCount);


_SECTION_BEGIN("ZIG - Zig");
P = ParamField( "Price field" );
change = Param("% change",0.5,0.1,25,0.1);
Plot( Zig(P, change), _DEFAULT_NAME(), ParamColor( "Color", colorCycle 
), ParamStyle("Style") );
_SECTION_END();

y2p=LastValue(Peak(H,0.5,2))+4;
//_TRACE("y2p = "+y2p);
y1p=LastValue(Peak(H,0.5,1))+4;
//_TRACE("y1p = "+y1p);
x2p=BarCount - 1 - LastValue(PeakBars(H,0.5,2));
//_TRACE("x2p = "+x2p);
x1p=BarCount - 1 - LastValue(PeakBars(H,0.5,1));
//_TRACE("x1p = "+x1p);
LineHi = LineArray( x2p, y2p, x1p, y1p, 0 );


// a = ( low2 - low1 ) / ( bars2 - bars1 ) // price a (slope) peak
pap = ( y2p - y1p ) / ( x2p - x1p );
//_TRACE("slope price = "+pap);

DivColorHi=IIf(pap>=0,27,32);

Plot( LineHi, "TLhi", DivColorHi,styleLine+styleDots);


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


//MACD fast no cross 10 UT
//v 1.1
//to find the no cross signal
// adaptation by reinsley

/////////////////Plot Price//////////////////////
_N( Title = "MACD fast no cross 10 UT - " + StrFormat( "{{NAME}} - 
{{INTERVAL}} {{DATE}} " ) );
/////////////////////////////////////////////////


r1 = Param( "Fast avg", 5, 2, 200, 1 );
r2 = Param( "Slow avg", 10, 2, 200, 1 );
r3 = Param( "Signal avg", 3, 2, 200, 1 );

ml = MACD( r1, r2 );
sl = Signal( r1, r2, r3 );
// color macd and signal
MACDcol = IIf( ml > sl, colorGreen, IIf( ml < sl, colorRed, colorGreen ) );
Sigcol = IIf( ml > sl, colorGreen, IIf( ml < sl, colorRed, colorGreen ) );

Plot( ml , StrFormat( _SECTION_NAME() + "(%g,%g)", r1, r2 ), MACDcol, 
styleThick );//("MACD style")//| styleNoLabel
Plot( sl , "Signal" + _PARAM_VALUES(), Sigcol   ,  styleDashed 
);//ParamStyle( "Signal style" ) );//| styleNoLabel
Plot( mh = ml - sl, "MACD Histogram", ParamColor( "Histogram color", 
colorBlack ), styleNoTitle | ParamStyle( "Histogram style", 
styleHistogram | styleThick | styleNoLabel, maskHistogram ) );//| 
styleNoLabel

_SECTION_BEGIN( "MACD" );
// color enveloppe histo bar
mcol = IIf( mh > Ref( mh, -1 ), IIf( mh > 0, 27, 43 ), IIf( mh > 0, 32, 
32 ) );// 43 bright green
//mcol= IIf(mh>Ref(mh,-1),IIf(mh > 0,27,27),IIf(mh > 0,32,32));// 27 
green : 32 red
lastbar0 = Ref( mh, 0 ) > Ref( mh, - 1 )AND mh >= 0 ;
lastbar1 = Ref( mh, - 1 ) < Ref( mh, - 2 )AND mh >= 0 ;
lastbar2 = Ref( mh, - 2 ) < Ref( mh, - 3 )AND mh >= 0 ;
lastbar3 = Ref( mh, - 3 ) < Ref( mh, - 4 )AND mh >= 0 ;

signocrossup = IIf( lastbar0 AND lastbar1 AND lastbar2   , 1, 0 );
//color no cross histo bar in white
barcolorup = IIf( signocrossup, 2, 1 );// 2 white

lastbardn0 = Ref( mh, 0 ) < Ref( mh, - 1 )AND mh <= 0 ;
lastbardn1 = Ref( mh, - 1 ) > Ref( mh, - 2 )AND mh <= 0 ;
lastbardn2 = Ref( mh, - 2 ) > Ref( mh, - 3 )AND mh <= 0 ;
lastbardn3 = Ref( mh, - 3 ) > Ref( mh, - 4 )AND mh <= 0 ;

signocrossdown = IIf( lastbardn0 AND lastbardn1 AND lastbardn2   , 1, 0 );
//color no cross histo bar in white
barcolordn = IIf( signocrossdown, 2, 1 );
//color histo bar zero line
//Color=IIf(mh > 0,colorGreen,colorDarkRed);
Color = IIf( mh > Ref( mh, -1 ), IIf( mh > 0, 27, 43 ), IIf( mh > 0, 32, 
32 ) );

Graph2BarColor = IIf ( signocrossup, barcolorup, IIf( signocrossdown, 
barcolordn, Color ) );

Plot( mh, "MACDHistogram", mcol, 6 | styleNoTitle | 4096 );//32768|
Plot( mh, "MACDHistogram", mcol, 5 | styleNoTitle | 4096 ); //32768|

GraphXSpace = 5;


m11 = MACD( r1, r2 );
percent = Param( "Zigpercnt", 2, 0.1, 5, 0.1 );

x22t = BarCount - 1 - LastValue( TroughBars( C, percent , 2 ) );
x11t = BarCount - 1 - LastValue( TroughBars( C, percent , 1 ) );
y22t = m11[x22t] - 2;
y11t = m11[x11t] - 2;
LineLow = LineArray( x22t, y22t, x11t, y11t, 0 );

// a = ( low2 - low1 ) / ( bars2 - bars1 )
at = ( y22t - y11t ) / ( x22t - x11t );

// color divergence line trough
DivColorTrou = IIf( at >= 0, 27, 32 );

Plot( LineLow, "TLlow", DivColorTrou, styleLine + styleDots );


x22p = BarCount - 1 - LastValue( PeakBars( C, percent , 2 ) );
x11p = BarCount - 1 - LastValue( PeakBars( C, percent , 1 ) );
y22p = m11[x22p] + 2;
y11p = m11[x11p] + 2;
LineHigh = LineArray( x22p, y22p, x11p, y11p, 0 );

// a = ( low2 - low1 ) / ( bars2 - bars1 )
ap = ( y22p - y11p ) / ( x22p - x11p );

// color divergence line peak
DivColorPeak = IIf( ap >= 0, 27, 32 );

Plot( LineHigh, "TLhigh", DivColorPeak, styleLine + styleDots );
_SECTION_END();

//SetChartBkGradientFill( ParamColor("BgTop", 
colorLightYellow),ParamColor("BgBottom", colorDarkGrey)); 
//colorLightGrey//colorCustom10


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

**** 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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/