fxprime_v231

Download script
fxprime_v231

This technical indicator is designed to identify high-probability trading opportunities by analyzing price momentum, trend direction, and volatility. It functions by synthesizing multiple market "filters" to ensure that a signal is only generated when several different conditions align simultaneously.

The logic can be broken down into four primary analytical components:

1. Trend Direction and Slope (EMA Angle)

The script measures the steepness of an Exponential Moving Average (EMA). Rather than just looking at whether the average is going up or down, it calculates the specific "angle" of the movement over a set number of bars.

  • Bullish Momentum: A positive angle above a specific threshold signals a strong upward push.
  • Bearish Momentum: A negative angle below a specific threshold signals a strong downward push.
  • Neutrality: If the angle is too flat, the script considers the market sideways and filters out potential trades.

2. Momentum and Overbought/Oversold Analysis (CCI & RSI)

The indicator uses two different momentum oscillators to confirm the strength of the price move:

  • Commodity Channel Index (CCI): It compares current price levels against a long-term average to see if the market is moving significantly faster than usual. It checks for specific "crosses" where the momentum breaks out of neutral zones into active trading territory.
  • Relative Strength Index (RSI): This acts as a secondary confirmation to ensure that the price isn't just moving fast, but is also maintaining relative strength in its current direction.

3. Volatility and Flow Tracking (ADX)

To avoid entering "fake-out" moves where the market lacks enough volume or energy, the script incorporates an ADX (Average Directional Index) check. This helps determine if a trend is actually gaining strength. It specifically looks for instances where the directional flow (Positive vs. Negative) is dominant and exceeding a minimum threshold of intensity.

4. Signal Execution and Alerts

When all of the above conditions—Trend Angle, Momentum, and Volatility—align, the script triggers specific visual markers:

  • Buy Signals: Generated when there is a strong positive EMA angle, high CCI momentum, positive RSI strength, and active ADX flow.
  • Sell Signals: Generated when there is a strong negative EMA angle, low CCI momentum, negative RSI strength, and active downward ADX flow.
  • Exit Signals: The script also monitors for "cross-overs" in the momentum indicators that suggest the current trend is exhausting, providing an alert to consider closing a position.

Summary of Operation

Essentially, this tool acts as a multi-layered filter. It requires the market to be moving with enough "slope" (EMA Angle), enough "speed" (CCI/RSI), and enough "power" (ADX) before it provides a visual signal or alert to the user. This prevents the user from entering trades in choppy, flat, or weak markets.

Indicators Used
Relative strength indexCommodity channel indexMovement directional indexMoving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
7 Views
0 Downloads
0 Favorites
fxprime_v231
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 6

/*
#property indicator_minimum -100
#property indicator_maximum 100
*/
#property  indicator_color1  LimeGreen
#property  indicator_color2  Yellow
#property  indicator_color3  FireBrick
#property  indicator_color4  LightGreen
#property  indicator_color5  Tomato
#property  indicator_color6  LightSlateGray

#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 2

//---- indicator parameters
extern int       rsi_period=8;
extern int       rsi_price=PRICE_CLOSE;
extern bool      chk_rsi = true;

extern     bool      check_ema_angle = true;
extern     bool      enablealertbuy = true;
extern     bool      enablealertsell = true;
extern     bool      enablealertexit = true;
extern     bool      alertpair = true;
extern     bool      display_fxprime_short = true;
extern     bool      display_fxprime_long = true;
extern     bool      display_fxprime_exit = true;

extern     int       indicator_period = PERIOD_M1;
extern     int       previous_shift = 1;
extern     int       cci_period = 34;
extern     int       long_period = 170;
extern     int       short_rsi = 8;
extern     int       long_rsi = 14;
extern     int       filter_out_cci = 5;
extern     double    filter_out_long = 165;
extern     double    filter_out_short = -165;

extern     double    exit_cci_cross_long = 0;
extern     double    exit_cci_cross_short = 0;
extern     double    long_rsi_cross = 55;
extern     double    short_rsi_cross = 45;

extern     double    small_long_cci_cross = 30;
extern     double    small_short_cci_cross = -30;
extern     double    large_long_cci_cross = 25;
extern     double    large_short_cci_cross = -25;
extern     int       sto_K = 5;
extern     int       sto_D = 3;
extern     int       sto_S = 3;
extern     int       adx_period = 20;
extern     double    adx_level = 15;
extern     bool      chk_adx = false;
extern     int       cci_price = PRICE_TYPICAL;

// ---------- ema angle settings
extern     int       ea_EMAPeriod=34;
extern     double    ea_AngleTreshold=0.3;
extern     int       ea_StartEMAShift=6;
extern     int       ea_EndEMAShift=0;
extern     bool      display_ema_angle = false;

