Author: Copyright � 2005, Forex-Experts
AFStar_v2

This tool is designed as a technical analysis indicator for trading platforms, specifically built to identify potential entry points in financial markets by analyzing price trends and momentum. It works by looking at several layers of market data simultaneously to filter out "noise" and pinpoint moments where the price direction might be shifting.

Core Logic Overview

The script operates through three distinct stages of analysis before displaying a signal on your chart:

1. Trend Direction Analysis (Moving Average Crossings) The indicator first looks for "crossovers" between fast and slow moving averages. By comparing a quick-moving average (which reacts fast to price changes) against a slower-moving average (which represents the broader trend), the script identifies basic momentum shifts. If the fast line crosses over the slow line, it suggests a change in trend direction.

2. Volatility and Range Filtering To ensure the signals aren't triggered by minor, insignificant price wiggles, the script calculates the "average range" of recent price movements. It then performs a secondary check to see if the current price action is significant enough relative to that average. This helps distinguish between a meaningful trend change and standard market fluctuation.

3. Momentum and Overbought/Oversold Validation The indicator uses a momentum-based calculation (specifically a Percentage of Range analysis) to determine if the market is stretched too far in one direction. It checks if the price is currently in an "overextended" state. By combining this with the trend data, it tries to identify locations where the price is likely to pull back or reverse.

Signal Generation

The final output on your chart—the visual arrows—only appears when multiple conditions align:

  • Confirmation: A signal is only generated if both the "Trend Analysis" and the "Momentum/Volatility Analysis" agree on the same direction.
  • Proximity Check: The script also checks adjacent candles to ensure that even if a signal occurred slightly before or after the current bar, it is captured as a valid entry point.
  • Conflict Resolution: If the logic simultaneously detects a buy signal and a sell signal at the exact same moment (a "conflicting" market state), it will automatically cancel both signals to prevent entering a trade in an uncertain environment.

In summary, rather than relying on a single rule, this script uses a "consensus" model—requiring trend crossovers, sufficient volatility, and momentum alignment to all point in the same direction before notifying the user.

Indicators Used
Moving average indicatorLarry William percent range indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
AFStar_v2
//+------------------------------------------------------------------+
//|                                                       AFStar.mq4 |
//|                                  Copyright © 2005, Forex-Experts |
//|                                     http://www.forex-experts.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Forex-Experts"
#property link      "http://www.forex-experts.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 Aqua
//---- input parameters
extern double StartFast=3;
extern double EndFast=3.5;
extern double StartSlow=8;
extern double EndSlow=9;
extern double StepPeriod=0.2;
extern double StartRisk=1;
extern double EndRisk=2.8;
extern double StepRisk=0.5;
extern int    AllBars=500;

