Author: MNS
Q(Sig0)

This trading indicator is designed to identify specific entry points in the market by analyzing price momentum and structural trends. It combines two primary technical tools—the Commodity Channel Index (CCI) and the ZigZag indicator—to filter out market noise and highlight significant reversals.

Core Analytical Logic

The script operates by monitoring three distinct layers of market behavior:

1. Momentum Filtering (CCI) The tool uses the Commodity Channel Index to measure whether an asset is overbought or oversold relative to its average price. It specifically looks for "breakout" moments where the momentum shifts from one extreme to another. Instead of just following a trend, it waits for the momentum to cross specific predefined thresholds (Buy and Sell levels), indicating that a price movement has reached a point of exhaustion or significant shift.

2. Structural Confirmation (ZigZag) To ensure that the signals are not triggered by minor fluctuations, the script integrates logic from the ZigZag indicator. This helps the system recognize the primary "peaks" and "valleys" of the market structure. The script looks for these structural points to confirm that a price move is part of a larger trend change rather than a temporary spike.

3. Dynamic Range Calculation The indicator calculates the average price range (the distance between the highest and lowest prices) over a rolling window of 10 bars. It uses this data to determine the "offset" for the visual signals. This ensures that the arrows appear at a consistent, proportional distance from the candles, regardless of whether the market is currently experiencing high or low volatility.

Signal Generation

The script generates two types of signals:

  • Bullish Signals (Buy): Triggered when the momentum moves upward past the Buy Level, the current closing price exceeds the previous candle's high, and a structural point from the ZigZag is detected. When these conditions align, a "Buy" signal is plotted below the candle.
  • Bearish Signals (Sell): Triggered when the momentum drops below the Sell Level, the current closing price falls below the previous candle's low, and a structural point is confirmed. A "Sell" signal is then plotted above the candle.

Execution Flow

To maintain clarity and prevent repetitive signals, the script includes a "flag" system. Once a Buy signal is triggered, it will ignore further Buy signals until a Sell condition is met, and vice versa. This ensures that the indicator identifies distinct trend shifts rather than cluttering the chart with multiple signals during a single move.

Indicators Used
Commodity channel index
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
Q(Sig0)
//+------------------------------------------------------------------+
//| Web:                                                 Q(Sig0).mq4 |
//|                                                              MNS |
//|                                                mns777.ru@mail.ru |
//+------------------------------------------------------------------+
#property copyright "MNS"
#property link      "Web:" 
//---- Îïðåäåëåíèå èíäèêàòîðîâ
#property indicator_chart_window
#property indicator_buffers 8
//---- Öâåòà
     
#property indicator_color7 Gold
#property indicator_color8 Gold
//---- òîëùèíà èíäèêàòîðíûõ ëèíèé
#property indicator_width7 2
#property indicator_width8 2

//---- Ïàðàìåòðû
//----Q1
extern int PeriodCCI = 14 ;
extern int PriceCCI = 5;
extern int BuyLevel = -100 ;
extern int SellLevel = 100 ;
//----Q2
extern int ExtDepth=12;
extern int ExtDeviation=5;
extern int ExtBackstep=3;



extern double NormalizeAccuracy = 0.0000;