extern     string    alertbuymsg = "#fxprime BUY (Canadian dude says: happy pippin')";
extern     string    alertsellmsg = "#fxprime SELL (Canadian dude says: happy pippin')";
extern     string    alertexitmsg = "#fxprime EXIT";

extern int EMAPeriod=34;
extern double AngleTreshold=0.3;
extern int StartEMAShift=6;
extern int EndEMAShift=0;

//---- indicator buffers
double UpBuffer[];
double DownBuffer[];
double ZeroBuffer[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];

#define pos                50
#define shortmul           -1
#define SPACE              " "
#define IND_LONG_SYMBOL    110
#define IND_SHORT_SYMBOL   110
#define IND_EXIT_SYMBOL    159
#define OP_NEUTRAL         -1
#define EMPTY_LEVEL        -200
#define SIG_LEVEL          0.2
#define EXT_LEVEL          -0.2

#define OP_EXIT            -100
#define PI                 3.14159
#define PIDEGREES          180.0


datetime buytime;
datetime selltime;
datetime exittime;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   int emaa_draw = DRAW_HISTOGRAM;
   if (!display_ema_angle) emaa_draw = DRAW_NONE;
   IndicatorBuffers(6);
   SetIndexStyle(0,emaa_draw,STYLE_SOLID,2);
   SetIndexStyle(1,emaa_draw,STYLE_SOLID,2);
   SetIndexStyle(2,emaa_draw,STYLE_SOLID,2);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);

   SetIndexBuffer(0,UpBuffer);
   SetIndexBuffer(1,DownBuffer);
   SetIndexBuffer(2,ZeroBuffer);
   
   int draw_fxprime;
   
   draw_fxprime = DRAW_ARROW;
   if (!display_fxprime_long) draw_fxprime = DRAW_NONE;
   SetIndexStyle(3,draw_fxprime);
   SetIndexArrow(3,IND_LONG_SYMBOL);
   SetIndexBuffer(3,ExtMapBuffer5);
   SetIndexEmptyValue(3,EMPTY_LEVEL);

   draw_fxprime = DRAW_ARROW;
   if (!display_fxprime_short) draw_fxprime = DRAW_NONE;   
   SetIndexStyle(4,draw_fxprime);
   SetIndexArrow(4,IND_SHORT_SYMBOL);
   SetIndexBuffer(4,ExtMapBuffer6);
   SetIndexEmptyValue(4,EMPTY_LEVEL);

   draw_fxprime = DRAW_ARROW;
   if (!display_fxprime_exit) draw_fxprime = DRAW_NONE;
   SetIndexStyle(5,draw_fxprime);
   SetIndexArrow(5,IND_EXIT_SYMBOL);
   SetIndexBuffer(5,ExtMapBuffer7);
   SetIndexEmptyValue(5,EMPTY_LEVEL);
   
   ShowCopyright();

   return(0);
}
//+------------------------------------------------------------------+
//| The angle for EMA                                                |
//+------------------------------------------------------------------+
int start()
{
   double fEndMA, fStartMA;
   double fAngle, mFactor, dFactor;
   int nLimit, i;
   int nCountedBars;
   double angle;
   int ShiftDif;
 
   if(EndEMAShift >= StartEMAShift)
   {
      Print("Error: EndEMAShift >= StartEMAShift");
      StartEMAShift = 6;
      EndEMAShift = 0;      
   }  
         
   nCountedBars = IndicatorCounted();
//---- check for possible errors
   if(nCountedBars<0) 
      return(-1);
//---- last counted bar will be recounted
   if(nCountedBars>0) 
      nCountedBars--;
   nLimit = Bars-nCountedBars;
   dFactor = 3.14159/180.0;
   mFactor = 10000.0;
   
   if (Symbol() == "USDJPY") mFactor = 100.0;
   ShiftDif = StartEMAShift-EndEMAShift;
   mFactor /= ShiftDif; 
//---- main loop
   
   for(i=0; i<nLimit; i++)
   {
      ExtMapBuffer5[i] = EMPTY_LEVEL;
      ExtMapBuffer6[i] = EMPTY_LEVEL;
      ExtMapBuffer7[i] = EMPTY_LEVEL;
   
      bool ea_green = false;
      bool ea_red = false;
      bool ea_yellow = false;
      
      double rsi = iRSI(NULL, 0, rsi_period, rsi_price, i);
      double cci_fo = iCCI(Symbol(), indicator_period, filter_out_cci, cci_price, i);
      
      double cci = iCCI(Symbol(), indicator_period, cci_period, cci_price, i);
      double cci_p = iCCI(Symbol(), indicator_period, cci_period, cci_price, i+previous_shift);
      double cci_l = iCCI(Symbol(), indicator_period, long_period, cci_price, i);
      double cci_lp = iCCI(Symbol(), indicator_period, long_period, cci_price, i+previous_shift);
      
      double lrsi = iRSI(Symbol(), indicator_period, long_rsi, PRICE_CLOSE, i);
      
      double adxpdi = iADX(Symbol(), indicator_period, adx_period, PRICE_CLOSE, MODE_PLUSDI, i);
      double adxmdi = iADX(Symbol(), indicator_period, adx_period, PRICE_CLOSE, MODE_MINUSDI, i);
      double adxmain = iADX(Symbol(), indicator_period, adx_period, PRICE_CLOSE, MODE_MAIN, i);

      int adx_op = OP_NEUTRAL;
      if (adxpdi >= adxmdi && adxmain > adx_level) adx_op = OP_BUY;
      if (adxpdi < adxmdi && adxmain > adx_level) adx_op = OP_SELL;


      fEndMA=iMA(NULL,0, EMAPeriod,0,MODE_EMA,PRICE_MEDIAN,i+EndEMAShift);
      fStartMA=iMA(NULL,0,EMAPeriod,0,MODE_EMA,PRICE_MEDIAN,i+StartEMAShift);
      // 10000.0 : Multiply by 10000 so that the fAngle is not too small
      // for the indicator Window.
      fAngle = mFactor * (fEndMA - fStartMA);
//      fAngle = MathArctan(fAngle)/dFactor;

      DownBuffer[i] = 0.0;
      UpBuffer[i] = 0.0;
      ZeroBuffer[i] = 0.0;
      
      if(fAngle > AngleTreshold)
      {
         ea_green = true;
         UpBuffer[i] = fAngle;
      }
      else if (fAngle < -AngleTreshold)
      {
         ea_yellow = true;
         DownBuffer[i] = fAngle;
      }
      else 
      {
         ea_red = true;
         ZeroBuffer[i] = fAngle;
      }
      
      
      if (cci > small_long_cci_cross && cci_l > large_long_cci_cross && (rsi > long_rsi_cross || !chk_rsi) && (adx_op == OP_BUY || !chk_adx) && ea_green)
      {
         ExtMapBuffer5[i] = SIG_LEVEL;
         if (i == 1 && ExtMapBuffer5[i+1] != SIG_LEVEL && enablealertbuy && buytime < iTime(NULL, 0, 2))
         {
            buytime = iTime(NULL, 0, 2);
            AlertSignal(alertpair, OP_BUY, alertbuymsg, alertsellmsg, alertexitmsg);
         }
      }
      // if (cci > long_cci_cross && rsi > long_rsi_cross && adxpdi > adxmdi && adxmdi < adxmain) 
         
      // cci_l < short_cci_cross && 
      // (cci < short_cci_cross && rsi < short_rsi_cross && adxpdi < adxmdi && adxmdi > adxpdi) 
      // (cci < short_cci_cross && cci_l < short_cci_cross && rsi > short_rsi_cross)
      if (cci < small_short_cci_cross && cci_l < large_short_cci_cross && (rsi < short_rsi_cross || !chk_rsi) && (adx_op == OP_SELL || !chk_adx) && ea_yellow)
      {
         ExtMapBuffer6[i] = SIG_LEVEL;
         if (i == 1 && ExtMapBuffer6[i+1] != SIG_LEVEL && enablealertsell && selltime < iTime(NULL, 0, 2))
         {
            selltime = iTime(NULL, 0, 2);
            AlertSignal(alertpair, OP_SELL, alertbuymsg, alertsellmsg, alertexitmsg);
         }
      }
      if ((cci >= exit_cci_cross_short && cci_p < exit_cci_cross_short) || (cci <= exit_cci_cross_long && cci_p > exit_cci_cross_long))
      // if (cci_fo > filter_out_long || cci_fo < filter_out_short)
      {
         ExtMapBuffer7[i] = EXT_LEVEL;
         if (i == 1 && ExtMapBuffer7[i+1] != SIG_LEVEL && enablealertexit && exittime < iTime(NULL, 0, 2))
         {
            exittime = iTime(NULL, 0, 2);
            AlertSignal(alertpair, OP_EXIT, alertbuymsg, alertsellmsg, alertexitmsg);
         }
      }
    
   }
   return(0);
  }
//+------------------------------------------------------------------+


void ShowCopyright()
{
   Print("Copyright © 2007-2008, ", "Canadian Dude & Rev");
   Print("http://www.learnfxprime.com");
}

void AlertSignal(bool alertpair, int op, string buy, string sell, string exit)
{
   string msg = "";
   
   if (alertpair) msg = StringConcatenate(msg, Symbol(), ", ");
   
   if (op == OP_BUY) msg = StringConcatenate(msg, buy);
   else if (op == OP_SELL) msg = StringConcatenate(msg, sell);
   else if (op == OP_EXIT) msg = StringConcatenate(msg, exit);
   
   Alert(msg);
}

Comments