MACD Crossover - Multiple Timeframe-HELP REQUESTED

#1
Dear Senior Members

I'm trying to EXPLORE stocks for which MACD Fast Avg HAS CROSSED OVER Slow Average for MULTIPLE TIMEFRAMES, say for example 5Min, Hourly, Daily, Weekly, etc.
Following is the code which is NOT working right for me (checked for Hourly status for ABIRLANUVO, for example, where the Daily and Hourly MACD are generating wrong signals.

Basically, I want to EXPLORE as BUY / SELL stocks for MACD Exploration where ALL (5Min, 60Min/Hourly, Daily, Weekly) have had a Fast MACD Crossover the SLOW MACD @8,18 setting......

Requesting EXPERTS to correct the code please.....

Here is the code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 8, 2, 200, 1 );
r2 = Param( "Slow avg", 18, 2, 200, 1 );
r3 = Param( "Signal avg", 6, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);

MACD_Buy= ml > sl;
MACD_Sell= sl > ml;

TimeFrameSet( in5Minute );
MACD_Buy_5Min= ml > sl;
MACD_Sell_5Min= sl > ml;

TimeFrameExpand(MACD_Buy_5Min,in5Minute);

wnArrow, colorGreen );

TimeFrameSet( inHourly );
m_Hourly = MACD(8, 18 ); // MACD from Hourly data
MACD_Buy_Hourly= ml > sl;
MACD_Sell_Hourly= sl > ml;

TimeFrameExpand(MACD_Buy_5Min,inHourly);


TimeFrameSet( inDaily );
MACD_Buy_Daily= ml > sl;
MACD_Sell_Daily= sl > ml;
TimeFrameExpand(MACD_Buy_5Min,inDaily);


TimeFrameSet( inWeekly );
MACD_Buy_Weekly= ml > sl;
MACD_Sell_Weekly= sl > ml;
TimeFrameExpand(MACD_Buy_5Min,inWeekly);

MACD_AllPeriod_Buy= IIf((MACD_Buy_5min AND MACD_Buy_Hourly AND MACD_Buy_Daily AND MACD_Buy_Weekly)==True, 1, 0) ;
MACD_AllPeriod_Sell= IIf((MACD_Sell_5min AND MACD_Sell_Hourly AND MACD_Sell_Daily AND MACD_Sell_Weekly)==True, 1, 0) ;





AddColumn(Close,"Close");
AddColumn(MACD_AllPeriod_Buy,"MACD All Buy", format = 1.2, IIf(MACD_AllPeriod_Buy == True, Textcolor = colorBlue, textcolor = colorWhite));

AddColumn(MACD_AllPeriod_Sell,"MACD All Sell", format = 1.2, IIf(MACD_AllPeriod_Sell == True, Textcolor = colorBlue, textcolor = colorWhite));


Filter= MACD_AllPeriod_Buy OR MACD_AllPeriod_Sell;


warm regards...RB
 
#3
Hi Colion

You are Right....EXTREMELY Sorry....God knows how this code came in and from where :(

Here is the same code without that line

*********************************************************
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();


_SECTION_BEGIN("MACD");
r1 = Param( "Fast avg", 8, 2, 200, 1 );
r2 = Param( "Slow avg", 18, 2, 200, 1 );
r3 = Param( "Signal avg", 6, 2, 200, 1 );
ml = MACD(r1, r2);
sl = Signal(r1,r2,r3);

MACD_Buy= ml > sl;
MACD_Sell= sl > ml;

TimeFrameSet( in5Minute );
MACD_Buy_5Min= ml > sl;
MACD_Sell_5Min= sl > ml;

TimeFrameExpand(MACD_Buy_5Min,in5Minute);



TimeFrameSet( inHourly );
m_Hourly = MACD(8, 18 ); // MACD from Hourly data
MACD_Buy_Hourly= ml > sl;
MACD_Sell_Hourly= sl > ml;

TimeFrameExpand(MACD_Buy_5Min,inHourly);


TimeFrameSet( inDaily );
MACD_Buy_Daily= ml > sl;
MACD_Sell_Daily= sl > ml;
TimeFrameExpand(MACD_Buy_5Min,inDaily);


TimeFrameSet( inWeekly );
MACD_Buy_Weekly= ml > sl;
MACD_Sell_Weekly= sl > ml;
TimeFrameExpand(MACD_Buy_5Min,inWeekly);

MACD_AllPeriod_Buy= IIf((MACD_Buy_5min AND MACD_Buy_Hourly AND MACD_Buy_Daily AND MACD_Buy_Weekly)==True, 1, 0) ;
MACD_AllPeriod_Sell= IIf((MACD_Sell_5min AND MACD_Sell_Hourly AND MACD_Sell_Daily AND MACD_Sell_Weekly)==True, 1, 0) ;





AddColumn(Close,"Close");
AddColumn(MACD_AllPeriod_Buy,"MACD All Buy", format = 1.2, IIf(MACD_AllPeriod_Buy == True, Textcolor = colorBlue, textcolor = colorWhite));

AddColumn(MACD_AllPeriod_Sell,"MACD All Sell", format = 1.2, IIf(MACD_AllPeriod_Sell == True, Textcolor = colorBlue, textcolor = colorWhite));


Filter= MACD_AllPeriod_Buy OR MACD_AllPeriod_Sell;

*********************************************************
Warm regards...RB
 
#4
Dear Experts

Requesting your assistance to make the necessary corrections in the AFL given in the earlier post, for multiple MACD timeframe crossover....

warm regards...RB
 
#6
The Lord,

Thank you for the same. Infact, I had already visited this page just yesterday night. But, unfortunately, this is not what I am looing for ..... :(

Thanks, anyway.

warm regards..RB
 
#7
Hey Guys,
I've managed to do this myself :thumb:. Thanks to The Lord, who suggested a page. That page was not useful. But I should admit that I got an idea of what to do....then googled for mutlipletimeframe option and with a lot of trial and error, managed to get what I wanted.....
Thanks The Lord...that hint of yours was really encouraging....
warm regards...RB
 
#10
from last one week i am trying below manual formula but if someone help me for correct AFL of this and sucess rate info as per back test report. my buy and sell signal is in 5 min crossover.
1587733657433.png
 

Similar threads