LOCSignal-MACDDoublePike
Download scriptThis script is a specialized technical analysis tool designed to identify specific momentum shifts in the financial markets. It automates the process of recognizing complex patterns within the MACD (Moving Average Convergence Divergence) indicator, which is commonly used by traders to determine whether a market trend is gaining strength or losing steam.
Core Logic and Methodology
The primary objective of this tool is to filter out "noise" and focus on significant price reversals. Instead of simply looking for a basic crossover, the logic identifies what it calls a "Double Pike." This requires several layers of conditions to be met simultaneously before a signal is displayed on your chart:
- Momentum Direction: The script analyzes the relationship between the main momentum line and its historical values over multiple price candles. It specifically looks for a "V" or inverted "V" shape, where the momentum moves in one direction and then sharply reverses while remaining on a specific side of the zero line (the baseline).
- Consecutive Trend Validation: To ensure the signal isn't just a temporary flicker, the logic verifies a sequence of historical data points. It checks that previous price bars followed a distinct, consistent path, ensuring that the current "spike" is significant enough to warrant a signal.
- Signal Verification (Pike Detection): The script includes a secondary internal verification process. This "Pike Detection" scans backward through historical data to confirm that the momentum change aligns with specific signal line requirements. It ensures that the relationship between the main momentum and the signal average is consistent with an actual trend shift rather than just random price volatility.
Visual Execution
Once the script confirms that all these mathematical conditions are met—meaning the momentum has hit a specific point of reversal and validated its trajectory against historical data—it places visual markers on your trading chart:
- Buy Signals: These appear as arrows positioned slightly below the low of the price candle, indicating a potential upward move.
- Sell Signals: These appear as arrows positioned slightly above the high of the price candle, indicating a potential downward move.
Key Technical Characteristics
- Automated Filtering: The tool automatically handles the complex math of comparing multiple previous candles (P1 through P4) so you don't have to manually calculate these trends.
- Dynamic Adjustment: The script is designed to work across different types of currency pairs and assets by automatically adjusting its visual spacing based on the number of decimal places in the price (e.g., standard 4 or 5-digit brokers).
- Stability: By requiring a minimum amount of historical data before it begins calculating, the tool ensures that signals are grounded in established market context rather than insufficient information.
//+---------------------------------------------------------------------+
//| LOCSignal-MACDDoublePike.mq4 |
//| For more EXPERTS, INDICATORS, TRAILING EAs and SUPPORT Please visit:|
//| http://www.landofcash.net |
//| Our forum is at: http://forex-forum.landofcash.net |
//+---------------------------------------------------------------------+
#property copyright "Mikhail LandOfCash"
#property link "http://www.landofcash.net"
#property indicator_chart_window
#property indicator_buffers 3
//Buy signal
#property indicator_color1 OrangeRed
#property indicator_width1 1
#property indicator_style1 STYLE_SOLID
//Sell signal
#property indicator_color2 OrangeRed
#property indicator_width2 1
#property indicator_style2 STYLE_SOLID
//Lot size
#property indicator_color3 CLR_NONE
#property indicator_width3 0
string _name = "LOCSignal-MACDDoublePike";
string _ver="v1.0";
//---------------------------------------------
//indicator parameters
int _fastEmaPeriod=24;
int _slowEmaPeriod=52;
int _signalPeriod =9;
int _appliedPrice =PRICE_CLOSE;
//lot size is constant
double _lotSizeDefault=0;
//---------------------------------------------
double _buySignal[];
double _sellSignal[];
double _lotSize[];
double _pipsMultiplyer=1;
int init()
{
Print(_name+" - " + _ver);
IndicatorShortName(_name+" - " + _ver);
Comment(_name+" " + _ver+" @ "+"http://www.landofcash.net");
_lotSizeDefault=MarketInfo(Symbol(),MODE_MINLOT);
//init buffers
IndicatorBuffers(3);
SetIndexBuffer(0,_buySignal);
SetIndexBuffer(1,_sellSignal);
SetIndexBuffer(2,_lotSize);
//set draw style
SetIndexStyle(0,DRAW_ARROW);
SetIndexStyle(1,DRAW_ARROW);
SetIndexStyle(2,DRAW_NONE);
SetIndexLabel(0,"Buy");
SetIndexLabel(1,"Sell");
SetIndexLabel(2,"Lot");
SetIndexArrow(0,233);
SetIndexArrow(1,234);
//get pip value
if(Digits == 2 || Digits == 4) {
_pipsMultiplyer = 1;
} else {
if(Digits == 3 || Digits == 5) {
_pipsMultiplyer = 10;
}
}
return(0);
}
int deinit()
{
return(0);
}
int start()
{
double visualAddition= 3*_pipsMultiplyer*Point;
int counted_bars=IndicatorCounted();
if(Bars<=100) {return(0);}
int i=Bars-counted_bars-1;
while(i>=0)
{
_buySignal[i]=EMPTY_VALUE;
_sellSignal[i]=EMPTY_VALUE;
_lotSize[i]=_lotSizeDefault;
double macdMain=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i);
double macdMainP1=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i+1);
double macdMainP2=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i+2);
double macdMainP3=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i+3);
double macdMainP4=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i+4);
double macdSignal=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_SIGNAL,i);
double pikeP=0;
//macd neg pike
if( macdMain>macdMainP1 && macdMainP2>macdMainP1 && macdMain<0){
if(macdMainP1<macdMainP2 && macdMainP2<macdMainP3 && macdMainP3<macdMainP4){
pikeP=PikeDetect(i+4);
if(pikeP<0/* && pikeP<macdMainP1*/){
_buySignal[i]=iLow(Symbol(),Period(),i)-visualAddition;
}
}
}
//macd pike
if( macdMain<macdMainP1 && macdMainP2<macdMainP1 && macdMain>0){
if(macdMainP1>macdMainP2 && macdMainP2>macdMainP3 && macdMainP3>macdMainP4){
pikeP=PikeDetect(i+4);
if(pikeP>0 /*&& pikeP>macdMainP1*/){
_sellSignal[i]=iHigh(Symbol(),Period(),i)+visualAddition;
}
}
}
i--;
}
return(0);
}
double PikeDetect(int i){
bool signalGood=false;
double macdLast=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i);
while(i<=Bars-2)
{
double macdMain=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i);
double macdMainP1=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i+1);
double macdMainP2=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_MAIN,i+2);
double macdSignal=iMACD(Symbol(),Period(),_fastEmaPeriod,_slowEmaPeriod,_signalPeriod,_appliedPrice,MODE_SIGNAL,i);
if((macdMain>0 && macdLast<0)||(macdMain<0 && macdLast>0)){
return(0);
}
if(macdLast<0 && macdSignal<macdMain){
signalGood=true;
}
if(macdLast>0 && macdSignal>macdMain){
signalGood=true;
}
if(macdLast<0 && macdMain>macdMainP1 && macdMainP2>macdMainP1 && macdMain<0 && signalGood){
return (macdMainP1);
}
if(macdLast>0 && macdMain<macdMainP1 && macdMainP2<macdMainP1 && macdMain>0 && signalGood){
return (macdMainP1);
}
i++;
}
return (0);
}
Comments