El código de la plataforma Metatrader del indicador Signal to Noise Ratio :
//+——————————————————————+
//| Shaun-Pi-2.mq4 |
//| Copyright 2015,SyneAsya Pte Ltd. |
//| http://www.SyneAsya.com|
//+——————————————————————+
#property copyright “Copyright 2015,SyneAsya Pte Ltd.”
#property link “www.SyneAsya.com”
#property version “2.00”
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_minimum -0.00001
extern string MyPair = “EURUSD”;
extern bool MySymbol = FALSE; //False = Symbol on the chart // True = MyPair
extern int BarsBack = 1000;
extern int MyLookBackShift = 14;
extern color CLR1 = Yellow;
double Buf0[];
double Buf1[];
double MyClose[10000];
double AbsCh[10000];
double LookBackShift[10000];
double MyWalk[10000];
double MyDistance[10000];
double MyDTWRatio[10000];
double MyB;
//+——————————————————————+
//| Custom indicator initialization function |
//+——————————————————————+
int OnInit()
{
SetIndexBuffer(0,Buf0);
SetIndexLabel(0,MyPair);
SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2,CLR1);
SetIndexBuffer(1,Buf1);
SetIndexLabel(1,”MyPiRatio”);
SetIndexStyle (1,DRAW_LINE,STYLE_DOT,1,clrWhite);
double MyPiRatio = 1/3.14159265358979*0.5;
SetLevelValue( 0, MyPiRatio ) ;
SetLevelStyle( STYLE_DOT , 1 , Silver ) ;
IndicatorShortName(“SNRatio2 (“+IntegerToString(Period())+”)”);
return(0);
//—
return(INIT_SUCCEEDED);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
limit=MathMin(Bars-counted_bars,BarsBack-MyLookBackShift-2);
if(counted_bars>0) counted_bars–;
{
//====================================================
for(int i = 0; i < limit; i++)
{
string Pair;
if(MySymbol == TRUE)
{
Pair = MyPair;
}
else
if(MySymbol == FALSE)
{
Pair = Symbol();
}
double A = iClose(Pair,Period(),i);
MyClose[i] = A;
}
//====================================================
for(int i = 0; i < limit; i++)
{
LookBackShift[i] = MyClose[i+MyLookBackShift];
}
//====================================================
for(int i = 0; i < limit; i++)
{
AbsCh[i] = MathAbs(MyClose[i] – MyClose[i+1]);
MyDistance[i] = MathAbs(MyClose[i]-LookBackShift[i]);
}
//====================================================
for(int i = 0; i < limit; i++)
{
MyB = 0;
for(int y = 0; y < MyLookBackShift + 1; y++)
{
MyB = MyB + AbsCh[y+i];
}
MyWalk[i] = MyB; //Print(“MyWalk”,” “,MyWalk[i]);
}
//====================================================
for(int i = 0; i < limit; i++)
{
MyDTWRatio[i] = MyDistance[i]/MyWalk[i];
}
double MyPiRatio = 1/3.14159265358979/2;
for(int i = 0; i < limit; i++)
{
Buf0[i] = MyDTWRatio[i];
Buf1[i] = MyPiRatio;
}
}
return(0);