ma_2MAGoodCooked

Download script
Author: MainCook: Integer
ma_2MAGoodCooked

This indicator is designed to help traders identify trend reversals by monitoring the relationship between two Moving Averages (MA) and analyzing specific price fluctuations. Instead of just showing general momentum, it focuses on identifying "pullbacks" or temporary corrections before a trend resumes.

Core Logic Overview

The tool operates by comparing a Fast Moving Average against a Slow Moving Average. The primary goal is to detect moments when the market price moves away from the established trend and then signals a potential return to that trend.

1. Trend Identification

The script first establishes the overall market direction:

  • If the Fast MA is above the Slow MA, the current environment is considered bullish (upward).
  • If the Fast MA is below the Slow MA, the environment is considered bearish (downward).

2. Reversal and Pullback Detection

The logic specifically looks for "hooks" or "turns" in the Fast Moving Average line. It identifies three specific conditions to trigger a signal:

  • The Cross: It detects when the Fast MA crosses over the Slow MA, establishing the base trend.
  • The Retracement (The Pullback): The script looks for instances where the Fast MA moves against its own momentum—essentially a temporary dip in an uptrend or a temporary rally in a downtrend.
  • The Confirmation: To prevent false signals, the script uses a "Two Bar" logic. It checks if the Moving Average has formed a specific "V" or "inverted V" shape over recent bars. It ensures that the move is not just noise but a distinct structural change where the average begins to turn back in favor of the primary trend.

3. Signal Visuals

The indicator provides clear visual feedback on the chart to distinguish between different types of movements:

  • Primary Signals: These appear when the script detects the initial shift or the specific "turn" in the trend following a pullback.
  • Secondary Signals (First Occurrence): The logic includes a counter system to identify unique instances. It can highlight the very first time a specific reversal pattern occurs after a period of consolidation, helping traders distinguish between a primary entry and a continuation of an existing move.

Summary for the Trader

Essentially, this tool filters out the "choppiness" of the market. Rather than giving a signal every time the price moves up or down, it waits for the market to establish a trend, experience a brief correction (pullback), and then provide a visual confirmation that the original trend is resuming. It is built to help you find entries where the momentum is returning to the main direction of the market.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
ma_2MAGoodCooked

/*
   Âõîä íà âîññòàíîâëåíèè òðåíäà ïîñëå îòêàòà íà 2 ÌÀ. 
*/


#property copyright "MainCook: Integer"
#property link      "for-good-letters@yandex.ru"



#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
#property indicator_color3 DeepSkyBlue
#property indicator_color4 Red
#property indicator_color5 DeepSkyBlue
#property indicator_color6 Red
#property indicator_color7 Yellow

#property indicator_width3 0
#property indicator_width4 0
#property indicator_width5 1
#property indicator_width6 1

//---- input parameters
extern int FastMAPeriod=21;   // Ïåðèîä áûñòðîé ÌÀ
extern int FastMAMethod=1;    // Ìåòîä áûñòðîé ÌÀ: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA
extern int FastMAPrice=0;     // Öåíà áûñòðîé ÌÀ: 0-Close, 1-Open, 2-High, 3-Low, 4-Median, 5-Typical, 6-Weighted
extern int SlowMAPeriod=34;   // Ïåðèîä ìåäëåííîé ÌÀ   
extern int SlowMAMethod=1;    // Ìåòîä ìåäëåííîé ÌÀ: 0-SMA, 1-EMA, 2-SMMA, 3-LWMA
extern int SlowMAPrice=0;     // Öåíà ìåäëåííîé: ÌÀ 0-Close, 1-Open, 2-High, 3-Low, 4-Median, 5-Typical, 6-Weighted
extern bool TwoBar=true;      // Ïðîâåðÿòü ïåðåãèá ÌÀ ïî äâóì áàðàì (ñëåâà îò ýêñòðåìóìà, ñïðàâà âñåãäà ïî îäíîì áàðó)

//---- buffers
double fma[];
double sma[];
double buy[];
double sell[];
double buy1[];
double sell1[];
double close[];
double cnt[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

   IndicatorBuffers(8);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,fma);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,sma);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexArrow(2,225);
   SetIndexBuffer(2,buy);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexArrow(3,226);
   SetIndexBuffer(3,sell);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(4,233);
   SetIndexBuffer(4,buy1);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexArrow(5,234);
   SetIndexBuffer(5,sell1);

   SetIndexStyle(6,DRAW_ARROW);
   SetIndexArrow(6,251);   
   SetIndexBuffer(6,close);
   SetIndexBuffer(7,cnt);
   
   SetIndexLabel(0,"Fast MA");
   SetIndexLabel(1,"Slow MA");
   SetIndexLabel(2,"");
   SetIndexLabel(3,"");
   SetIndexLabel(4,"");
   SetIndexLabel(5,"");   
   SetIndexLabel(6,"");   
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
         int limit=Bars-IndicatorCounted();

            for(int i=limit-1;i>=0;i--){
               buy[i]=EMPTY_VALUE;
               sell[i]=EMPTY_VALUE;
               fma[i]=iMA(NULL,0,FastMAPeriod,0,FastMAMethod,FastMAPrice,i);
               sma[i]=iMA(NULL,0,SlowMAPeriod,0,SlowMAMethod,SlowMAPrice,i);
               cnt[i]=cnt[i+1];
               buy1[i]=EMPTY_VALUE;
               sell1[i]=EMPTY_VALUE;               
               close[i]=EMPTY_VALUE;
                  if(fma[i]>sma[i]){
                           
                           if(fma[i+1]<=sma[i+1]){
                              close[i]=Low[i]-Point*5;
                           }
                  
                           if(fma[i+3]>fma[i+2] || !TwoBar){
                              if(fma[i+2]>fma[i+1]){
                                 if(fma[i+1]<fma[i]){
                                       buy[i]=Low[i]-Point*5;
                                          if(cnt[i]<0){
                                             cnt[i]=0;
                                          }
                                       cnt[i]++;
                                          if(cnt[i]==1){
                                             buy1[i]=Low[i]-Point*5;
                                          }
                                 }
                              }
                           }
                  }
                  
                  if(fma[i]<sma[i]){
                  
                           if(fma[i+1]>=sma[i+1]){
                              close[i]=High[i]+Point*5;
                           }                  
                  
                           if(fma[i+3]<fma[i+2] || !TwoBar){
                              if(fma[i+2]<fma[i+1]){
                                 if(fma[i+1]>fma[i]){
                                       sell[i]=High[i]+Point*5;    
                                          if(cnt[i]>0){
                                             cnt[i]=0;
                                          }           
                                       cnt[i]--;     
                                          if(cnt[i]==-1){
                                             sell1[i]=High[i]+Point*5;  
                                          }                                                                 
                                 }
                              }   
                           }               
                  }
               
            }
   return(0);
  }
//+------------------------------------------------------------------+

Comments