T3MA-ALARM
Download scriptThis tool is designed to act as a visual signaling system for traders, providing real-time alerts on price movements by analyzing the momentum of the market. Instead of looking at simple price changes, the script uses a sophisticated multi-layered calculation to identify specific turning points where the market trend might be shifting.
How the Logic Works
The core of this tool relies on a "moving average of an oscillator." In simpler terms, it doesn't just look at the current price; it calculates the average movement over a specific period (defined by the user) to smooth out the "noise" of minor price fluctuations.
To provide more accurate signals, the script performs several layers of processing:
- Primary Smoothing: It first creates an Exponential Moving Average (EMA), which gives more weight to recent price data.
- Secondary Smoothing: It then applies a second layer of smoothing over that initial average. This ensures that the signals are based on established trends rather than temporary spikes.
- Momentum Comparison: The script compares these smoothed values across different time points. By looking at the difference between the current smoothed value and the previous ones, it determines the "velocity" of the price movement.
Visual Signals and Alerts
The tool translates these complex mathematical calculations into two clear visual cues on your chart:
- Buy Signals (Blue Arrows): When the logic detects that the downward momentum has stalled and is beginning to turn upward, a blue arrow appears. This suggests a potential transition from a bearish trend to a bullish one.
- Sell Signals (Red Arrows): Conversely, when the logic identifies that upward momentum has peaked and is starting to drop, a red arrow appears. This suggests a potential transition from a bullish trend to a bearish one.
Additional On-Screen Information
Beyond the visual arrows, the script provides a live "Comment" section on your screen. This area updates automatically to show:
- Current Trend Direction: It identifies whether the current market environment is trending toward a "Buy" or a "Sell" state based on the most recent calculations.
- Cost Data: It displays the swap rates (overnight fees) for both long and short positions, helping you keep track of the costs associated with holding trades open overnight.
In summary, this tool serves as a trend-following assistant that filters out market noise to highlight specific moments where price momentum changes direction, represented by clear visual markers on your trading chart.
//+------------------------------------------------------------------+
//| T3MA_ALARM.mq4 |
//| Copyright © 2011, Martingeil |
//| fx.09@mail.ru |
//+------------------------------------------------------------------+
//èñïðàâëåííûé Martingeil, òåïåðü ìîæíî â òåñòåðå óâèäåòü åãî ñòðåëêè.
#property copyright "Copyright © 2011, Martingeil"
#property link "fx.09@mail.ru"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- indicator parameters
extern int period = 4; //12
extern int shift = 0; //ñäâèã ïî áàðó
//---- indicator buffers
double BufferUp[],BufferDn[];
int q,st=5;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,2);
SetIndexArrow(0,233);
SetIndexStyle(1,DRAW_ARROW,2);
SetIndexArrow(1,234);
SetIndexBuffer(0,BufferUp);//ñòðåëêà ñèíÿÿ âåðõ
SetIndexBuffer(1,BufferDn);//ñòðåëêà êðàñíàÿ âíèç
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("T3MA-ALARM ("+period+")");
//---- initialization done
if(Digits==3 || Digits==5) q=10;
st=st*q;
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
ObjectDelete("low");
ObjectDelete("high");
}
//+----------------------------------------------------------------------+
//| Moving Average of Oscillator |
//+----------------------------------------------------------------------+
int start()
{
//---- ArraySetAsSeries --------------------------------------------------
double Ma[],MaOn[];
double y0[],y1[],y2[];
// int i;
int i;
ArraySetAsSeries(Ma,true);
//---- IndicatorCounted --------------------------------------------------
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit1=Bars-counted_bars;
if(counted_bars==0) limit1-=1+MathMax(period,shift)+2;
int buffer_size=ArraySize(BufferUp);
ArrayResize(Ma,buffer_size);
ArrayResize(MaOn,buffer_size);
ArrayResize(y0,buffer_size+shift+2);
ArrayResize(y1,buffer_size+shift+2);
ArrayResize(y2,buffer_size+shift+2);
int limit=ArraySize(Ma);
//---- EMA ---------------------------------------------------------------
for(i=limit1; i>=0; i--) Ma[i] =iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
for(i=limit1; i>=0; i--) MaOn[i]=iMAOnArray(Ma,limit,period,0,MODE_EMA,i);
for(i=limit1; i>=0; i--)
{
y0[i+shift]=MaOn[i+shift];
y1[i+1+shift]=MaOn[i+1+shift];
y2[i+2+shift]=MaOn[i+2+shift];
if(y0[i+shift]-y1[i+1+shift]<0 && y1[i+1+shift]-y2[i+2+shift]>0){BufferDn[i+1]=High[i+1]+st*Point;}
if(y0[i+shift]-y1[i+1+shift]>0 && y1[i+1+shift]-y2[i+2+shift]<0){BufferUp[i+1]=Low[i+1]-st*Point;}
//---- Signal Trend Up || Dn ---------------------------------------------
if(y0[i]-y1[i+1]>0) Comment("\n SWAPLONG = ",MarketInfo(Symbol(),MODE_SWAPLONG),
" SWAPSHORT = ",MarketInfo(Symbol(),MODE_SWAPSHORT),"\n BUY TREND ",DoubleToStr(Close[i],Digits));
else if(y0[i]-y1[i+1]<0) Comment("\n SWAPLONG = ",MarketInfo(Symbol(),MODE_SWAPLONG),
" SWAPSHORT = ",MarketInfo(Symbol(),MODE_SWAPSHORT),"\n SELL TREND ",DoubleToStr(Close[i],Digits));
}
//---- done
return(0);
}
//+---------------------------------------------------------------------+
Comments