Ever wanted to know what is the maximum price range for a particular currency pair?
For example: You want to know the largest/average monthly price range for GBPUSD for the past 12 months?
Here's a code for this. I've also added the LongSwap and ShortSwap interests. For those who are looking for a cross-broker Swap Hedge (one-side pay swap interest, one-side do not charge swap interest), this is useful to know which currency pair pays the highest interest.
I've also included a SwpIndex especially for those who are exploring the Interest Swap Hedging trying to figure out which currency pair is the best for that purpose. Basically, it takes into consideration the Interest Swap paid/charge, the longest price range for that period and also the (current) spread. These are the factors that determine the most suitable pair for this purpose.
Drop this EA on each of the currency pair chart in MT4 (MetaTrader 4).
//+------------------------------------------------------------------+
//| PriceRangeOfChart.mq4 |
//| http://www.fs.com.my |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, EMail: joseph.lee [a.t.] f s.c o m.my"
#property link "http://www.fs.com.my"
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
double
viPricePerPip
= 0.0001;
double
viPointsToPip
= 1;
string
vsLeftTab
= " ";
//=================================================
int init() {
if((Digits == 2) || (Digits == 3)) {viPricePerPip
= 0.01;}
if((Digits == 3) || (Digits == 5)) {viPointsToPip
= 10;}
}
//=================================================
int start() {
int
viIndex;
double
viLength;
double
viStartTick = GetTickCount();
double
viSpread
= (Ask-Bid)/viPricePerPip;
double
viPipValue
= MarketInfo( Symbol(), MODE_TICKVALUE) * viPointsToPip;
int
pvaiCandlePeriods[5];
pvaiCandlePeriods[0]
= 7;
pvaiCandlePeriods[1]
= 12;
pvaiCandlePeriods[2]
= 14;
pvaiCandlePeriods[3]
= 24;
pvaiCandlePeriods[4]
= 30;
double viSwapLongInPips
= MarketInfo( Symbol(), MODE_SWAPLONG );
double viSwapShortInPips= MarketInfo( Symbol(), MODE_SWAPSHORT );
string pvsDisplay = "";
for(viIndex=0; viIndex
viLength = fniGetAvgCandleLen(pvaiCandlePeriods[viIndex]);
pvsDisplay = pvsDisplay + "\n" + vsLeftTab + "Avg Candle (" + pvaiCandlePeriods[viIndex] + "): " + DoubleToStr(viLength,1) + "pips, ";
pvsDisplay = pvsDisplay + "SWPIndex: ";
if( viLength != 0 ) {
pvsDisplay = pvsDisplay + DoubleToStr(1000*viSwapLongInPips/(viLength*viSpread), 2 ) + " / ";
pvsDisplay = pvsDisplay + DoubleToStr(1000*viSwapShortInPips/(viLength*viSpread), 2 );
}
}
pvsDisplay = pvsDisplay + "\n";
for(viIndex=0; viIndex viLength = fniGetLongestCandleLen(pvaiCandlePeriods[viIndex]);
pvsDisplay = pvsDisplay + "\n" + vsLeftTab + "Longest Candle (" + pvaiCandlePeriods[viIndex] + "): " + DoubleToStr(viLength,1) + "pips, ";
pvsDisplay = pvsDisplay + "SWPIndex: ";
if( viLength != 0 ) {
pvsDisplay = pvsDisplay + DoubleToStr(1000*viSwapLongInPips/(viLength*viSpread), 2 ) + " / ";
pvsDisplay = pvsDisplay + DoubleToStr(1000*viSwapShortInPips/(viLength*viSpread), 2 );
}
}
Comment(
"\n" + vsLeftTab + "Chart Candle LENGTH (" + Symbol() + ")\n" + vsLeftTab + "======================"
, "\n" + vsLeftTab + "Current Ask/Bid: "
+ DoubleToStr( Ask, Digits ) + " / "
+ DoubleToStr( Bid, Digits )
+ " (" + DoubleToStr(viSpread,1) + "pips Spread)"
+ " Pip Value: $" + DoubleToStr(viPipValue,2)
, "\n" + vsLeftTab + "Swap Long/Short: "
+ DoubleToStr(viSwapLongInPips, 2) + "pips / "
+ DoubleToStr(viSwapShortInPips, 2) + "pips"
, "\n"
, pvsDisplay
);
return(0);
}
//====================================================================
double fniGetAvgCandleLen( int pviCount ) {
double viTotalValue = 0.0;
for( int viIndex=1; viIndex<=pviCount; viIndex++ ) {
viTotalValue += (iHigh( Symbol(), 0, viIndex ) - iLow( Symbol(), 0, viIndex ))/viPricePerPip;
}
if( pviCount != 0 )
return( viTotalValue/pviCount );
else
return( 0 );
}
double fniGetLongestCandleLen( int pviCount ) {
double viLength = 0.0;
double viLongest = 0.0;
for( int viIndex=1; viIndex<=pviCount; viIndex++ ) {
viLength = (iHigh( Symbol(), 0, viIndex ) - iLow( Symbol(), 0, viIndex ))/viPricePerPip;
if( viLength > viLongest ) viLongest = viLength;
}
return( viLongest );
}
double fniGetShortestCandleLen( int pviCount ) {
double viLength = 0.0;
double viShortest = 0.0;
for( int viIndex=1; viIndex<=pviCount; viIndex++ ) {
viLength = (iHigh( Symbol(), 0, viIndex ) - iLow( Symbol(), 0, viIndex ))/viPricePerPip;
if( viLength < viShortest ) viShortest = viLength;
}
return( viShortest );
}
//====================================================================