Baluda wrote:For Coders Only!
Here is a libary to get to all NB 10.5 CSS values you want. Include this internally or externally:
Code: Select all //+------------------------------------------------------------------+
//| LibCSS.mq4 |
//| Copyright 2013, Deltabron - Paul Geirnaerdt |
//| http://www.deltabron.nl |
//+------------------------------------------------------------------+
#define libCSS.version "v1.0.0"
#define libCSS.EPSILON 0.00000001
#define libCSS.CURRENCYCOUNT 8
//+------------------------------------------------------------------+
//| Release Notes |
//+------------------------------------------------------------------+
// v1.0.0, 5/7/13
// * Initial release
// * NanningBob's 10.5 rules apply
bool libCSS.sundayCandlesDetected = false;
bool libCSS.addSundayToMonday = true;
bool libCSS.useOnlySymbolOnChart = true;
string libCSS.symbolsToWeigh = "GBPNZD,EURNZD,GBPAUD,GBPCAD,GBPJPY,GBPCHF,CADJPY,EURCAD,EURAUD,USDCHF,GBPUSD,EURJPY,NZDJPY,AUDCHF,AUDJPY,USDJPY,EURUSD,NZDCHF,CADCHF,AUDNZD,NZDUSD,CHFJPY,AUDCAD,USDCAD,NZDCAD,AUDUSD,EURCHF,EURGBP";
int libCSS.symbolCount;
string libCSS.symbolNames[];
string libCSS.currencyNames[libCSS.CURRENCYCOUNT] = { "USD", "EUR", "GBP", "CHF", "JPY", "AUD", "CAD", "NZD" };
double libCSS.currencyValues[libCSS.CURRENCYCOUNT]; // Currency slope strength
double libCSS.currencyOccurrences[libCSS.CURRENCYCOUNT]; // Holds the number of occurrences of each currency in symbols
//+------------------------------------------------------------------+
//| libCSS.init() |
//+------------------------------------------------------------------+
void libCSS.init()
{
libCSS.initSymbols();
libCSS.sundayCandlesDetected = false;
for ( int i = 0; i < 8; i++ )
{
if ( TimeDayOfWeek( iTime( NULL, PERIOD_D1, i ) ) == 0 )
{
libCSS.sundayCandlesDetected = true;
break;
}
}
return;
}
//+------------------------------------------------------------------+
//| Initialize Symbols Array |
//+------------------------------------------------------------------+
int libCSS.initSymbols()
{
int i;
// Get extra characters on this crimmal's symbol names
string symbolExtraChars = StringSubstr(Symbol(), 6, 4);
// Trim user input
libCSS.symbolsToWeigh = StringTrimLeft(libCSS.symbolsToWeigh);
libCSS.symbolsToWeigh = StringTrimRight(libCSS.symbolsToWeigh);
// Add extra comma
if (StringSubstr(libCSS.symbolsToWeigh, StringLen(libCSS.symbolsToWeigh) - 1) != ",")
{
libCSS.symbolsToWeigh = StringConcatenate(libCSS.symbolsToWeigh, ",");
}
// Split user input
i = StringFind( libCSS.symbolsToWeigh, "," );
while ( i != -1 )
{
int size = ArraySize(libCSS.symbolNames);
string newSymbol = StringConcatenate(StringSubstr(libCSS.symbolsToWeigh, 0, i), symbolExtraChars);
if ( MarketInfo( newSymbol, MODE_TRADEALLOWED ) > libCSS.EPSILON )
{
ArrayResize( libCSS.symbolNames, size + 1 );
// Set array
libCSS.symbolNames[size] = newSymbol;
}
// Trim symbols
libCSS.symbolsToWeigh = StringSubstr(libCSS.symbolsToWeigh, i + 1);
i = StringFind(libCSS.symbolsToWeigh, ",");
}
// Kill unwanted symbols from array
if ( libCSS.useOnlySymbolOnChart )
{
libCSS.symbolCount = ArraySize(libCSS.symbolNames);
string tempNames[];
for ( i = 0; i < libCSS.symbolCount; i++ )
{
for ( int j = 0; j < libCSS.CURRENCYCOUNT; j++ )
{
if ( StringFind( Symbol(), libCSS.currencyNames[j] ) == -1 )
{
continue;
}
if ( StringFind( libCSS.symbolNames[i], libCSS.currencyNames[j] ) != -1 )
{
size = ArraySize( tempNames );
ArrayResize( tempNames, size + 1 );
tempNames[size] = libCSS.symbolNames[i];
break;
}
}
}
for ( i = 0; i < ArraySize( tempNames ); i++ )
{
ArrayResize( libCSS.symbolNames, i + 1 );
libCSS.symbolNames[i] = tempNames[i];
}
}
libCSS.symbolCount = ArraySize(libCSS.symbolNames);
// Print("symbolCount: ", symbolCount);
for ( i = 0; i < libCSS.symbolCount; i++ )
{
// Increase currency occurrence
int currencyIndex = libCSS.getCurrencyIndex(StringSubstr(libCSS.symbolNames[i], 0, 3));
libCSS.currencyOccurrences[currencyIndex]++;
currencyIndex = libCSS.getCurrencyIndex(StringSubstr(libCSS.symbolNames[i], 3, 3));
libCSS.currencyOccurrences[currencyIndex]++;
}
}
//+------------------------------------------------------------------+
//| getCurrencyIndex(string currency) |
//+------------------------------------------------------------------+
int libCSS.getCurrencyIndex(string currency)
{
for (int i = 0; i < libCSS.CURRENCYCOUNT; i++)
{
if (libCSS.currencyNames[i] == currency)
{
return(i);
}
}
return (-1);
}
//+------------------------------------------------------------------+
//| getSlope() |
//+------------------------------------------------------------------+
double libCSS.getSlope( string symbol, int tf, int shift )
{
double dblTma, dblPrev;
int shiftWithoutSunday = shift;
if ( libCSS.addSundayToMonday && libCSS.sundayCandlesDetected && tf == PERIOD_D1 )
{
if ( TimeDayOfWeek( iTime( symbol, PERIOD_D1, shift ) ) == 0 ) shiftWithoutSunday++;
}
double atr = iATR(symbol, tf, 25, shiftWithoutSunday + 10) / 10;
double gadblSlope = 0.0;
if ( atr != 0 )
{
dblTma = libCSS.calcTmaTrue( symbol, tf, shiftWithoutSunday );
dblPrev = libCSS.calcPrevTrue( symbol, tf, shiftWithoutSunday );
gadblSlope = ( dblTma - dblPrev ) / atr;
}
return ( gadblSlope );
}
//+------------------------------------------------------------------+
//| calcTmaTrue() |
//+------------------------------------------------------------------+
double libCSS.calcTmaTrue( string symbol, int tf, int inx )
{
return ( iMA( symbol, tf, 3, 0, MODE_LWMA, PRICE_CLOSE, inx ) );
}
//+------------------------------------------------------------------+
//| calcPrevTrue() |
//+------------------------------------------------------------------+
double libCSS.calcPrevTrue( string symbol, int tf, int inx )
{
double dblSum = iClose( symbol, tf, inx + 1 ) * 3;
double dblSumw = 3;
int jnx, knx;
dblSum += iClose( symbol, tf, inx ) * 20;
dblSumw += 20;
for ( jnx = 1, knx = 20; jnx <= 20; jnx++, knx-- )
{
dblSum += iClose( symbol, tf, inx + 1 + jnx ) * knx;
dblSumw += knx;
}
return ( dblSum / dblSumw );
}
//+------------------------------------------------------------------+
//| getCSS( double& CSS[], int tf, int shift ) |
//+------------------------------------------------------------------+
void libCSS.getCSS( double& css[], int tf, int shift )
{
static double volume;
if ( volume != iVolume("EURUSD", PERIOD_M1, 0) )
{
int i;
ArrayInitialize(libCSS.currencyValues, 0.0);
// Get Slope for all symbols and totalize for all currencies
for ( i = 0; i < libCSS.symbolCount; i++ )
{
double slope = libCSS.getSlope(libCSS.symbolNames[i], tf, shift);
libCSS.currencyValues[libCSS.getCurrencyIndex(StringSubstr(libCSS.symbolNames[i], 0, 3))] += slope;
libCSS.currencyValues[libCSS.getCurrencyIndex(StringSubstr(libCSS.symbolNames[i], 3, 3))] -= slope;
}
ArrayResize( css, libCSS.CURRENCYCOUNT );
for ( i = 0; i < libCSS.CURRENCYCOUNT; i++ )
{
// average
if ( libCSS.currencyOccurrences[i] > 0 ) libCSS.currencyValues[i] /= libCSS.currencyOccurrences[i]; else libCSS.currencyValues[i] = 0;
}
}
for ( i = 0; i < libCSS.CURRENCYCOUNT; i++ )
{
css[i] = libCSS.currencyValues[i];
}
volume = iVolume("EURUSD", PERIOD_M1, 0);
}
//+------------------------------------------------------------------+
//| getCSSCurrency(string currency, int tf, int shift) |
//+------------------------------------------------------------------+
double libCSS.getCSSCurrency( string currency, int tf, int shift )
{
double css[];
libCSS.getCSS( css, tf, shift );
return ( css[libCSS.getCurrencyIndex(currency)] );
}
//+------------------------------------------------------------------+
//| getCSSdiff(int tf, int shift) |
//+------------------------------------------------------------------+
double libCSS.getCSSDiff( string symbol, int tf, int shift )
{
double css[];
libCSS.getCSS( css, tf, shift );
double diffLong = css[libCSS.getCurrencyIndex(StringSubstr(symbol, 0, 3))];
double diffShort = css[libCSS.getCurrencyIndex(StringSubstr(symbol, 3, 3))];
return ( diffLong - diffShort );
}
InitializationCode: Select all // Put this is in your EA/Indicator init()
libCSS.init();
Get all css'
Code: Select all // Create array
double myCSS[];
// Call library
libCSS.getCSS( myCSS, PERIOD_H4, 0 );
// Results are in array
// Order of array: "USD", "EUR", "GBP", "CHF", "JPY", "AUD", "CAD", "NZD"
// e.g. myCSS[2] is css for GBP
Get css for one currency
Code: Select all // Get css for specific currency
double cssEUR = libCSS.getCSSCurrency( "EUR", PERIOD_H1, 0 );
Get diff for symbol
Code: Select all // Get css diff for symbol, positive is long, negative is short
double myDiff = libCSS.getCSSDiff( Symbol(), PERIOD_H4, 0 );
Enjoy,
Please let me know what you come up with.
Paul
Excellent work Paul, many thanks for your help.
Andy |