Fruity Pebbles 1.1_v1
Download scriptThis custom indicator is designed to analyze market trends and identify specific entry points by combining two popular technical analysis tools: Moving Averages and the MACD (Moving Average Convergence Divergence) oscillator. Its primary goal is to detect momentum shifts and price action trends to signal potential buying and selling opportunities on your trading chart.
Core Logic Overview
The tool operates by constantly comparing current market data against historical averages to determine the "flow" of the price. It looks for specific alignments between trend direction and momentum velocity.
1. Trend Identification (Moving Averages) The script utilizes an Exponential Moving Average (EMA) to establish the underlying trend. By comparing the current moving average value against a previous value, it determines whether the general market sentiment is trending upward or downward.
2. Momentum Analysis (MACD Oscillator) The indicator monitors the MACD "Main" and "Signal" lines. It calculates the difference between these two lines to measure the strength of the price move. Specifically, it looks for changes in the gap between these lines:
- It tracks whether the momentum is expanding or contracting compared to the previous period.
- It identifies when the momentum crosses specific thresholds to filter out "noise" and focus on significant moves.
3. Signal Generation Logic The script produces visual signals based on a three-part confirmation process:
- State Tracking: The tool maintains an internal "switch" (a state memory). This allows it to understand the current market context before deciding whether to trigger a signal.
- Buy Signals: A potential buy signal is triggered when the momentum gap is positive but decreasing, the price is moving above its moving average, and the internal state confirms a favorable setup. When these conditions align, it marks a point on the chart near the current price.
- Sell Signals: Conversely, a sell signal is triggered when the momentum gap is negative but increasing (moving toward zero), the price is falling below its moving average, and the internal state confirms a bearish setup.
Visual Representation
Instead of complex lines or bars, this script focuses on clarity. It places specific markers (dots) on your chart to highlight exactly where the mathematical conditions for a "Buy" or "Sell" have been met. This allows traders to see clearly where the momentum and trend have synchronized to create a high-probability entry point.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| Custom Moving Average.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Black
//---- indicator parameters
extern double TakeProfit = 1000;
extern double MACDCharttime = 0;
extern double MATrendPeriod= 26;
extern double ShiftFromBar = 0.01;
extern int FastLength = 12;
extern int SlowLength = 26;
extern int MACDLength = 9;
//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtSwitchBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,STYLE_DOT);
SetIndexStyle(1,DRAW_ARROW,STYLE_DOT);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtSwitchBuffer2);
SetIndexEmptyValue(0,0.0);
ArraySetAsSeries(ExtMapBuffer1,true);
ArraySetAsSeries(ExtMapBuffer2,true);
//ArraySetAsSeries(ExtSwitchBuffer2,true);
//SetIndexShift(0, 20);
//SetIndexShift(1, 20);
//---- indicator short name
IndicatorShortName("FRUITWORKS");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int shift, back, lasthighpos, lastlowpos;
double val,res;
double curlow, curhigh,lasthigh,lastlow;
double MacdCurrent, MacdPrevious;
double SignalCurrent, SignalPrevious;
double MaCurrent, MaPrevious;
double MacdDiffy, MacDuff;
int cnt, ticket, total;
int limit;
//if(Bars<900)
// {
// Print("bars less than 900");
// return(0);
// }
SetIndexEmptyValue(0,0.0);
RefreshRates( ) ;
for(shift=(Bars-100); shift>=0; shift--)
{
ExtMapBuffer1[shift] = 0;
ExtMapBuffer2[shift] = 0;
MaCurrent =iMA(NULL,MACDCharttime,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,(shift+0));
MaPrevious=iMA(NULL,MACDCharttime,MATrendPeriod,0,MODE_EMA,PRICE_CLOSE,(shift+4));
MacdCurrent = iMACD(NULL,MACDCharttime,FastLength,SlowLength,MACDLength,PRICE_CLOSE,MODE_MAIN,(shift+0));
MacdPrevious = iMACD(NULL,MACDCharttime,FastLength,SlowLength,MACDLength,PRICE_CLOSE,MODE_MAIN,(shift+1));
SignalCurrent = iMACD(NULL,MACDCharttime,FastLength,SlowLength,MACDLength,PRICE_CLOSE,MODE_SIGNAL,(shift+0));
SignalPrevious = iMACD(NULL,MACDCharttime,FastLength,SlowLength,MACDLength,PRICE_CLOSE,MODE_SIGNAL,(shift+1));
MacdDiffy = (MacdCurrent - SignalCurrent);
MacDuff = (MacdPrevious - SignalPrevious);
ExtSwitchBuffer2[shift] = 0;
//if (shift < Bars)
//{
//ExtSwitchBuffer2[shift] = ExtSwitchBuffer2[shift+1];
//}
if ( ((MacDuff<=0) && (MacdDiffy>=0)) || (ExtSwitchBuffer2[shift+1]==1))
{
ExtSwitchBuffer2[shift] = 1;
}
if (MacdDiffy < -0.00015 && MacdDiffy > MacDuff && MaCurrent >= MaPrevious && ExtSwitchBuffer2[shift] == 1)
{
ExtSwitchBuffer2[shift] = 0;
ExtMapBuffer1[shift] = Open[shift] + ShiftFromBar;
if (shift == 0)
{
ExtMapBuffer1[shift] = Ask + ShiftFromBar;
}
//Comment("SELL : Macd Diff : ",MacdDiffy,":",ExtMapBuffer2[shift]," from current : ",shift);
}
if (MacdDiffy > 0.00015 && MacdDiffy < MacDuff && MaCurrent <= MaPrevious && ExtSwitchBuffer2[shift] == 1)
{
ExtSwitchBuffer2[shift] = 0;
ExtMapBuffer2[shift] = Open[shift] - ShiftFromBar;
if (shift == 0)
{
ExtMapBuffer2[shift] = Bid + ShiftFromBar;
}
//Comment("BUY : Macd Diff : ",MacdDiffy,":",ExtMapBuffer2[shift]," from current : ",shift);
}
//--ExtMapBuffer2[shift]=MacdDiffy;
}
}
Comments