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

Re: [amibroker] Macd no crossover



PureBytes Links

Trading Reference Links

Gotcha !

What a stange world...Array is hard to get it.

//MACD no cross
//v 1.1
//to visualize the no cross signal

_N( Title = "MACD no cross - " + StrFormat( "{{NAME}} - {{INTERVAL}} 
{{DATE}} Open %g, Hi %g, Lo %g, Cl %g {{VALUES}}", O, H, L , C  ) );

_SECTION_BEGIN( "MACD" );
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
Plot( ml = MACD( r1, r2 ), StrFormat( _SECTION_NAME() + "(%g,%g)", r1, 
r2 ), ParamColor( "MACD color", colorRed ), styleThick );//("MACD style")
Plot( sl = Signal( r1, r2, r3 ), "Signal" + _PARAM_VALUES(), ParamColor( 
"Signal color", colorBlue ), ParamStyle( "Signal style" ) );
Plot( ml - sl, "MACD Histogram", ParamColor( "Histogram color", 
colorBlack ), styleNoTitle | ParamStyle( "Histogram style", 
styleHistogram | styleNoLabel, maskHistogram ) );
_SECTION_END();

m1 = MACD( r1, r2 );
s1 = Signal( r1, r2, r3 );
MACDhist = m1 - s1;

lastbar0 = Ref( MACDhist, 0 ) > Ref( MACDhist, - 1 )AND MACDhist >= 0 ;
lastbar1 = Ref( MACDhist, - 1 ) < Ref( MACDhist, - 2 )AND MACDhist >= 0 ;
lastbar2 = Ref( MACDhist, - 2 ) < Ref( MACDhist, - 3 )AND MACDhist >= 0 ;
lastbar3 = Ref( MACDhist, - 3 ) < Ref( MACDhist, - 4 )AND MACDhist >= 0 ;

signocrossup = IIf( lastbar0 AND lastbar1 AND lastbar2 AND lastbar3  , 
1, 0 );
barcolorup = IIf( signocrossup, 2, 1 );

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

signocrossdown = IIf( lastbardn0 AND lastbardn1 AND lastbardn2 AND 
lastbardn3  , 1, 0 );
barcolordn = IIf( signocrossdown, 2, 1 );

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

reinsley a écrit :
>
> Hello,
>
> I want to identity a MACD no-crossover.
>
> My "if" condition is wrong, it depends of the last bar.
>
> However, I find both side (positive or negative) but one after another,
> never together.
>
> What test do I do, on a scalar var and not on an array ?
>
> Must I do a loop to show upside and downside, it seems strange as I get
> the correct result without loop.
>
> I enter myself in a loop and madness is not far.
>
> Any help is appreciated.
>
> Best Regards
>
> //MACD no cross
> //v 1.1
> //to find the no cross signal
>
> /////////////////Plot Price//////////////////////
> _N( Title = "MACD no cross - " + StrFormat( "{{NAME}} - {{INTERVAL}}
> {{DATE}} Open %g, Hi %g, Lo %g, Cl %g {{VALUES}}", O, H, L , C ) );
> /////////////////////////////////////////////////
>
> _SECTION_BEGIN( "MACD" );
> r1 = Param( "Fast avg", 12, 2, 200, 1 );
> r2 = Param( "Slow avg", 26, 2, 200, 1 );
> r3 = Param( "Signal avg", 9, 2, 200, 1 );
> Plot( ml = MACD( r1, r2 ), StrFormat( _SECTION_NAME() + "(%g,%g)", r1,
> r2 ), ParamColor( "MACD color", colorRed ), styleThick );//("MACD style")
> Plot( sl = Signal( r1, r2, r3 ), "Signal" + _PARAM_VALUES(), ParamColor(
> "Signal color", colorBlue ), ParamStyle( "Signal style" ) );
> Plot( ml - sl, "MACD Histogram", ParamColor( "Histogram color",
> colorBlack ), styleNoTitle | ParamStyle( "Histogram style",
> styleHistogram | styleNoLabel, maskHistogram ) );
> _SECTION_END();
>
> m1 = MACD( r1, r2 );
> s1 = Signal( r1, r2, r3 );
> MACDhist = m1 - s1;
>
> _TRACE( "MACDhist = " + MACDhist );
>
> if ( LastValue( MACDhist ) >= 0 )// this is wrong to get up and down at
> the same time
> {
> lastbar0 = Ref( MACDhist, 0 ) > Ref( MACDhist, - 1 );
> lastbar1 = Ref( MACDhist, - 1 ) < Ref( MACDhist, - 2 );
> lastbar2 = Ref( MACDhist, - 2 ) < Ref( MACDhist, - 3 );
> lastbar3 = Ref( MACDhist, - 3 ) < Ref( MACDhist, - 4 );
>
> downmacd = 0 ;
> signocrossup = IIf( lastbar0 AND lastbar1 AND lastbar2 AND lastbar3
> , 1, 0 );
> _TRACE( "signocrossup= " + signocrossup );
> _TRACE( "lastbar0up = " + lastbar0 );
> _TRACE( "lastbar1up = " + lastbar1 );
> _TRACE( "lastbar2up = " + lastbar2 );
> _TRACE( "lastbar3up = " + lastbar3 );
>
> barcolor = IIf( signocrossup, 2, 1 );
> }
> else // negative
> {
> lastbardn0 = Ref( MACDhist, 0 ) < Ref( MACDhist, - 1 );
> lastbardn1 = Ref( MACDhist, - 1 ) > Ref( MACDhist, - 2 );
> lastbardn2 = Ref( MACDhist, - 2 ) > Ref( MACDhist, - 3 );
> lastbardn3 = Ref( MACDhist, - 3 ) > Ref( MACDhist, - 4 );
>
> downmacd = 1 ;
> signocrossdown = IIf( lastbardn0 AND lastbardn1 AND lastbardn2 AND
> lastbardn3 , 1, 0 );
> _TRACE( "signocrossdown= " + signocrossdown );
> _TRACE( "lastbardn0= " + lastbardn0 );
> _TRACE( "lastbardn1 = " + lastbardn1 );
> _TRACE( "lastbardn2 = " + lastbardn2 );
> _TRACE( "lastbardn3 = " + lastbardn3 );
>
> barcolor = IIf( signocrossdown, 2, 1 );
> }
>
> Graph2BarColor = ValueWhen( barcolor != 0, barcolor );
>
>  



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

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

*********************
TO GET TECHNICAL 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/