MAcross_OpenBarSig

Author: Copyright � 2006, MetaQuotes Software Corp.
MAcross_OpenBarSig

This tool is designed to act as a visual signaling system for traders, identifying specific moments when market momentum shifts. It works by monitoring the relationship between two different moving averages—mathematical lines that smooth out price action to reveal underlying trends.

Core Logic and Mechanics

1. Moving Average Comparison The script tracks two separate moving averages: a "Faster" one (set to 18 periods) and a "Slower" one (set to 28 periods). By comparing these two, the tool identifies when the short-term trend is beginning to move away from or toward the long-term trend.

2. The "Crossover" Detection The primary logic relies on identifying a "crossover" event. This occurs when:

  • Bullish Signal: The faster moving average moves from below the slower average to above it.
  • Bearish Signal: The faster moving average moves from above the slower average to below it.

Rather than just looking at where the lines are currently sitting, the script specifically looks for the moment they intersect, which often signifies a change in market sentiment.

3. Dynamic Visual Positioning To ensure the signals are clearly visible on your chart without cluttering the price candles, the script calculates the "Range" of the market. It looks at the average height of recent price bars (the distance between the highest and lowest points) over a 10-bar period.

It then uses this range to place the visual arrows:

  • Upward Arrows: Placed slightly below the bottom of the price candle.
  • Downward Arrows: Placed slightly above the top of the price candle.

By using this calculation, the script ensures that the markers stay proportional to the current market volatility—meaning they won't appear too far away during low-activity periods or too crowded during high-activity periods.

Summary for the User

When you use this indicator, it acts as a "spotter." It monitors the underlying math of the price movement and places an arrow on your chart exactly when the short-term momentum breaks through the long-term average. This helps traders visually identify potential trend reversals or entries at a glance.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
MAcross_OpenBarSig
//+------------------------------------------------------------------+
//|                                                   18_28Cross.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
//mod2008fxtsd ki   MAcross_OpenBarSig
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//----
double CrossUp[];
double CrossDown[];
extern int FasterMode=1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int FasterMA  =18;
extern int SlowerMode=1; //0=sma, 1=ema, 2=smma, 3=lwma
extern int SlowerMA  =28;
extern int SoundAlert=1; // 0 = disabled
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, CrossUp);
   
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, CrossDown);

   SetIndexEmptyValue(0,EMPTY_VALUE);
   SetIndexEmptyValue(1,EMPTY_VALUE);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
  int start() 
  {
   int limit, i, counter;
   double fasterMAnow, slowerMAnow, fasterMAprevious, slowerMAprevious, fasterMAafter, slowerMAafter;
   double Range, AvgRange;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
//----
   limit=Bars-counted_bars;
     for(i=0; i<=limit; i++) 
     {
      counter=i;
      Range=0;
      AvgRange=0;
      for(counter=i ;counter<=i+9;counter++)
         {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
         }
         Range=AvgRange/10;
      
      fasterMAnow=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i);
      fasterMAprevious=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i+1);
//    fasterMAafter=iMA(NULL, 0, FasterMA, 0, FasterMode, PRICE_CLOSE, i-1);

      slowerMAnow=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i);
      slowerMAprevious=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i+1);
//    slowerMAafter=iMA(NULL, 0, SlowerMA, 0, SlowerMode, PRICE_CLOSE, i-1);
//----
        if ((fasterMAnow > slowerMAnow) && (fasterMAprevious < slowerMAprevious)) 
         {
         CrossUp[i]=Low[i] - Range*0.5 ;
         }
        else if ((fasterMAnow < slowerMAnow) && (fasterMAprevious > slowerMAprevious)) 
         {
         CrossDown[i]=High[i] + Range*0.5;
         }
        else 
         {
         CrossUp[i]   = EMPTY_VALUE;
         CrossDown[i] = EMPTY_VALUE;
         }
  
  
     }
   //----     
   return(0);
  }
//+------------------------------------------------------------------+

Comments