Whats wrong with the code

#1
Can some one plz correct this exploration code of MACD ? .......After run exploration the result is not coming. But its ok for scanning.

Thanks




_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 );

r1 = Optimize( "Fast avg", r1 , 2, 200, 1 );
r2 = Optimize( "Slow avg", r2 , 2, 200, 1 );
r3 = Optimize( "Signal avg", r3 , 2, 200, 1 );

Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), ParamColor("MACD color", colorRed ), ParamStyle("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 ) );

Buy= Cross(ml , sl);
Sell= Cross( sl, ml);

PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGreen, colorRed ) );

AlertIf( Buy , "SOUND C:\\Windows\\Media\\chimes.wav", "Audio alert", 2 );
AlertIf( Sell , "SOUND C:\\Windows\\Media\\alert.wav", "Audio alert", 2 );

_SECTION_END();


Filter = ml== 0 || sl == 0;

AddColumn(ml,"MACD", format = 1.2);
AddColumn(sl,"Signal", format = 1.2);

AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);
 

KelvinHand

Well-Known Member
#2
Can some one plz correct this exploration code of MACD ? .......After run exploration the result is not coming. But its ok for scanning.

Thanks




_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 );

r1 = Optimize( "Fast avg", r1 , 2, 200, 1 );
r2 = Optimize( "Slow avg", r2 , 2, 200, 1 );
r3 = Optimize( "Signal avg", r3 , 2, 200, 1 );

Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), ParamColor("MACD color", colorRed ), ParamStyle("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 ) );

Buy= Cross(ml , sl);
Sell= Cross( sl, ml);

PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow, IIf( Buy, colorGreen, colorRed ) );

AlertIf( Buy , "SOUND C:\\Windows\\Media\\chimes.wav", "Audio alert", 2 );
AlertIf( Sell , "SOUND C:\\Windows\\Media\\alert.wav", "Audio alert", 2 );

_SECTION_END();


Filter = ml== 0 || sl == 0;

AddColumn(ml,"MACD", format = 1.2);
AddColumn(sl,"Signal", format = 1.2);

AddColumn(Close,"Close",1.2);
AddColumn(Volume,"Volume",1.0);
Filter is wrong
 

KelvinHand

Well-Known Member
#5
Dear KelvinHand

Expecting touch of ur expert hand to make the filter correct.

Thanks
When you want to filter ml=0 or sl=0 which means that you want macd() to give you exact zero value OR signal() to give you exact zero value Which this condition exploration is very seldom produce.

In amibroker, condition logic is best to use AND, OR, NOT to reduce mistake

When i give you the hint, I expect you to think how to do it yourself, find out more information in the guide,
Only then you can be expert in writing. Otherwise, wait for other to give you the correct answer
 
Last edited:

Similar threads