//+---------------------------------------------------------------------+ //| Copyright © 2008, Orest @ ForexFactory | //+---------------------------------------------------------------------+ #property copyright "Copyright © 2008" #property link "http://www.metaquotes.net" #property indicator_chart_window //+------------------------------------------------------------------+ //| User Inputs | //+------------------------------------------------------------------+ extern string estrBasicSettings = "----- Basic settings -----"; extern string estrDateFormat = "----- yyyy.mm.dd hh:mm -----"; extern string estrOpenDate = ""; extern double edblLots = 0.1; extern int eintGroupCount = 12; extern bool eblnProfitPips = true; //+------------------------------------------------------------------+ //| Constants | //+------------------------------------------------------------------+ string cFONT = "Lucida Console Bold"; //+------------------------------------------------------------------+ //| Global Variables | //+------------------------------------------------------------------+ double gdblLotSize; datetime gdtOpenDate; int gintStartShift; int gintWindow; string gstrShortName; //********************************************************************************************* //* STANDARD INDICATOR FUNCTIONS BELOW * //********************************************************************************************* //+------------------------------------------------------------------+ //| init() | //+------------------------------------------------------------------+ int init() { // Set global variables gdblLotSize = MarketInfo( Symbol(), MODE_LOTSIZE ); initializePairData(); if ( estrOpenDate == "" ) gdtOpenDate = StrToTime( TimeToStr( TimeCurrent(), TIME_DATE ) + " 00:00:00" ); else gdtOpenDate = StrToTime( estrOpenDate ); gstrShortName = "T101_Dashboard" + " --- " + TimeToStr( gdtOpenDate, TIME_DATE | TIME_MINUTES ); IndicatorShortName( gstrShortName ); Comment( "" ); return(0); } //+------------------------------------------------------------------+ //| deinit() | //+------------------------------------------------------------------+ int deinit() { deleteObjects(); return(0); } //+------------------------------------------------------------------+ //| start() | //+------------------------------------------------------------------+ int start() { gintStartShift = iBarShift( NULL, 0, gdtOpenDate, true ); // Get the window for this indicator gintWindow = WindowFind( gstrShortName ); if ( gintWindow == -1 ) gintWindow = 0; if ( isNewBar() ) { // Since we have a new bar, delete all objects and redraw everything deleteObjects(); // Draw the left-most column grid lines and headers drawHdrColumnLines(); // Process history and current data processHistory( gintStartShift, true ); processGroup( 0, true ); } else { if ( gintStartShift >= 0 ) { // Not a new bar, just process current data processGroup( 0, false ); } } WindowRedraw(); return( 0 ); } //********************************************************************************************* //* MAIN PROCESSING FUNCTIONS BELOW * //********************************************************************************************* //+------------------------------------------------------------------+ //| processHistory() | //+------------------------------------------------------------------+ void processHistory( int intShift, bool blnLines ) { int intMax = intShift; // Don't want the history group count to be more than user specified if ( intMax > eintGroupCount ) intMax = eintGroupCount; // Process each history group for ( int inx = 1; inx <= intMax; inx++ ) { processGroup( inx, blnLines ); } } //+------------------------------------------------------------------+ //| processGroup() | //+------------------------------------------------------------------+ void processGroup( int intGroupShift, bool blnDrawLines ) { int intProfit, intTemp, intID; double dblOpen, dblClose, dblTick, dblPoint; string strName; int aintPairsDisplay[14]; int aintProfit[14]; int aintTotals[2][8]; datetime dtCcyStartTime = Time[gintStartShift]; datetime dtCcyEndTime = Time[intGroupShift]; // Initialize arrays ArrayInitialize( aintPairsDisplay, 0 ); ArrayInitialize( aintProfit, 0 ); ArrayInitialize( aintTotals, 0 ); // Draw the grid lines for this group if ( blnDrawLines ) drawGroupColumnLines( intGroupShift ); // Loop through each of the currency pairs, calculating price data for each for ( int knx = 0; knx < 14; knx++ ) { strName = getPairNameByID( knx ); // Get the Open and Close price for each pair. This contains special // logic to verify the bar shift and the time are the same for each pair if ( dtCcyStartTime == iTime( strName, 0, gintStartShift ) ) dblOpen = iOpen( strName, 0, gintStartShift ); else dblOpen = iOpen( strName, 0, getBarShift( strName, dtCcyStartTime ) ); if ( dtCcyEndTime == iTime( strName, 0, intGroupShift ) ) dblClose = iClose( strName, 0, intGroupShift ); else dblClose = iClose( strName, 0, getBarShift( strName, dtCcyEndTime ) ); if ( eblnProfitPips ) { // Display Profit in Pips dblPoint = MarketInfo( strName, MODE_POINT ); if ( isBuyPair( knx ) ) intProfit = NormalizeDouble( ( dblClose - dblOpen ) / dblPoint, 0 ); else intProfit = NormalizeDouble( ( dblOpen - dblClose ) / dblPoint, 0 ); } else { // Display profit in MT4 account currency dblTick = MarketInfo( strName, MODE_TICKVALUE ); if ( isBuyPair( knx ) ) intProfit = NormalizeDouble( dblTick * edblLots * gdblLotSize * ( dblClose - dblOpen ), 0 ); else intProfit = NormalizeDouble( dblTick * edblLots * gdblLotSize * ( dblOpen - dblClose ), 0 ); } aintProfit[knx] = intProfit; } // Initialize the list of pairs to display for ( int bnx = 0; bnx < 14; bnx++ ) { aintPairsDisplay[bnx] = bnx; } // Populate the list of pairs to display, sorted by profit for ( int inx = 0; inx < 14; inx++ ) { for ( int jnx = inx + 1; jnx < 14; jnx++ ) { if ( aintProfit[inx] < aintProfit[jnx] ) { intTemp = aintProfit[jnx]; aintProfit[jnx] = aintProfit[inx]; aintProfit[inx] = intTemp; intTemp = aintPairsDisplay[jnx]; aintPairsDisplay[jnx] = aintPairsDisplay[inx]; aintPairsDisplay[inx] = intTemp; } } } // Currency Total processing for( int dnx = 0; dnx < 14; dnx++ ) { intID = aintPairsDisplay[dnx]; strName = getPairNameByID( intID ); // Add this pair data to the currency totals addTotalForCcy( intID, aintProfit[dnx], aintTotals ); // Add this pair data to the grand totals if( isBuyPair( intID ) ) aintTotals[0][7] += aintProfit[dnx]; else aintTotals[1][7] += aintProfit[dnx]; } // Now that we have all of the current data, let's draw it drawGroupDetail( intGroupShift, aintPairsDisplay, aintProfit ); drawGroupTotals( intGroupShift, aintTotals ); } //+------------------------------------------------------------------+ //| addTotalForCcy() | //+------------------------------------------------------------------+ int addTotalForCcy( int intPairID, int intProfit, int& aintCcyTotals[][] ) { bool blnBuy = isBuyPair( intPairID ); string strName; string strPair = getPairNameByID( intPairID ); // Loop through all currencies for ( int inx = 0; inx < 7; inx++ ) { strName = getCcyNameByID( inx ); if ( blnBuy ) { if ( StringSubstr( strPair, 0, 3 ) == strName ) aintCcyTotals[0][inx] += intProfit; else if ( StringSubstr( strPair, 3, 3 ) == strName ) aintCcyTotals[0][inx] -= intProfit; } else { if ( StringSubstr( strPair, 0, 3 ) == strName ) aintCcyTotals[1][inx] -= intProfit; else if ( StringSubstr( strPair, 3, 3 ) == strName ) aintCcyTotals[1][inx] += intProfit; } } } //********************************************************************************************* //* DRAWING FUNCTIONS BELOW * //********************************************************************************************* //+------------------------------------------------------------------+ //| drawHdrColumnLines() | //+------------------------------------------------------------------+ void drawHdrColumnLines() { string strLabel; int intX, intY; // Draw the horizontal cell dividers - top to bottom drawHL( "HL0", 10, gintWindow, 2, 10, White ); drawHL( "HL1", 10, gintWindow, 2, 31, White ); drawHL( "HL2", 10, gintWindow, 2, 155, White ); drawHL( "HL3", 10, gintWindow, 2, 278, White ); drawHL( "HL4", 10, gintWindow, 2, 393, White ); drawHL( "HL5", 10, gintWindow, 2, 416, White ); drawHL( "HL6", 10, gintWindow, 2, 441, White ); // Draw the vertical cell dividers drawVL( "HL7", 50, gintWindow, 50, 21, White ); drawVL( "HL8", 57, gintWindow, 50, 221, White ); // Draw the Time Header drawLabel( "LH0", "Time", gintWindow, 5, 23, White, 9, cFONT ); // Draw the Header for sorted pair ranking (14 pairs) intY = 27; for ( int jnx = 1; jnx <= 14; jnx++ ) { if ( jnx < 10 ) intX = 14; else intX = 12; if ( jnx == 8 ) intY += 21; else intY += 17; drawLabel( "LH" + jnx, jnx, gintWindow, intX, intY, White, 9, cFONT ); } // Draw the Headers for currency totals (7 currencies) intY += 4; for ( int inx = 0; inx < 7; inx++ ) { strLabel = "LH" + (15 + inx); intY += 16; drawLabel( strLabel, getCcyNameByID( inx ), gintWindow, 9, intY, White, 9, cFONT ); } // Draw the headers for grand totals and signals drawLabel( "LH22", "TOT", gintWindow, 9, intY + 22, White, 9, cFONT ); drawLabel( "LH23", "SIG", gintWindow, 10, intY + 46, White, 9, cFONT ); } //+------------------------------------------------------------------+ //| drawGroupColumnLines() | //+------------------------------------------------------------------+ void drawGroupColumnLines( int intGroup ) { int intX1 = 42 + ( intGroup * 130 ); int intX2 = 50 + ( ( intGroup + 1 ) * 130 ); // Draw the horizontal cell dividers - top to bottom drawHL( "G" + intGroup + "L0", 33, gintWindow, intX1, 10, White ); drawHL( "G" + intGroup + "L1", 33, gintWindow, intX1, 31, White ); drawHL( "G" + intGroup + "L2", 33, gintWindow, intX1, 155, White ); drawHL( "G" + intGroup + "L3", 33, gintWindow, intX1, 278, White ); drawHL( "G" + intGroup + "L4", 33, gintWindow, intX1, 393, White ); drawHL( "G" + intGroup + "L5", 33, gintWindow, intX1, 416, White ); drawHL( "G" + intGroup + "L6", 33, gintWindow, intX1, 441, White ); // Draw the vertical cell dividers drawVL( "G" + intGroup + "L7", 50, gintWindow, intX2, 21, White ); drawVL( "G" + intGroup + "L8", 57, gintWindow, intX2, 221, White ); } //+------------------------------------------------------------------+ //| drawGroupDetail() | //+------------------------------------------------------------------+ void drawGroupDetail( int intGroup, int& aintPairIDs[], int& aintProfit[] ) { datetime dtTemp = Time[intGroup - 1]; int intX = 50 + ( intGroup * 130 ); int intY = 22; int intID; string strTemp; string strName = "G" + intGroup + "H"; // Draw the Data header if ( intGroup == 0 ) dtTemp = TimeCurrent(); strTemp = TimeToStr( dtTemp, TIME_DATE ) + " " + TimeToStr( dtTemp, TIME_SECONDS ); drawLabel( strName, strTemp, gintWindow, intX, intY, Yellow, 9, cFONT ); intY += 22; // Draw each of the currency pairs for ( int enx = 0; enx < 14; enx++ ) { // Display the currency pair and it's profit value intID = aintPairIDs[enx]; strName = "G" + intGroup + "C" + enx; drawLabel( strName, getPairNameByID( intID ), gintWindow, intX, intY, getColorByPairID( intID ), 9, cFONT ); strName = "G" + intGroup + "P" + enx; drawLabel( strName, aintProfit[enx], gintWindow, intX + 80, intY, getColorByPairID( intID ), 9, cFONT ); if ( enx == 6 ) intY += 21; else intY += 17; } } //+------------------------------------------------------------------+ //| drawGroupTotals() | //+------------------------------------------------------------------+ void drawGroupTotals( int intGroup, int& aintTotals[][] ) { int intX1 = 50 + ( intGroup * 130 ); int intX2 = 90 + ( intGroup * 130 ); int intX3 = 130 + ( intGroup * 130 ); int intY = 290; int intBuyTotal, intSellTotal; string strTrend = "NONE"; color clrColor = White; // Draw the totals for each currency for ( int inx = 0; inx < 7; inx++ ) { intBuyTotal = aintTotals[0][inx]; intSellTotal = aintTotals[1][inx]; drawLabel( "G" + intGroup + "TB" + inx, intBuyTotal, gintWindow, intX1, intY, Blue, 9, cFONT ); drawLabel( "G" + intGroup + "TS" + inx, intSellTotal, gintWindow, intX2, intY, Red, 9, cFONT ); drawLabel( "G" + intGroup + "TT" + inx, intBuyTotal + intSellTotal, gintWindow, intX3, intY, Yellow, 9, cFONT ); intY += 16; } // Draw the grand total intBuyTotal = aintTotals[0][inx]; intSellTotal = aintTotals[1][inx]; intY += 5; drawLabel( "G" + intGroup + "TB" + inx, intBuyTotal, gintWindow, intX1, intY, Blue, 9, cFONT ); drawLabel( "G" + intGroup + "TS" + inx, intSellTotal, gintWindow, intX2, intY, Red, 9, cFONT ); drawLabel( "G" + intGroup + "TT" + inx, intBuyTotal + intSellTotal, gintWindow, intX3, intY, Yellow, 9, cFONT ); // Display the overall signal if ( intSellTotal > 0 && intBuyTotal < 0 ) { strTrend = "SHORT (Strong)"; clrColor = Red; } else if ( intSellTotal > intBuyTotal && intSellTotal > 0 && intBuyTotal > 0 ) { strTrend = "SHORT (Weak)"; clrColor = Yellow; } else if ( intBuyTotal > 0 && intSellTotal < 0 ) { strTrend = "LONG (Strong)"; clrColor = Blue; } else if ( intBuyTotal > intSellTotal && intBuyTotal > 0 && intSellTotal > 0 ) { strTrend = "LONG (Weak)"; clrColor = Blue; } intY += 24; drawLabel( "G" + intGroup + "S", strTrend, gintWindow, intX1, intY, clrColor, 11, cFONT ); } //+------------------------------------------------------------------+ //| drawHL() | //+------------------------------------------------------------------+ void drawHL( string strName, int intLen, int intWindow, int intX, int intY, color clrColor ) { string strLine = getStringOneChar( '-', intLen ); drawLabel( strName, strLine, intWindow, intX, intY, clrColor, 10, "Arial" ); } //+------------------------------------------------------------------+ //| drawVL() | //+------------------------------------------------------------------+ void drawVL( string strName, int intLen, int intWindow, int intX, int intY, color clrColor ) { string strLine = getStringOneChar( '-', intLen ); drawLabel( strName, strLine, intWindow, intX, intY, clrColor, 10, "Arial", -90 ); } //+------------------------------------------------------------------+ //| drawLabel() | //+------------------------------------------------------------------+ void drawLabel( string lblName, string data, int window, int xc, int yc, color textColor, int textSize, string fontName, int angle = 0 ) { if ( ObjectFind( lblName ) == -1 ) { ObjectCreate( lblName, OBJ_LABEL, window, 0, 0 ); ObjectSet( lblName, OBJPROP_XDISTANCE, xc ); ObjectSet( lblName, OBJPROP_YDISTANCE, yc ); if ( angle != 0 ) ObjectSet( lblName, OBJPROP_ANGLE, angle ); } ObjectSetText( lblName, data, textSize, fontName, textColor ); } //+------------------------------------------------------------------+ //| deleteObjects() | //+------------------------------------------------------------------+ void deleteObjects() { for ( int hnx = 0; hnx < 25; hnx++ ) ObjectDelete( "LH" + hnx ); for ( int inx = 0; inx < 10; inx++ ) { ObjectDelete( "HL" + inx ); ObjectDelete( "G" + inx + "H" ); ObjectDelete( "G" + inx + "S" ); for ( int jnx = 0; jnx < 15; jnx++ ) { ObjectDelete( "G" + inx + "L" + jnx ); ObjectDelete( "G" + inx + "C" + jnx ); ObjectDelete( "G" + inx + "P" + jnx ); ObjectDelete( "G" + inx + "TB" + jnx ); ObjectDelete( "G" + inx + "TS" + jnx ); ObjectDelete( "G" + inx + "TT" + jnx ); } } Comment( "" ); } //********************************************************************************************* //* UTILITY FUNCTIONS BELOW * //********************************************************************************************* //+------------------------------------------------------------------+ //| isMiniAccount() | //+------------------------------------------------------------------+ bool isMiniAccount( double myLot ) { bool aRet = false; if ( myLot <= 10001.00 ) aRet = true; return( aRet ); } //+------------------------------------------------------------------+ //| getStringOneChar() | //+------------------------------------------------------------------+ string getStringOneChar( int intChar, int intSize ) { string strTemp = "--------------------------------------------------"; if ( intChar != '-' ) { for ( int inx = 0; inx < StringLen( strTemp ); inx++ ) strTemp = StringSetChar( strTemp, inx, intChar ); } string strLine = StringConcatenate( strTemp, strTemp, strTemp, strTemp, strTemp, strTemp, strTemp, strTemp ); strLine = StringSubstr( strLine, 0, intSize ); return( strLine ); } //+------------------------------------------------------------------+ //| isNewBar() | //+------------------------------------------------------------------+ bool isNewBar() { bool blnReturn = false; static datetime dtLastTime = 0; if ( Time[0] != dtLastTime ) { dtLastTime = Time[0]; blnReturn = true; } return( blnReturn ); } //+------------------------------------------------------------------+ //| getBarShift() | //+------------------------------------------------------------------+ int getBarShift( string strPair, datetime dtBar ) { int intShift = iBarShift( strPair, 0, dtBar, true ); if ( intShift < 0 ) intShift = 0; return( intShift ); } //********************************************************************************************* //* DATA STORAGE AND RETRIEVAL FUNCTIONS BELOW * //********************************************************************************************* string gastrPairs[14]; string gastrCcy[7]; int gaintPairData[1][14]; //+------------------------------------------------------------------+ //| initializePairData() | //+------------------------------------------------------------------+ void initializePairData() { gastrPairs[0] = "CADJPY"; gastrPairs[1] = "AUDUSD"; gastrPairs[2] = "USDJPY"; gastrPairs[3] = "EURUSD"; gastrPairs[4] = "EURCHF"; gastrPairs[5] = "GBPJPY"; gastrPairs[6] = "USDCAD"; gastrPairs[7] = "GBPUSD"; gastrPairs[8] = "EURGBP"; gastrPairs[9] = "GBPCHF"; gastrPairs[10] = "CHFJPY"; gastrPairs[11] = "AUDJPY"; gastrPairs[12] = "EURJPY"; gastrPairs[13] = "USDCHF"; gastrCcy[0] = "EUR"; gastrCcy[1] = "GBP"; gastrCcy[2] = "CHF"; gastrCcy[3] = "AUD"; gastrCcy[4] = "JPY"; gastrCcy[5] = "USD"; gastrCcy[6] = "CAD"; // Need to add "m" to end of currency pairs when using mini account if ( isMiniAccount( gdblLotSize ) ) { for ( int inx = 0; inx < 14; inx++ ) gastrPairs[inx] = gastrPairs[inx] + "m"; } // Buy = 1, Sell = 0 gaintPairData[0][0] = 0; gaintPairData[0][1] = 0; gaintPairData[0][2] = 0; gaintPairData[0][3] = 0; gaintPairData[0][4] = 0; gaintPairData[0][5] = 0; gaintPairData[0][6] = 0; gaintPairData[0][7] = 1; gaintPairData[0][8] = 1; gaintPairData[0][9] = 1; gaintPairData[0][10] = 1; gaintPairData[0][11] = 1; gaintPairData[0][12] = 1; gaintPairData[0][13] = 1; } //+------------------------------------------------------------------+ //| getPairNameByID() | //+------------------------------------------------------------------+ string getPairNameByID( int intID ) { return( gastrPairs[intID ] ); } //+------------------------------------------------------------------+ //| getCcyNameByID() | //+------------------------------------------------------------------+ string getCcyNameByID( int intID ) { return( gastrCcy[intID ] ); } //+------------------------------------------------------------------+ //| isBuyPair() | //+------------------------------------------------------------------+ bool isBuyPair( int intID ) { return( gaintPairData[0][intID] ); } //+------------------------------------------------------------------+ //| getColorByPairID() | //+------------------------------------------------------------------+ color getColorByPairID( int intID ) { if ( isBuyPair( intID ) ) return( Blue ); return( Red ); }