Jump to content

Add a invert option to this indicator dollar index


toddanderson

Recommended Posts

Could someone please add a Invert option to this dollar index indicator

so when you use it against the eurusd or usdchf you have a better view

on the index verse the pair

 

Thank you for any help

 

 

//+------------------------------------------------------------------+

//| usdx histo |

//| usdx histo.mq4 |

//| |

//+------------------------------------------------------------------+

#property copyright "copyleft mladen"

#property link "[email protected]"

 

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_color1 Red

#property indicator_color2 Green

#property indicator_color3 DimGray

#property indicator_width3 2

 

//

//

//

//

//

 

extern int SmoothPeriod = 4;

extern bool ShowHisto = true;

 

//

//

//

//

//

 

double gbuffer[];

double rbuffer[];

double mbuffer[];

double wbuffer[];

string symbols[] = {"EURUSD","USDJPY","GBPUSD","USDCAD","USDSEK","USDCHF"};

double weights[] = {-0.576,-0.136,-0.119,-0.091,-0.042,-0.036};

bool divide[] = {false,true,false,true,true,true};

 

 

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

//

//

//

//

//

 

int init()

{

IndicatorBuffers(4);

SetIndexBuffer(0,rbuffer); SetIndexStyle(0,DRAW_HISTOGRAM);

SetIndexBuffer(1,gbuffer); SetIndexStyle(1,DRAW_HISTOGRAM);

SetIndexBuffer(2,mbuffer);

SetIndexBuffer(3,wbuffer);

IndicatorShortName("USDX ");

return(0);

}

 

//

//

//

//

//

 

int start()

{

int counted_bars=IndicatorCounted();

int i,limit;

 

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

 

//

//

//

//

//

 

 

for(i=limit; i>=0; i--)

{

double product = 0.00;

bool error = false;

 

//

//

//

//

//

 

mbuffer = EMPTY_VALUE;

wbuffer = EMPTY_VALUE;

for (int k=0; k<6; k++)

{

double rateWeight = rateWeight(i,k,error);

if ( error ) break;

if ( product == 0.00)

product = rateWeight;

else product *= rateWeight;

}

if ( error ) continue;

 

//

//

//

//

//

 

wbuffer = product*50.14348112;

mbuffer = smooth(i,SmoothPeriod);

if (ShowHisto)

{

rbuffer = rbuffer[i+1];

gbuffer = gbuffer[i+1];

if (mbuffer > mbuffer[i+1]) { gbuffer = mbuffer; rbuffer = EMPTY_VALUE; }

if (mbuffer < mbuffer[i+1]) { rbuffer = mbuffer; gbuffer = EMPTY_VALUE; }

}

}

return(0);

}

 

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

//

//

//

//

 

double rateWeight(int i, int k, bool& error)

{

double price = iClose(symbols[k],0,i);

double weight = 0.00;

 

if (price == 0) { error = true; return(0); }

if (divide[k])

weight = 1/price;

else weight = price;

return(MathPow(weight,weights[k]));

}

 

//

//

//

//

//

 

#define Pi 3.141592653589793238462643

 

double smoothCoeffs[];

double smoothDivisor;

bool smoothInitialized = false;

int smoothLength = 0;

 

//

//

//

//

//

 

double smooth(int i, int length)

{

//

//

//

//

//

if (!smoothInitialized || length != smoothLength)

{

smoothInitialized = true;

smoothLength = MathMax(length,1);

 

//

//

//

//

//

 

ArrayResize(smoothCoeffs, smoothLength);

smoothCoeffs[0] = 1;

smoothDivisor = 1;

for (int k = 1; k < smoothLength; k++)

{

double temp = 1 << k / Pi;

smoothCoeffs[k] = MathSin(temp) / temp;

smoothDivisor += smoothCoeffs[k];

}

}

 

//

//

//

//

//

 

double sum = 0;

for (int l = 0; l < smoothLength; l++) sum += wbuffer[l+i]*smoothCoeffs[l];

return(sum/smoothDivisor);

}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...