Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
Gann-ICWR-fixed
//+------------------------------------------------------------------+
//| ICWR |
//| Copyright © 2005, John Lotoski |
//| mailto:john@fayandjohn.com |
//| |
//| Gann-ICWR beta5 |
//| update code Alex.Piech.FinGeR 23.01.2006 |
//| mailto:regnif@gmx.net |
//+------------------------------------------------------------------+
#property copyright "Alex.Piech.FinGeR"
#property link "regnif@gmx.net"
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 DeepSkyBlue
#property indicator_color2 DeepSkyBlue
//#property indicator_color3 DeepSkyBlue
//#property indicator_color4 DeepSkyBlue
//#property indicator_color5 DeepSkyBlue
//#property indicator_color6 DeepSkyBlue
//#property indicator_color7 DeepSkyBlue
//#property indicator_color8 DeepSkyBlue
//---- input parameters
extern string Parameters_1= "Gann ZigZag";
extern int GannSwing=2;
extern string Parameters_2 = "ActiveWave";
extern int calc.NumBars=100;
extern int RequiredWaveHeight=40;
string buff_str;
string buff_str2;
string buff_str3;
string buff_str4;
string buff_str5;
string buff_str6;
string buff_str7;
string buff_str8;
int GSv_tend;
//---- buffers
double Upz[];
double Dnz[];
double sH[];
double sL[];
double aH[];
double aL[];
double fB[];
double lB[];
//----------
double CurH,CurL;
int lb,sp,lbars;
bool draw_up,draw_dn;
int oldWaveIndex = 1;
GSv_tend= GannSwing;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_ZIGZAG,STYLE_SOLID);
SetIndexStyle(1,DRAW_ZIGZAG,STYLE_SOLID);
SetIndexStyle(2,DRAW_NONE);
SetIndexStyle(3,DRAW_NONE);
SetIndexStyle(4,DRAW_NONE);
SetIndexStyle(5,DRAW_NONE);
SetIndexStyle(6,DRAW_NONE);
SetIndexStyle(7,DRAW_NONE);
SetIndexBuffer(0,Upz);
SetIndexBuffer(1,Dnz);
SetIndexBuffer(2,sH);
SetIndexBuffer(3,sL);
SetIndexBuffer(4,aH);
SetIndexBuffer(5,aL);
SetIndexBuffer(6,fB);
SetIndexBuffer(7,lB);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
SetIndexEmptyValue(2,0);
SetIndexEmptyValue(3,0);
SetIndexEmptyValue(4,-1);
SetIndexEmptyValue(5,-1);
SetIndexEmptyValue(6,-1);
SetIndexEmptyValue(7,-1);
SetIndexLabel(0,"z1");
SetIndexLabel(1,"z2");
SetIndexLabel(2,"sH");
SetIndexLabel(3,"sL");
SetIndexLabel(4,"aH");
SetIndexLabel(5,"aL");
SetIndexLabel(6,"fB");
SetIndexLabel(7,"lB");
//----
return(0);
}
//+------------------------------------------------------------------+
int deinit()
{
//----
for(int ix=0;ix<=Bars;ix++) {
buff_str = "ActiveWave"+ix;
ObjectDelete(buff_str);
}
for(int ii=0;ii<=Bars;ii++) {
buff_str2 = "Fibo"+ii;
ObjectDelete(buff_str2);
}
for(int iii=0;iii<=Bars;iii++) {
buff_str4 = "text"+iii;
ObjectDelete(buff_str4);
}
for(int iiii=0;iiii<=Bars;iiii++) {
buff_str5 = "V"+iiii;
ObjectDelete(buff_str5);
}
for(int iiiii=0;iiiii<=Bars;iiiii++) {
buff_str6 = "rc"+iiiii;
ObjectDelete(buff_str6);
}
for(int iiiiii=0;iiiiii<=Bars;iiiiii++) {
buff_str7 = "b"+iiiiii;
ObjectDelete(buff_str7);
}
for(int iiiiiii=0;iiiiiii<=Bars;iiiiiii++) {
buff_str8 = "bb"+iiiiiii;
ObjectDelete(buff_str8);
}
for( int ia=0; ia<=6; ia++ ){
for(int iiiiiiii=0;iiiiiiii<=Bars;iiiiiiii++) {
buff_str3 = "mml"+ia+iiiiiiii;
ObjectDelete(buff_str3);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
for(int ix=0;ix<=Bars;ix++) {
buff_str = "ActiveWave"+ix;
ObjectDelete(buff_str);
}
for(int ii=0;ii<=Bars;ii++) {
buff_str2 = "Fibo"+ii;
ObjectDelete(buff_str2);
}
for(int iii=0;iii<=Bars;iii++) {
buff_str4 = "text"+iii;
ObjectDelete(buff_str4);
}
for(int iiii=0;iiii<=Bars;iiii++) {
buff_str5 = "V"+iiii;
ObjectDelete(buff_str5);
}
for(int iiiii=0;iiiii<=Bars;iiiii++) {
buff_str6 = "rc"+iiiii;
ObjectDelete(buff_str6);
}
for(int iiiiii=0;iiiiii<=Bars;iiiiii++) {
buff_str7 = "b"+iiiiii;
ObjectDelete(buff_str7);
}
for(int iiiiiii=0;iiiiiii<=Bars;iiiiiii++) {
buff_str8 = "bb"+iiiiiii;
ObjectDelete(buff_str8);
}
for( int ia=0; ia<=6; ia++ ){
for(int iiiiiiii=0;iiiiiiii<=Bars;iiiiiiii++) {
buff_str3 = "mml"+ia+iiiiiiii;
ObjectDelete(buff_str3);
}
}
int shift,back,lasthighpos,lastlowpos,LastActivePos;
double val,res;
double curlow,curhigh,lasthigh,lastlow,LastActive;
int AWStartPos, AWEndPos;
double AWStart, AWEnd;
double FiboL, FiboH, FiboLC, FiboLR, FiboHR, FiboHC;
int counted_bars=IndicatorCounted();
int cb,index,limit,ai,i;
//----
if( !counted_bars<0 )
{
index=Bars-1;
if( index-counted_bars<2 )
{
limit=0;
}
else
{
limit=index-counted_bars-1;
}
}
else
{
Alert("");
return(-1);
}
//----
for( cb=limit; cb>=0; cb-- )
{
double nsb=iBarShift(NULL, PERIOD_D1, Time[cb]);
double RSI=iRSI(NULL,PERIOD_D1,14,PRICE_CLOSE,nsb);
ai=index-cb;
if( lbars!=Bars && lb==ai )
{
lbars=Bars;
continue;
}
if( lb!=ai )
{
lb=ai;
if( Upz[cb+1]>0 || Dnz[cb+1]>0 )
{
aH[cb]=High[cb+1];
aL[cb]=Low[cb+1];
}
else
{
if( High[cb+1]<=aH[cb+1] && Low[cb+1]>=aL[cb+1] )
{
aH[cb]=aH[cb+1];
aL[cb]=aL[cb+1];
sH[cb]=sH[cb+1];
sL[cb]=sL[cb+1];
}
else
{
if( High[cb+1]>aH[cb+1] )
{
aH[cb]=High[cb+1];
}
else
{
aH[cb]=aH[cb+1];
}
if( aL[cb+1]>0 )
{
if( Low[cb+1]<aL[cb+1] )
{
aL[cb]=Low[cb+1];
}
else
{
aL[cb]=aL[cb+1];
}
}
else
{
aL[cb]=Low[cb+1];
}
}
}
if( draw_up!=0 )
{
if( fB[cb+1]==1 )
{
sH[cb]=sH[cb+1]+1;
if( lB[cb+1]==0 )
{
sH[cb]=0;
sL[cb]=1;
}
}
else
{
if( fB[cb+1]==0 )
{
sL[cb]=sL[cb+1]+1;
if( lB[cb+1]==1 )
{
sH[cb]=1;
sL[cb]=0;
}
}
}
}
else
{
if( draw_dn!=0 )
{
if( fB[cb+1]==0 )
{
sL[cb]=sL[cb+1]+1;
if( lB[cb+1]==1 )
{
sH[cb]=1;
sL[cb]=0;
}
}
else
{
if( fB[cb+1]==1 )
{
sH[cb]=sH[cb+1]+1;
if( lB[cb+1]==0 )
{
sH[cb]=0;
sL[cb]=1;
}
}
}
}
else
{
if( fB[cb+1]==1 )
{
sH[cb]=sH[cb+1]+1;
sL[cb]=sL[cb+1];
if( lB[cb+1]==0 )
{
sL[cb]++;
}
}
else
{
if( fB[cb+1]==0 )
{
sH[cb]=sH[cb+1];
sL[cb]=sL[cb+1]+1;
if( lB[cb+1]==1 )
{
sH[cb]++;
}
}
}
}
}
if( GSv_tend>1 )
{
if( sH[cb]==GSv_tend && Upz[cb+1]>0 && High[cb+1]>High[cb+2] && Low[cb+1]<Low[cb+2] && fB[cb+1]==1 )
{
sL[cb]=1;
}
else
{
if( sL[cb]==GSv_tend && Dnz[cb+1]>0 && High[cb+1]>High[cb+2] && Low[cb+1]<Low[cb+2] && fB[cb+1]==0 )
{
sH[cb]=1;
}
}
}
CurH=0;
CurL=Low[cb];
}
if( High[cb]<=aH[cb] && Low[cb]>=aL[cb] )
{
continue;
}
if( High[cb]<=CurH && Low[cb]>=CurL )
{
continue;
}
if( High[cb]>CurH ) CurH=High[cb];
if( Low[cb] <CurL ) CurL=Low[cb];
Extr_seq(cb);
if( GSv_tend>1 )
{
if( fB[cb]>0 && sH[cb]==GSv_tend-1 && sL[cb]>0 )
{
sL[cb]=0;
}
else
{
if( fB[cb]>-1 && sL[cb]==GSv_tend-1 && sH[cb]>0 )
{
sH[cb]=0;
}
}
}
if( draw_up!=0 )
{
if( fB[cb]==1 )
{
if( sp!=ai )
{
Upz[index-sp]=0;
sp=ai;
}
Upz[cb]=High[cb];
if( lB[cb]==0 && (sL[cb]+1)>=GSv_tend && GSv_tend<2 )
{
Dnz[cb]=Low[cb];
draw_up=0;
draw_dn=1;
}
}
else
{
if( fB[cb]==0 )
{
if( (sL[cb]+1)>=GSv_tend )
{
Dnz[cb]=Low[cb];
sp=ai;
draw_up=0;
draw_dn=1;
if( lB[cb]==1 && (sH[cb]+1)>=GSv_tend )
{
Upz[cb]=High[cb];
draw_up=1;
draw_dn=0;
}
}
else
{
if( lB[cb]==1 )
{
Upz[index-sp]=0;
sp=ai;
Upz[cb]=High[cb];
}
}
}
}
}
else
{
if( draw_dn!=0 )
{
if( fB[cb]==1 )
{
if( (sH[cb]+1)>=GSv_tend )
{
Upz[cb]=High[cb];
sp=ai;
draw_up=1;
draw_dn=0;
if( lB[cb]==0 && (sL[cb]+1)>=GSv_tend )
{
Dnz[cb]=Low[cb];
draw_up=0;
draw_dn=1;
}
}
else
{
if( lB[cb]==0 )
{
Dnz[index-sp]=0;
sp=ai;
Dnz[cb]=Low[cb];
}
}
}
else
{
if( fB[cb]==0 )
{
if( sp!=ai )
{
Dnz[index-sp]=0;
sp=ai;
}
Dnz[cb]=Low[cb];
if( lB[cb]==1 && (sH[cb]+1)>=GSv_tend && GSv_tend<2 )
{
Upz[cb]=High[cb];
draw_up=1;
draw_dn=0;
}
}
}
}
else
{
if( fB[cb]==1 && (sH[cb]+1)>=GSv_tend )
{
Dnz[index]=Low[index];
Upz[cb]=High[cb];
draw_up=1;
sp=ai;
if( lB[cb]==0 && (sL[cb]+1)>=GSv_tend )
{
Dnz[cb]=Low[cb];
draw_up=0;
draw_dn=1;
}
}
else
{
if( fB[cb]==0 && (sL[cb]+1)>=GSv_tend )
{
Upz[index]=High[index];
Dnz[cb]=Low[cb];
draw_dn=1;
sp=ai;
if( lB[cb]==1 && (sH[cb]+1)>=GSv_tend )
{
Upz[cb]=High[cb];
draw_up=1;
draw_dn=0;
}
}
}
}
}
}
for(int shifta=0; shifta<=calc.NumBars; shifta++)
{
LastActive = -1;
LastActivePos = -1;
for(shift=shifta; shift<=Bars-2; shift++)
{
if(Dnz[shift]!=0.0 || Upz[shift]!=0.0 )
{
if(LastActive > 0)
{
if( (Upz[shift]==0.0 && MathAbs(LastActive - Dnz[shift]) >= RequiredWaveHeight*Point) || (Dnz[shift]==0.0 && MathAbs(LastActive - Upz[shift] ) >= RequiredWaveHeight*Point) )
{
AWStartPos = shift;
if(Dnz[shift]!=0.0) AWStart = Dnz[shift];
if(Upz[shift]!=0.0) AWStart = Upz[shift];
AWEndPos = LastActivePos;
AWEnd = LastActive;
buff_str = "ActiveWave"+shift;
buff_str2 = "Fibo"+shift;
buff_str4 = "text"+shift;
buff_str5 = "V"+shift;
buff_str6 = "rc"+shift;
buff_str7 = "b"+shift;
buff_str8 = "bb"+shift;
//if(ObjectFind("ActiveWave") != 0)
// {
ObjectCreate(buff_str, OBJ_TREND, 0, Time[AWStartPos], AWStart, Time[AWEndPos], AWEnd);
ObjectSet(buff_str, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(buff_str, OBJPROP_WIDTH, 3);
ObjectSet(buff_str, OBJPROP_RAY, false);
// }
// else
//{
// ObjectCreate("ActiveWave", OBJ_TREND, 0, Time[AWStartPos], AWStart, Time[AWEndPos], AWEnd);
// ObjectSet("ActiveWave", OBJPROP_STYLE, STYLE_SOLID);
// ObjectSet("ActiveWave", OBJPROP_COLOR, Red);
// ObjectSet("ActiveWave", OBJPROP_WIDTH, 3);
// ObjectSet("ActiveWave", OBJPROP_RAY, false);
// }
if(AWStart < AWEnd)
{
FiboL = AWStart;
FiboH = AWEnd;
ObjectSet(buff_str, OBJPROP_COLOR, Blue);
//ObjectCreate(buff_str2, OBJ_FIBO, 0, Time[AWEndPos], AWStart, Time[AWEndPos], AWEnd);
ObjectCreate(buff_str5, OBJ_TREND, 0, Time[AWEndPos], AWStart, Time[AWEndPos], AWEnd);
ObjectSet(buff_str5, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(buff_str5, OBJPROP_COLOR, Blue);
ObjectSet(buff_str5, OBJPROP_WIDTH, 2);
ObjectSet(buff_str5, OBJPROP_RAY, false);
}
else
{
ObjectSet(buff_str, OBJPROP_COLOR,Red);
FiboL = AWEnd;
FiboH = AWStart;
// ObjectCreate(buff_str2, OBJ_FIBO, 0, Time[AWEndPos], AWStart, Time[AWEndPos], AWEnd);
ObjectCreate(buff_str5, OBJ_TREND, 0, Time[AWEndPos], AWStart, Time[AWEndPos], AWEnd);
ObjectSet(buff_str5, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(buff_str5, OBJPROP_COLOR, Red);
ObjectSet(buff_str5, OBJPROP_WIDTH, 2);
ObjectSet(buff_str5, OBJPROP_RAY, false);
}
FiboLC = FiboL + (FiboH - FiboL)*0.25;
FiboLR = FiboL + (FiboH - FiboL)*0.382;
FiboHR = FiboL + (FiboH - FiboL)*0.618;
FiboHC = FiboL + (FiboH - FiboL)*0.75;
if(1==1)
{
ObjectSet(buff_str2, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(buff_str2, OBJPROP_COLOR, Green);
ObjectSet(buff_str2, OBJPROP_WIDTH, 1);
ObjectSet(buff_str2, OBJPROP_FIBOLEVELS, 6);
ObjectSet(buff_str2, OBJPROP_RAY, false);
ObjectSet(buff_str2, OBJPROP_FIRSTLEVEL+0, 0);
ObjectSet(buff_str2, OBJPROP_FIRSTLEVEL+1, 0.25);
ObjectSet(buff_str2, OBJPROP_FIRSTLEVEL+2, 0.382);
ObjectSet(buff_str2, OBJPROP_FIRSTLEVEL+3, 0.618);
ObjectSet(buff_str2, OBJPROP_FIRSTLEVEL+4, 0.75);
ObjectSet(buff_str2, OBJPROP_FIRSTLEVEL+5, 1);
//
if (RSI == 50.0)
Comment("\n","ICWR: Daily RSI is Flat ",RSI);
else if (RSI > 50.0)
Comment("\n","ICWR: Daily RSI is Long ",RSI);
else if (RSI < 50.0)
Comment("ICWR: Daily RSI is Short ",RSI);
if(RSI == 50.0)
{
ObjectCreate(buff_str4, OBJ_TEXT, 0, Time[shifta+5], AWEnd+3*Point);
ObjectSetText(buff_str4,"Daily RSI is Flat ", 8, "Arial", Gray);
}
if(RSI > 50)
{
ObjectCreate(buff_str4, OBJ_TEXT, 0, Time[shifta+5], AWEnd+3*Point);
ObjectSetText(buff_str4,"Daily RSI is Long ", 8, "Arial", LimeGreen);
}
if(RSI < 50)
{
ObjectCreate(buff_str4, OBJ_TEXT, 0, Time[shifta+5], AWEnd+3*Point);
ObjectSetText(buff_str4, "Daily RSI is Short ", 8, "Arial", Red);
}
for( int yi=0; yi<=6; yi++ ){
buff_str3 = "mml"+yi+shift;
if (yi==1) {
ObjectCreate(buff_str3, OBJ_TREND, 0, Time[AWEndPos], FiboLC, Time[shifta]+100*Period(), FiboLC);
//ObjectMove(buff_str3, 0, Time[AWEndPos], FiboLC );
//ObjectMove(buff_str3, 0, Time[shifta]+100*Period(), FiboLC );
}
if (yi==2)
ObjectCreate(buff_str3, OBJ_TREND, 0, Time[AWEndPos], FiboLR, Time[shifta]+100*Period(), FiboLR);
if (yi==3)
ObjectCreate(buff_str3, OBJ_TREND, 0, Time[AWEndPos], FiboHR, Time[shifta]+100*Period(), FiboHR);
if (yi==4)
ObjectCreate(buff_str3, OBJ_TREND, 0, Time[AWEndPos], FiboHC, Time[shifta]+100*Period(), FiboHC);
if (yi==5)
ObjectCreate(buff_str3, OBJ_TREND, 0, Time[AWEndPos], AWStart, Time[shifta]+100*Period(), AWStart);
if (yi==6)
ObjectCreate(buff_str3, OBJ_TREND, 0, Time[AWEndPos], AWEnd, Time[shifta]+100*Period(), AWEnd);
ObjectSet(buff_str3, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(buff_str3, OBJPROP_COLOR, Gold);
ObjectSet(buff_str3, OBJPROP_WIDTH, 1);
ObjectSet(buff_str3, OBJPROP_RAY, false);
ObjectCreate(buff_str6,OBJ_RECTANGLE, 0, Time[AWEndPos], FiboLR, Time[shifta]+100*Period(), FiboHR);
ObjectSet(buff_str6, OBJPROP_COLOR, Gray);
ObjectCreate(buff_str7,OBJ_RECTANGLE, 0, Time[AWEndPos], FiboLC, Time[shifta]+100*Period(), FiboL);
ObjectSet(buff_str7, OBJPROP_COLOR, IndianRed);
ObjectCreate(buff_str8,OBJ_RECTANGLE, 0, Time[AWEndPos], FiboHC, Time[shifta]+100*Period(), FiboH);
ObjectSet(buff_str8, OBJPROP_COLOR, Green);
}
}
else
{
}
break;
}
}
if(Dnz[shift]!=0.0) LastActive = Dnz[shift];
if(Upz[shift]!=0.0) LastActive = Upz[shift];
LastActivePos = shift;
}
}
}
}
void Extr_seq(int curb)
{
//----
if( fB[curb]<0 )
{
if( High[curb]>aH[curb] && Low[curb]<aL[curb] )
{
if( Open[curb]>aH[curb] )
{
fB[curb]=1;
lB[curb]=0;
}
else
{
if( Open[curb]<aL[curb] )
{
fB[curb]=0;
lB[curb]=1;
}
else
{
if( Close[curb]>aH[curb] && Close[curb]>=Open[curb] )
{
fB[curb]=0;
lB[curb]=1;
}
else
{
if( Close[curb]>aL[curb] && Close[curb]<=Open[curb] )
{
fB[curb]=1;
lB[curb]=0;
}
else
{
if( Close[curb]>Open[curb] )
{
fB[curb]=0;
lB[curb]=1;
}
else
{
if( Close[curb]<Open[curb] )
{
fB[curb]=1;
lB[curb]=0;
}
else
{
if( MathAbs(Open[curb]-aL[curb])<MathAbs(Open[curb]-aH[curb]) )
{
fB[curb]=0;
lB[curb]=1;
}
else
{
if( MathAbs(Open[curb]-aL[curb])>MathAbs(Open[curb]-aH[curb]) )
{
fB[curb]=1;
lB[curb]=0;
}
else
{
if( MathAbs(Open[curb]-Low[curb])>=MathAbs(Open[curb]-High[curb]) )
{
fB[curb]=0;
lB[curb]=1;
}
else
{
fB[curb]=1;
lB[curb]=0;
}
}
}
}
}
}
}
}
}
}
else
{
if( High[curb]>aH[curb] )
{
fB[curb]=1;
}
else
{
fB[curb]=0;
}
}
}
else
{
if( (Low[curb]>=aL[curb] || Close[curb]==High[curb] ) && High[curb]>aH[curb] )
{
lB[curb]=1;
}
else
{
if( (High[curb]<=aH[curb] || Close[curb]==Low[curb]) && Low[curb]<aL[curb] )
{
lB[curb]=0;
}
}
}
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---