AF_STAR
Download scriptThis script is a technical analysis tool designed to identify potential entry points in financial markets by combining several layers of mathematical logic. Instead of relying on a single indicator, it performs a multi-step "filtering" process to confirm price movements before displaying a visual signal on your chart.
Here is a breakdown of how the logic works:
1. Trend and Momentum Detection (The Primary Scan)
The script begins by looking for crossovers between different "Moving Averages" (lines that smooth out price data). However, rather than just checking one set of averages, it performs an exhaustive search across a range of different speeds.
- It scans through multiple combinations of "Fast" and "Slow" settings simultaneously.
- If it detects the Fast line crossing over or under the Slow line within these predefined ranges, it flags a potential "Buy" or "Sell" opportunity.
2. Volatility and Range Analysis
Once a potential signal is found in the first step, the script validates it by looking at recent price volatility. It calculates a "Range" based on the highs and lows of previous bars. It then checks for specific price behaviors, such as:
- Large gaps between opening and closing prices.
- Significant jumps in price movement over a short period. These checks help ensure that the market is actually moving with enough strength to justify a trade, rather than just drifting sideways.
3. Oscillatory Confirmation (The "Risk" Filter)
The script incorporates an additional layer of verification using a momentum oscillator. It calculates a percentage-based value and compares it against dynamic "risk" boundaries.
- It looks for the price to be at extreme levels (overbought or oversold).
- It checks if the price is moving out of these extreme zones into a specific "neutral" zone. This ensures that the signals aren't just generated by over-extended market moves, but rather by confirmed shifts in momentum.
4. Final Signal Validation (The Decision Module)
Even after passing the first three tests, a signal is not shown immediately. The script requires a "confluence" of data. For a final Buy or Sell arrow to appear on your chart, the following must happen:
- Agreement: The results from the Moving Average scan and the Risk/Oscillator filter must both agree on the direction of the trade at the same time (or within one bar of each other).
- Conflict Resolution: If the logic somehow produces both a Buy and a Sell signal simultaneously, the script is programmed to ignore both, as this indicates a "conflicting" or "choppy" market where no clear direction exists.
Summary for the User
In plain terms, this script acts like a high-level filter. It looks for a Trend Cross, verifies it with Volatility Strength, confirms it with Momentum Exhaustion, and only then places an arrow on your chart if all these conditions align perfectly. This multi-layered approach is designed to reduce "noise" and focus on signals where multiple different technical factors agree with each other.
//+------------------------------------------------------------------+
//| 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=Bars-counted_bars;//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