Posted By: Grat
Vortex indicator - 10/10/16 10:41
HI,
i create indicator Vortex ( http://www.automated-trading-system.com/vortex-indicator/ ).
For the playing here is source:
i create indicator Vortex ( http://www.automated-trading-system.com/vortex-indicator/ ).
For the playing here is source:
Code:
#define _DEBUG_ 1 #define _LONG -1 #define _SHORT 1 #define _WRONG 0 #define version 0.1 #define HIT 0 #define M1 (1/BarPeriod) #define M5 (5/BarPeriod) #define M60 (60/BarPeriod) #ifdef _DEBUG_ string FileName="History\\vortex.csv"; #endif //---------------- Vortex indicator ----------------------------- vars PlusVI; vars MinusVI; int vortex(int Period){ checkLookBack(Period+1); int i,j; vars PlusVM,MinusVM,SumTR; PlusVM = series(abs(priceHigh()-priceLow(1))); MinusVM = series(abs(priceLow()-priceHigh(1))); SumTR = series(ATR(1)); #ifdef _DEBUG_ file_append(FileName,strf("\n%s;",strdate("%Y-%m-%d %H:%M:%S"))); file_append(FileName,strf("%f;",PlusVM[0])); file_append(FileName,strf("%f;",MinusVM[0])); file_append(FileName,strf("%f;",SumTR[0])); #endif PlusVI = series( 0); MinusVI = series( 0); if (Bar < Period) return _WRONG; //--------- var SumPlus =0,SumMinus =0, SumT1 =0; for(i = 0; i <= Period - 1; i++){ SumPlus += PlusVM[i]; SumMinus += MinusVM[i]; SumT1 += SumTR[i]; //Sum VI_Length values of the True Range by using a 1-period ATR } PlusVI[0] = ( SumPlus / SumT1); MinusVI[0] = ( SumMinus / SumT1); rRealUpperBand = PlusVI[0]; rRealLowerBand = MinusVI[0]; #ifdef _DEBUG_ file_append(FileName,strf("%f;",SumPlus)); file_append(FileName,strf("%f;",SumMinus)); file_append(FileName,strf("%f;",SumT1)); file_append(FileName,strf("%f;",PlusVI[0])); file_append(FileName,strf("%f;",MinusVI[0])); #endif if (Bar < Period*5) return _WRONG; if(crossOver(PlusVI,MinusVI)) return _SHORT; if(crossUnder(PlusVI,MinusVI)) return _LONG; return _WRONG; } function run() { set(PLOTNOW); StartDate=2016; EndDate=2016; NumYears = 1; MaxBars = 300; PlotScale = 8; PlotWidth = 1600; PlotHeight1 = 600; PlotHeight2 = 120; BarPeriod = 60; if (is(INITRUN)){ #ifdef _DEBUG_ file_delete(FileName); #endif } vars aVortex = series(vortex(12)); plot("PlusVI",PlusVI,NEW,RED); plot("MinusVI",MinusVI,0,BLUE); plot("Cross",aVortex,NEW,GREEN); }
Description: Output