MACD_CCIobos_mtf_Alert_v1.01
Download scriptThis indicator is designed to provide traders with visual signals by combining two popular technical analysis tools: the MACD (Moving Average Convergence Divergence) and the CCI (Commodity Channel Index). By merging these two indicators, the tool aims to filter out market noise and identify specific momentum shifts across different timeframes.
Core Logic & Functionality
The script monitors the market using a dual-layered confirmation system:
1. Momentum Analysis (MACD) The tool calculates the MACD values based on user-defined fast and slow moving averages. It specifically looks at the direction of the MACD line to determine if the current momentum is rising or falling compared to the previous data point.
2. Overbought/Oversold Filtering (CCI) Simultaneously, the tool tracks the CCI, which measures the price's deviation from its average over a specific period. It looks for instances where the market reaches extreme levels—specifically when it enters "Overbought" or "Oversold" territories.
3. Signal Generation The visual output on your chart is determined by the intersection of these two conditions:
- Bullish Signal (Royal Blue): Triggered when the CCI indicates an overbought/oversold threshold is crossed in a specific direction and the MACD confirms that momentum is moving upward.
- Bearish Signal (Red): Triggered when the CCI reaches its opposite extreme level and the MACD confirms that momentum is moving downward.
- Neutral State (Orange): If neither of the specific bullish or bearish conditions are met, the indicator remains in a neutral state.
Multi-Timeframe Capability
A key feature of this script is its ability to analyze higher timeframes while you are viewing a lower one. This allows you to see the "big picture" trends (e.g., checking daily momentum while looking at a 15-minute chart) without having to manually switch back and forth between different windows.
Automated Alerts
To ensure you don't miss key movements, the script includes an integrated alert system. You can configure it to send a notification whenever the indicator changes color (switching from neutral to a bullish or bearish signal). It also includes a customizable "Shift" setting, allowing you to choose whether the alert triggers on the current live candle or once a previous candle has fully closed to avoid "false" flickering signals.
Summary of User Controls
- Timeframe & Periods: Customize which timeframes to monitor and the sensitivity of both the MACD and CCI calculations.
- Levels: Adjust the Overbought (OB) and Oversold (OS) thresholds to suit different types of assets (Forex, Stocks, or Crypto).
- Visual Positioning: Set a specific level on the chart where the indicator symbols appear to keep your workspace organized.
//+------------------------------------------------------------------+
//| MACD_CCI.mq4 |
//| Copyright © 2009, challenger78 |
//+------------------------------------------------------------------+
//mod mtf
//19.jun.2009 - Add Alert for change color to "RoyalBlue" or "Red" (GF)
//22.jun.2009 - Add alert delay
#property copyright "challenger78"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 RoyalBlue
#property indicator_color2 Red
#property indicator_color3 Orange
#property indicator_minimum 0
#property indicator_maximum 77
extern int TimeFrame=0;
extern int macdMAfast =144; //12
extern int macdMAslow =233; //26;
extern int macdSigMA =21; //9
extern int macdPrice =0;
extern int macdLnMode =0;
extern int CCIperiod = 50;
extern int CCIprice = 5;
extern int cciOBlevel = 100;
extern int cciOSlevel = -100;
extern double BarLevl = 5;
//0main;1signal
extern string MA_Method_Price = "SMA0 EMA1 SMMA2 LWMA3||0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6||macdLnMode:0main 1sig";
extern string TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern int alertSwitch = 1; //0=OFF , 1=ON
extern int alertShift = 0; // 0=change color current Bars, 1=chamge color previous Bar, ....
double buffer1[], buffer2[], buffer3[];
int lastABar;
int init()
{
SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,167); SetIndexBuffer(0,buffer1); SetIndexEmptyValue(0,EMPTY_VALUE);
SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,167); SetIndexBuffer(1,buffer2); SetIndexEmptyValue(1,EMPTY_VALUE);
SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,167); SetIndexBuffer(2,buffer3); SetIndexEmptyValue(2,EMPTY_VALUE);
TimeFrame=MathMax(TimeFrame,Period());
string name1= " macd: "+macdMAfast+","+macdMAslow+","+macdSigMA;
string name2= " cci: " +CCIperiod;
IndicatorShortName("MACDCCI_"+name1+name2+" "+TimeFrame);
return(0);
}
int start()
{
int i,limit;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
limit = Bars - counted_bars;
if(TimeFrame!=Period())
limit = MathMax(limit,TimeFrame/Period());
for (i=limit; i>= 0; i--)
{
int y =iBarShift(NULL,TimeFrame,Time[i]);
double macd0 =iMACD(NULL,TimeFrame,macdMAfast,macdMAslow,macdSigMA,macdPrice,macdLnMode,y);
double macd1 =iMACD(NULL,TimeFrame,macdMAfast,macdMAslow,macdSigMA,macdPrice,macdLnMode,y+1);
double cci =iCCI (NULL,TimeFrame,CCIperiod,CCIprice,y);
buffer1[i]=EMPTY_VALUE; buffer2[i]=EMPTY_VALUE; buffer3[i]=EMPTY_VALUE;
if (cci > cciOBlevel && macd0 > macd1 ) buffer1[i] = BarLevl;
else
if (cci < cciOSlevel && macd0 < macd1 ) buffer2[i] = BarLevl;
else buffer3[i] = BarLevl;
}
if (alertSwitch == 1 && Bars > lastABar) {
if (buffer1[alertShift] != EMPTY_VALUE && buffer1[alertShift+1] == EMPTY_VALUE) {
Alert(Symbol(), " Indicator MACD_CCI OBOS change color (bar-",alertShift,") to 'color0'");
lastABar = Bars;
}
if (buffer2[alertShift] != EMPTY_VALUE && buffer2[alertShift+1] == EMPTY_VALUE) {
Alert(Symbol(), " Indicator MACD_CCI OBOS change color (bar-",alertShift,") to 'color1'");
lastABar = Bars;
}
}
return(0);
}
Comments