int      shift=0,RiskCnt=0, EndScan1=0, EndScan2=0;
double   iMaSlowPrevious=0, iMaSlowCurrent=0, iMaFastPrevious=0, iMaFastCurrent=0;
double   FastCnt=0, SlowCnt=0;
double   Buy1[1000], Sell1[1000];
double   Buy2[1000], Sell2[1000];
double   Buy=0, Sell=0;
//---- buffers
double val1[];
double val2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,226);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,225);
   SetIndexBuffer(0,val1);
   SetIndexBuffer(1,val2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   if (AllBars>=1000) AllBars=1000;
   SetIndexDrawBegin(0,Bars-AllBars+11+1);
   SetIndexDrawBegin(1,Bars-AllBars+11+1);
   int i,shift,counted_bars=IndicatorCounted();
   int Counter,i1,value10,value11;
   double value1,x1,x2;
   double value2,value3;
   double TrueCount,Range,AvgRange,MRO1,MRO2;
   double Table_value2[1000];
//----
   if(Bars<=11+1) return(0);
//---- initial zero
   if(counted_bars<11+1)
     {
      for(i=1;i<=0;i++) val1[AllBars-i]=0.0;
      for(i=1;i<=0;i++) val2[AllBars-i]=0.0;
     }
//---- TODO: add your code here
   //for (shift=(AllBars-11-1); shift<=0; shift--)
   //{
   shift=AllBars-11-1;
   while(shift>=0)
     {
      Sell1[shift]=0;
      Buy1[shift]=0;
      EndScan1=0;
      SlowCnt=StartSlow;
      while(SlowCnt<=EndSlow)
        {
         if (EndScan1==1) break;
         FastCnt=StartFast;
         while(FastCnt<=EndFast)
           {
            if (EndScan1==1) break;
            //Scan Parameters		
            iMaSlowPrevious=iMA(NULL,0,SlowCnt,0,MODE_EMA, PRICE_CLOSE, shift-1);
            iMaSlowCurrent=iMA(NULL,0,SlowCnt,0,MODE_EMA, PRICE_CLOSE, shift);
            iMaFastPrevious=iMA(NULL,0,FastCnt,0, MODE_EMA, PRICE_CLOSE, shift-1);
            iMaFastCurrent=iMA(NULL,0,FastCnt,0, MODE_EMA, PRICE_CLOSE, shift);
            if (iMaFastPrevious<iMaSlowPrevious && iMaFastCurrent>iMaSlowCurrent) { EndScan1=1; Sell1[shift]=1;}
            if (iMaFastPrevious>iMaSlowPrevious && iMaFastCurrent<iMaSlowCurrent) { EndScan1=1; Buy1[shift]=1;}
            FastCnt=FastCnt+StepPeriod;
           }
         SlowCnt=SlowCnt+StepPeriod;
        }
      EndScan2=0;
      Sell2[shift]=0;
      Buy2[shift]=0;
      RiskCnt=StartRisk;
      //	while (RiskCnt<=EndRisk)
      if (RiskCnt<=EndRisk)
        {
         if (EndScan2!=1)
           {
            value10=3+RiskCnt*2;
            x1=67+RiskCnt;
            x2=33-RiskCnt;
            value11=value10;
            //----
            //   shift=AllBars-11-1;
            //   while(shift>=0)
            //     {
            Counter=shift;
            Range=0.0;
            AvgRange=0.0;
            for(Counter=shift; Counter<=shift+9; Counter++) AvgRange=AvgRange+MathAbs(High[Counter]-Low[Counter]);
            Range=AvgRange/10;
            Counter=shift;
            TrueCount=0;
            while(Counter<shift+9 && TrueCount<1)
              {if (MathAbs(Open[Counter]-Close[Counter+1])>=Range*2.0) TrueCount=TrueCount+1;
               Counter=Counter+1;
              }
            if (TrueCount>=1) {MRO1=Counter;} else {MRO1=-1;}
            Counter=shift;
            TrueCount=0;
            while(Counter<shift+6 && TrueCount<1)
              {if (MathAbs(Close[Counter+3]-Close[Counter])>=Range*4.6) TrueCount=TrueCount+1;
               Counter=Counter+1;
              }
            if (TrueCount>=1) {MRO2=Counter;} else {MRO2=-1;}
            if (MRO1>-1) {value11=3;} else {value11=value10;}
            if (MRO2>-1) {value11=4;} else {value11=value10;}
            value2=100-MathAbs(iWPR(NULL,0,value11,shift)); // PercentR(value11=9)
            Table_value2[shift]=value2;
            val1[shift]=0;
            val2[shift]=0;
            value3=0;
            if (value2<x2)
              {i1=1;
               while(Table_value2[shift+i1]>=x2 && Table_value2[shift+i1]<=x1){i1++;}
               if (Table_value2[shift+i1]>x1)
                 {
                  value3=High[shift]+Range*0.5;
                  Sell2[shift]=value3;
                  //			val1[shift]=value3;
                 }
              }
            if (value2>x1)
              {i1=1;
               while(Table_value2[shift+i1]>=x2 && Table_value2[shift+i1]<=x1){i1++;}
               if (Table_value2[shift+i1]<x2)
                 {
                  value3=Low[shift]-Range*0.5;
                  Buy2[shift]=value3;
                  //			val2[shift]=value3;
                 }
              }
           }
         if (Buy2[shift]>0 || Sell2[shift]>0) {EndScan2=1;}
         RiskCnt=RiskCnt+StepRisk;
        }
      //Main decision module
      Buy=0; Sell=0;
      if ((Buy1[shift]>0 && Buy2[shift]>0) || (Buy1[shift]>0 && Buy2[shift+1]>0) || (Buy1[shift+1]>0 && Buy2[shift]>0)) Buy=Low[shift]-1*Point;
      if ((Sell1[shift]>0 && Sell2[shift]>0) || (Sell1[shift]>0 && Sell2[shift+1]>0) || (Sell1[shift+1]>0 && Sell2[shift]>0)) Sell=High[shift]+1*Point;
      //Ignore if we have two signals
      if (Buy!=0 && Sell!=0)
        {
         Buy=0; Sell=0;
        }
      val1[shift]=Sell;
      val2[shift]=Buy;
      shift--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments