VQ indicator
//+------------------------------------------------------------------+
//| VQ.mq4 |
//| Volatility Quality |
//| //+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Yellow
#property indicator_color2 Green
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Cyan
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
extern bool Crash = false;
extern int TimeFrame = 0;
extern int Length = 5;
extern int Method = 3;
extern int Smoothing = 1;
extern int Filter = 5;
extern bool RealTime = true;
extern bool Steady = false;
extern bool Color = true;
extern bool Alerts = true;
extern bool EmailON = false;
extern bool SignalPrice = true;
extern color SignalPriceBUY = Yellow;
extern color SignalPriceSELL = Aqua;
extern int CountBars = 1485;
double VQ[];
double SumVQ[];
double SumVQ_MTF[];
double DIR[];
double UpBuffer[];
double DnBuffer[];
double UpArrow[];
double DnArrow[];
bool TurnedUp = false;
bool TurnedDn = false;
datetime timeprev1=0;
datetime timeprev2=0;
int p=0;
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(0,SumVQ);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(1,UpBuffer);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID);
SetIndexBuffer(2,DnBuffer);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,233);
SetIndexBuffer(3,UpArrow);
SetIndexStyle(4,DRAW_ARROW);
SetIndexArrow(4,234);
SetIndexBuffer(4,DnArrow);
SetIndexBuffer(5,VQ);
SetIndexBuffer(6,DIR);
SetIndexBuffer(7,SumVQ_MTF);
if (Length < 2) Length = 2;
if (Method < 0) Method = 0;
if (Method > 3) Method = 3;
if (Smoothing < 0) Smoothing = 0;
if (Filter < 0) Filter = 0;
if ((TimeFrame < Period()) && (TimeFrame != 0)) TimeFrame = Period();
switch(TimeFrame)
{
case 1: string TimeFrameStr = "M1"; break;
case 5: TimeFrameStr = "M5"; break;
case 15: TimeFrameStr = "M15"; break;
case 30: TimeFrameStr = "M30"; break;
case 60: TimeFrameStr = "H1"; break;
case 240: TimeFrameStr = "H4"; break;
case 1440: TimeFrameStr = "D1"; break;
case 10080: TimeFrameStr = "W1"; break;
case 43200: TimeFrameStr = "MN1"; break;
default: TimeFrameStr = "";
}
string short_name = "VQ" + TimeFrameStr + " | " + Length + " , " + Method + " , " + Smoothing + " , " + Filter + " | ";
IndicatorShortName(short_name);
return(0);
}
//+------------------------------------------------------------------+
int start()
{
if (Bars < 100) {IndicatorShortName("Bars less than 100"); return(0);}
if(timeprev1<iTime(NULL,TimeFrame,0)) {TurnedDn = false; TurnedUp = false; timeprev1=iTime(NULL,TimeFrame,0);}
if (!RealTime)
{
if(timeprev2==iTime(NULL,TimeFrame,0)) return(0);
timeprev2=iTime(NULL,TimeFrame,0);
p=TimeFrame/Period()+1; if (p==0) p=1;
}
double TR = 0, MH = 0, ML = 0, MO = 0, MC = 0, MC1 = 0;
if (CountBars>iBars(NULL,TimeFrame) || CountBars>Bars-Length-1) CountBars=MathMin(Bars-Length-1,iBars(NULL,TimeFrame)-Length-1);
if (Crash && CountBars>0){CountBars=CountBars-10; IndicatorShortName("Crash: "+CountBars+" ");}
if (Crash && CountBars<0) IndicatorShortName("Crash");
int i = CountBars;
SumVQ = Close;
SumVQ_MTF = Close;
while (i >= 0)
{
MH = iMA(NULL,TimeFrame,Length,0,Method,PRICE_HIGH,i);
ML = iMA(NULL,TimeFrame,Length,0,Method,PRICE_LOW,i);
MO = iMA(NULL,TimeFrame,Length,0,Method,PRICE_OPEN,i);
MC = iMA(NULL,TimeFrame,Length,0,Method,PRICE_CLOSE,i);
MC1 = iMA(NULL,TimeFrame,Length,0,Method,PRICE_CLOSE,i + Smoothing);
if (Steady==true) {MC=iMA(NULL,TimeFrame,Length,0,Method,PRICE_MEDIAN,i); MC1=iMA(NULL,TimeFrame,Length,0,Method,PRICE_MEDIAN,i+Smoothing);}
VQ = MathAbs(((MC - MC1) / MathMax(MH - ML,MathMax(MH - MC1,MC1 - ML)) + (MC - MO) / (MH - ML)) * 0.5) * ((MC - MC1 + (MC - MO)) * 0.5);
SumVQ = SumVQ + VQ;
if (Filter > 0) if (MathAbs(SumVQ - SumVQ) < Filter * Point) SumVQ = SumVQ;
if (TimeFrame > Period()) SumVQ_MTF = SumVQ;
i--;
}
if (TimeFrame>Period())
{
datetime TimeArray1[];
ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame);
int limit=CountBars+TimeFrame/Period();
for(i=0, int y=0;i<limit;i++) {if (Time<TimeArray1[y]) y++; SumVQ=SumVQ_MTF[y];}
}
for (i = CountBars; i >= 0; i--)
{
DIR = DIR;
if (SumVQ - SumVQ > 0) DIR = 1;
if (SumVQ - SumVQ > 0) DIR = -1;
if (Color == true)
{
if (DIR > 0)
{
UpBuffer = SumVQ;
if (DIR < 0) UpBuffer = SumVQ;
DnBuffer = EMPTY_VALUE;
}
else
{
if (DIR < 0)
{
DnBuffer = SumVQ;
if (DIR > 0) DnBuffer = SumVQ;
UpBuffer = EMPTY_VALUE;
}
}
}
if (Alerts == true)
{
UpArrow = EMPTY_VALUE; DnArrow = EMPTY_VALUE;
if ((DIR == 1) && (DIR == -1)) UpArrow = SumVQ - (Ask - Bid);
if ((DIR == -1) && (DIR == 1)) DnArrow = SumVQ + (Ask - Bid);
}
}
if (Alerts == true)
{
string AlertTXT;
if (UpArrow[0+p]!=EMPTY_VALUE && TurnedUp==false)
{
AlertTXT="VQ BUY: "+Symbol()+" - "+Period()+" at "+ DoubleToStr(Close[0],Digits)+ " - "+ TimeToStr(CurTime(),TIME_SECONDS);
Alert(AlertTXT); if (EmailON) SendMail(AlertTXT,AlertTXT);
if (SignalPrice == true)
{
ObjectCreate("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJ_ARROW,0,Time[0],Close[0]);
ObjectSet("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_ARROWCODE,5);
ObjectSet("BUY SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_COLOR,SignalPriceBUY);
}
TurnedDn = false; TurnedUp = true;
}
if (DnArrow[0+p]!=EMPTY_VALUE && TurnedDn==false)
{
AlertTXT="VQ SELL: "+Symbol()+" - "+Period()+" at "+ DoubleToStr(Close[0],Digits)+ " - "+ TimeToStr(CurTime(),TIME_SECONDS);
Alert(AlertTXT); if (EmailON) SendMail(AlertTXT,AlertTXT);
if (SignalPrice == true)
{
ObjectCreate("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJ_ARROW,0,Time[0],Close[0]);
ObjectSet("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_ARROWCODE,5);
ObjectSet("SELL SIGNAL: " + DoubleToStr(Time[0],0),OBJPROP_COLOR,SignalPriceSELL);
}
TurnedUp = false; TurnedDn = true;
}
}
return(0);
}
BUY SELL EVERY ARROQ DRAWN
please anybody kind me for Converting custom Indicators code to EA code
Thanks ..
//+------------------------------------------------------------------+
//| TMA+CG.mq4 |
//| mladen |
//| arrowse coded acording to idea presented by rajiv |
//+------------------------------------------------------------------+
#property copyright "rajivxxx"
#property link "rajivxxx@gmail.com"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 DimGray
#property indicator_color2 Red
#property indicator_color3 LimeGreen
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_style1 STYLE_DOT
//
//
//
//
//
extern string TimeFrame = "current time frame";
extern int HalfLength = 56;
extern int Price = PRICE_WEIGHTED;
extern double BandsDeviations = 2.5;
extern bool Interpolate = true;
extern bool alertsOn = false;
extern bool alertsOnCurrent = false;
extern bool alertsOnHighLow = true;
extern bool alertsMessage = true;
extern bool alertsSound = false;
extern bool alertsEmail = false;
//
//
//
//
//
double tmBuffer[];
double upBuffer[];
double dnBuffer[];
double wuBuffer[];
double wdBuffer[];
double upArrow[];
double dnArrow[];
//
//
//
//
//
string IndicatorFileName;
bool calculatingTma = false;
bool returningBars = false;
int timeFrame;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
int init()
{
timeFrame = stringToTimeFrame(TimeFrame);
HalfLength = MathMax(HalfLength,1);
IndicatorBuffers(7);
SetIndexBuffer(0,tmBuffer); SetIndexDrawBegin(0,HalfLength);
SetIndexBuffer(1,upBuffer); SetIndexDrawBegin(1,HalfLength);
SetIndexBuffer(2,dnBuffer); SetIndexDrawBegin(2,HalfLength);
SetIndexBuffer(3,dnArrow); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(5,242);
SetIndexBuffer(4,upArrow); SetIndexStyle(4,DRAW_ARROW); SetIndexArrow(6,241);
SetIndexBuffer(5,wuBuffer);
SetIndexBuffer(6,wdBuffer);
if (TimeFrame=="calculateTma") { calculatingTma=true; return(0); }
if (TimeFrame=="returnBars") { returningBars=true; return(0); }
IndicatorFileName = WindowExpertName();
return(0);
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=MathMin(Bars-1,Bars-counted_bars+HalfLength);
if (returningBars) { tmBuffer[0] = limit; return(0); }
if (calculatingTma) { calculateTma(limit); return(0); }
if (timeFrame > Period()) limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,IndicatorFileName,"returnBars",0,0)*timeFrame/Period()));
//
//
//
//
//
for(i = limit; i >= 0; i--)
{
int shift1 = iBarShift(NULL,timeFrame,Time);
datetime time1 = iTime (NULL,timeFrame,shift1);
//
//
//
//
//
tmBuffer = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations,0,shift1);
upBuffer = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations,1,shift1);
dnBuffer = iCustom(NULL,timeFrame,IndicatorFileName,"calculateTma",HalfLength,Price,BandsDeviations,2,shift1);
upArrow = EMPTY_VALUE;
dnArrow = EMPTY_VALUE;
if (High[i+1]>upBuffer[i+1] && Close[i+1]>Open[i+1] && Close<Open) upArrow = High+iATR(NULL,0,20,i);
if ( Low[i+1]<dnBuffer[i+1] && Close[i+1]<Open[i+1] && Close>Open) dnArrow = High-iATR(NULL,0,20,i);
if (timeFrame <= Period() || shift1==iBarShift(NULL,timeFrame,Time[i-1])) continue;
if (!Interpolate) continue;
//
//
//
//
//
for(int n = 1; i+n = time1; n++) continue;
double factor = 1.0 / n;
for(int k = 1; k < n; k++)
{
tmBuffer[i+k] = k*factor*tmBuffer[i+n] + (1.0-k*factor)*tmBuffer;
upBuffer[i+k] = k*factor*upBuffer[i+n] + (1.0-k*factor)*upBuffer;
dnBuffer[i+k] = k*factor*dnBuffer[i+n] + (1.0-k*factor)*dnBuffer;
}
}
//
//
//
//
//
if (alertsOn)
{
if (alertsOnCurrent)
int forBar = 0;
else forBar = 1;
if (alertsOnHighLow)
{
if (High[forBar] > upBuffer[forBar] && High[forBar+1] < upBuffer[forBar+1]) doAlert("high penetrated upper bar");
if (Low[forBar] dnBuffer[forBar+1]) doAlert("low penetrated lower bar");
}
else
{
if (Close[forBar] > upBuffer[forBar] && Close[forBar+1] < upBuffer[forBar+1]) doAlert("close penetrated upper bar");
if (Close[forBar] dnBuffer[forBar+1]) doAlert("close penetrated lower bar");
}
}
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
void calculateTma(int limit)
{
int i,j,k;
double FullLength = 2.0*HalfLength+1.0;
//
//
//
//
//
for (i=limit; i>=0; i--)
{
double sum = (HalfLength+1)*iMA(NULL,0,1,0,MODE_SMA,Price,i);
double sumw = (HalfLength+1);
for(j=1, k=HalfLength; j<=HalfLength; j++, k--)
{
sum += k*iMA(NULL,0,1,0,MODE_SMA,Price,i+j);
sumw += k;
if (j<=i)
{
sum += k*iMA(NULL,0,1,0,MODE_SMA,Price,i-j);
sumw += k;
}
}
tmBuffer = sum/sumw;
//
//
//
//
//
double diff = iMA(NULL,0,1,0,MODE_SMA,Price,i)-tmBuffer;
if (i> (Bars-HalfLength-1)) continue;
if (i==(Bars-HalfLength-1))
{
upBuffer = tmBuffer;
dnBuffer = tmBuffer;
if (diff>=0)
{
wuBuffer = MathPow(diff,2);
wdBuffer = 0;
}
else
{
wdBuffer = MathPow(diff,2);
wuBuffer = 0;
}
continue;
}
//
//
//
//
//
if(diff>=0)
{
wuBuffer = (wuBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
wdBuffer = wdBuffer[i+1]*(FullLength-1)/FullLength;
}
else
{
wdBuffer = (wdBuffer[i+1]*(FullLength-1)+MathPow(diff,2))/FullLength;
wuBuffer = wuBuffer[i+1]*(FullLength-1)/FullLength;
}
upBuffer = tmBuffer + BandsDeviations*MathSqrt(wuBuffer);
dnBuffer = tmBuffer - BandsDeviations*MathSqrt(wdBuffer);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
void doAlert(string doWhat)
{
static string previousAlert="";
static datetime previousTime;
string message;
//
//
//
//
//
if (previousAlert!=doWhat || previousTime!=Time[0])
{
previousAlert = doWhat;
previousTime = Time[0];
message= StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," THA : ",doWhat);
if (alertsMessage) Alert(message);
if (alertsEmail) SendMail(StringConcatenate(Symbol(),"TMA "),message);
if (alertsSound) PlaySound("alert2.wav");
}
}
//
//
//
//
//
int stringToTimeFrame(string tfs)
{
for(int l = StringLen(tfs)-1; l >= 0; l--)
{
int char = StringGetChar(tfs,l);
if((char > 96 && char 223 && char < 256))
tfs = StringSetChar(tfs, 1, char - 32);
else
if(char > -33 && char < 0)
tfs = StringSetChar(tfs, 1, char + 224);
}
int tf=0;
if (tfs=="M1" || tfs=="1") tf=PERIOD_M1;
if (tfs=="M5" || tfs=="5") tf=PERIOD_M5;
if (tfs=="M15"|| tfs=="15") tf=PERIOD_M15;
if (tfs=="M30"|| tfs=="30") tf=PERIOD_M30;
if (tfs=="H1" || tfs=="60") tf=PERIOD_H1;
if (tfs=="H4" || tfs=="240") tf=PERIOD_H4;
if (tfs=="D1" || tfs=="1440") tf=PERIOD_D1;
if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;
if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;
if (tf==0 || tf<Period()) tf=Period();
return(tf);
}

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Time for the experts to show your skills ..
Lets use 3 indicators and change it into simple buy/sell expert advisors..
First wolfwave . buy or sell every swing
Second one is Targets,mq4