//---- Áóôåðû
double Q1[];
double Q2[];
double Q3[];
double Q4[];
double Q5[];
double Q6[];
double CrossUp[];
double CrossDown[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
  //---- Óñòàíîâêà ïàðàìåòðîâ ïðîðèñîâêè
  //     Q
  SetIndexStyle( 0, DRAW_NONE );
  SetIndexStyle( 1, DRAW_NONE );
  SetIndexStyle( 2, DRAW_NONE );
  SetIndexStyle( 3, DRAW_NONE );
  SetIndexStyle( 4, DRAW_NONE );
  SetIndexStyle( 5, DRAW_NONE );
  
  //     Ñèãíàëû
  SetIndexStyle( 6, DRAW_ARROW, EMPTY );
  SetIndexArrow( 6, 241 );
  SetIndexStyle( 7, DRAW_ARROW, EMPTY );
  SetIndexArrow( 7, 242 );
  //---- Çàäàíèå áóôåðîâ
  SetIndexBuffer( 0, Q1    );
  SetIndexBuffer( 1, Q2    );
  SetIndexBuffer( 2, Q3    );
  SetIndexBuffer( 3, Q4    );
  SetIndexBuffer( 4, Q5    );
  SetIndexBuffer( 5, Q6    );
  SetIndexBuffer( 6, CrossUp   );
  SetIndexBuffer( 7, CrossDown );
  
  IndicatorDigits( MarketInfo( Symbol(), MODE_DIGITS ) );
  
  //---- Íàçâàíèå è ìåòêè
  IndicatorShortName( "Q(Sig0)" );
  SetIndexLabel( 0, NULL  );
  SetIndexLabel( 1, NULL );
  SetIndexLabel( 2, NULL   );
  SetIndexLabel( 3, NULL  );
  SetIndexLabel( 4, NULL   );
  SetIndexLabel( 5, NULL  );
  SetIndexLabel( 6, NULL  );
  SetIndexLabel( 7, NULL  );
  
  return ( 0 );
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
  static bool bBuy  = False;
  static bool bSell = False;
    
  bool   bConditionUp;
  bool   bConditionDown;
  double Range;
  double AvgRange;
  int    iLimit;
  int    i;
  int    counter;
  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--;
  
  iLimit = Bars - counted_bars;
  
  for ( i = 0; i <= iLimit; i++ ) {
    Q1[i] = iCCI(NULL,0,PeriodCCI,PriceCCI,i);
    Q2[i] = iCustom(NULL,0,"ZigZag",ExtDepth, ExtDeviation,ExtBackstep,0,i);
    Q3[i] = 0;
    Q4[i] = 0;
    Q5[i] = 0;
    Q6[i] = 0;
  } 
  
  for ( i = 1; i <= iLimit; i++ ) {
    AvgRange = 0;
    for ( counter = i; counter <= i + 9; counter++ ) {
      AvgRange += MathAbs( High[ counter ] - Low[ counter ] );
    }
    Range = AvgRange/10;
    
    /*if ( i == 0 ) {
      bConditionUp   = ( FastMA[i  ] > SlowMA[i  ] ) &&
                       ( FastMA[i+1] < SlowMA[i+1] ); // ïåðåñå÷åíèå ââåðõ 
      bConditionDown = ( FastMA[i  ] < SlowMA[i  ] ) &&
                       ( FastMA[i+1] > SlowMA[i+1] ); // ïåðåñå÷åíèå âíèç
    }
    else {*/
      bConditionUp   = (Q1[i] > BuyLevel )&&  
                       (Q1[i+1] < BuyLevel )&& 
                       (Close[i] > High[i+1] ) &&
                       ( Q2[i+1] != 0 )&&                     
                              
                                                  
                                                                
                       ( NormalizeDouble(Q1[i]-Q1[i+1],4)>=NormalizeAccuracy);
                       
      bConditionDown =  (Q1[i] < SellLevel )&&  
                       (Q1[i+1] > SellLevel )&&
                       (Close[i] < Low[i+1] ) &&
                       ( Q2[i+1] != 0 )&&
                           
                         
                       
                       
                       
                       ( NormalizeDouble(Q1[i+1]-Q1[i],4)>=NormalizeAccuracy);
    //} 
    
    
                       
                       
    
      if ( bConditionUp )
    CrossUp[i] = Low[i] - Range * 0.5;
    else if ( bConditionDown )
    CrossDown[i] = High[i] + Range * 0.5;
    
    if ( !bBuy && bConditionUp ) {
      // Ôëàãè
      bBuy  = True;  // óñòàíîâêà ôëàãà ïîêóïêè
      bSell = False; // ñáðîñ ôëàãà ïðîäàæè
      
     
       
      
    }
    else if ( !bSell && bConditionDown ) {
      // Ôëàãè
      bSell = True;  // óñòàíîâêà ôëàãà ïðîäàæè
      bBuy  = False; // ñáðîñ ôëàãà ïîêóïêè
      
     
       
    } 
  } 
 return ( 0 );
}

Comments