IndicatorExpert Advisor

1
I am trying to create a dashboard, below is the code to create different groups of buttons.

Code: Select all

int CreateSymbolButtons(CArrayString* dynamicArray, CChartObjectButton& ButtonSymbols[], int iWidth, int iHeight, int x, int y, int buttonInRow)
{
    bool bResult;
    int iRow=0, nRows, iCol=0, Xdistance, Ydistance;
    int nSymbols, iSymbol, iResult, ChartWin;
    string UniqueName;
    
    //DbugInfo(Print(__FILE__, " ", __FUNCTION__, "@", __LINE__); )
    ChartSetInteger(0, CHART_FOREGROUND, bChartForeground);  // Price chart in the foreground
    
    nSymbols = dynamicArray.Total();
    nRows = (nSymbols / buttonInRow);    // Div, Full Rows
    if ((nSymbols % buttonInRow) > 0)    // Modulus Remainder, if a Partial Row
      nRows++;

    ArrayFree(ObjButtonSymbols);    
    iResult = ArrayResize(ObjButtonSymbols, nSymbols);
   for (iSymbol = 0; iSymbol < nSymbols; iSymbol++){
      ChartWin = iChartWindow;
      UniqueName = sUniquePrefix + dynamicArray[iSymbol] + "-" + string(iSymbol);   
      bResult = ObjButtonSymbols[iSymbol].Create(0, UniqueName, ChartWin, 0, 0, 1, 1);

      bResult = ObjButtonSymbols[iSymbol].Description(dynamicArray[iSymbol]);
      bResult = ObjButtonSymbols[iSymbol].SetInteger(OBJPROP_BACK, bTransparent);       
      //bResult = ObjButtonSymbols[iSymbol].SetInteger(OBJPROP_HIDDEN, true); // Prohibit showing via terminal menu "Charts" - "Objects" - "List of objects". 
      bResult = ObjButtonSymbols[iSymbol].State(false);                       // button state (Pressed/Depressed) 
      //bResult = ObjButtonSymbols[iSymbol].Tooltip(casSymbols[iSymbol]);
      
      // Determine the Button Row. Start at Top if using a Top Corner, Reverse Order if using a Lower Corner 
      if ((BaseCorner == CORNER_LEFT_LOWER) || (BaseCorner == CORNER_RIGHT_LOWER))
        iRow = (nRows - 1) - (iSymbol / buttonInRow);
        else iRow = iSymbol / buttonInRow;  // Div        
         
      // Determine the Button Column. Start at Left if using a Left Corner, Reverse Order if using a Right Corner 
      if ((BaseCorner == CORNER_RIGHT_LOWER) || (BaseCorner == CORNER_RIGHT_UPPER))
        iCol = (buttonInRow - 1) - (iSymbol % buttonInRow);
        else iCol = iSymbol % buttonInRow;  // Modulus Remainder       

      Xdistance = (x>=0)?x+(iCol * (iWidth + ButtonSpacing)):MarginX + (iCol * (iWidth + ButtonSpacing));
      if ((BaseCorner == CORNER_RIGHT_LOWER) || (BaseCorner == CORNER_RIGHT_UPPER))
        Xdistance += iWidth;
      Ydistance = (y>=0)?y+(iRow * (iHeight + ButtonSpacing)):MarginY + (iRow * (iHeight + ButtonSpacing));
      if ((BaseCorner == CORNER_LEFT_LOWER) || (BaseCorner == CORNER_RIGHT_LOWER))
        Ydistance += iHeight;

      bResult = ObjButtonSymbols[iSymbol].Corner(BaseCorner);
      bResult = ObjButtonSymbols[iSymbol].X_Distance(Xdistance);
      bResult = ObjButtonSymbols[iSymbol].Y_Distance(Ydistance);
      bResult = ObjButtonSymbols[iSymbol].X_Size(iWidth);
      bResult = ObjButtonSymbols[iSymbol].Y_Size(iHeight);
   }

    return(0);
}
This is how I call the above function in OnInit() function of the expert advisor

Code: Select all

GetTextWidthHeight(&menuBars);
    iResult = CreateSymbolButtons(&menuBars, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 20,6);
    GetTextWidthHeight(&casSymbols);
    iResult = CreateSymbolButtons(&casSymbols, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 80,2);
I noticed the buttons that keeps showing on chart is

Code: Select all

iResult = CreateSymbolButtons(&casSymbols, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 80,2);
, if i comment it out, the first button

Code: Select all

iResult = CreateSymbolButtons(&menuBars, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 20,6);
will show, it means the second code is overwriting the first code. What i want is i want both buttons to appears on chart. I have tried solving this but i could not, a hand of help please.


Re: Expert Advisor

2
ArchRaphr wrote: Fri Mar 11, 2022 7:29 am I am trying to create a dashboard, below is the code to create different groups of buttons.

Code: Select all

int CreateSymbolButtons(CArrayString* dynamicArray, CChartObjectButton& ButtonSymbols[], int iWidth, int iHeight, int x, int y, int buttonInRow)
{
    bool bResult;
    int iRow=0, nRows, iCol=0, Xdistance, Ydistance;
    int nSymbols, iSymbol, iResult, ChartWin;
    string UniqueName;
    
    //DbugInfo(Print(__FILE__, " ", __FUNCTION__, "@", __LINE__); )
    ChartSetInteger(0, CHART_FOREGROUND, bChartForeground);  // Price chart in the foreground
    
    nSymbols = dynamicArray.Total();
    nRows = (nSymbols / buttonInRow);    // Div, Full Rows
    if ((nSymbols % buttonInRow) > 0)    // Modulus Remainder, if a Partial Row
      nRows++;

    ArrayFree(ObjButtonSymbols);    
    iResult = ArrayResize(ObjButtonSymbols, nSymbols);
   for (iSymbol = 0; iSymbol < nSymbols; iSymbol++){
      ChartWin = iChartWindow;
      UniqueName = sUniquePrefix + dynamicArray[iSymbol] + "-" + string(iSymbol);   
      bResult = ObjButtonSymbols[iSymbol].Create(0, UniqueName, ChartWin, 0, 0, 1, 1);

      bResult = ObjButtonSymbols[iSymbol].Description(dynamicArray[iSymbol]);
      bResult = ObjButtonSymbols[iSymbol].SetInteger(OBJPROP_BACK, bTransparent);       
      //bResult = ObjButtonSymbols[iSymbol].SetInteger(OBJPROP_HIDDEN, true); // Prohibit showing via terminal menu "Charts" - "Objects" - "List of objects". 
      bResult = ObjButtonSymbols[iSymbol].State(false);                       // button state (Pressed/Depressed) 
      //bResult = ObjButtonSymbols[iSymbol].Tooltip(casSymbols[iSymbol]);
      
      // Determine the Button Row. Start at Top if using a Top Corner, Reverse Order if using a Lower Corner 
      if ((BaseCorner == CORNER_LEFT_LOWER) || (BaseCorner == CORNER_RIGHT_LOWER))
        iRow = (nRows - 1) - (iSymbol / buttonInRow);
        else iRow = iSymbol / buttonInRow;  // Div        
         
      // Determine the Button Column. Start at Left if using a Left Corner, Reverse Order if using a Right Corner 
      if ((BaseCorner == CORNER_RIGHT_LOWER) || (BaseCorner == CORNER_RIGHT_UPPER))
        iCol = (buttonInRow - 1) - (iSymbol % buttonInRow);
        else iCol = iSymbol % buttonInRow;  // Modulus Remainder       

      Xdistance = (x>=0)?x+(iCol * (iWidth + ButtonSpacing)):MarginX + (iCol * (iWidth + ButtonSpacing));
      if ((BaseCorner == CORNER_RIGHT_LOWER) || (BaseCorner == CORNER_RIGHT_UPPER))
        Xdistance += iWidth;
      Ydistance = (y>=0)?y+(iRow * (iHeight + ButtonSpacing)):MarginY + (iRow * (iHeight + ButtonSpacing));
      if ((BaseCorner == CORNER_LEFT_LOWER) || (BaseCorner == CORNER_RIGHT_LOWER))
        Ydistance += iHeight;

      bResult = ObjButtonSymbols[iSymbol].Corner(BaseCorner);
      bResult = ObjButtonSymbols[iSymbol].X_Distance(Xdistance);
      bResult = ObjButtonSymbols[iSymbol].Y_Distance(Ydistance);
      bResult = ObjButtonSymbols[iSymbol].X_Size(iWidth);
      bResult = ObjButtonSymbols[iSymbol].Y_Size(iHeight);
   }

    return(0);
}
This is how I call the above function in OnInit() function of the expert advisor

Code: Select all

GetTextWidthHeight(&menuBars);
    iResult = CreateSymbolButtons(&menuBars, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 20,6);
    GetTextWidthHeight(&casSymbols);
    iResult = CreateSymbolButtons(&casSymbols, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 80,2);
I noticed the buttons that keeps showing on chart is

Code: Select all

iResult = CreateSymbolButtons(&casSymbols, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 80,2);
, if i comment it out, the first button

Code: Select all

iResult = CreateSymbolButtons(&menuBars, ObjButtonSymbols, (int)uiMaxWidth, (int)uiMaxHeight, 5, 20,6);
will show, it means the second code is overwriting the first code. What i want is i want both buttons to appears on chart. I have tried solving this but i could not, a hand of help please.
I have been able to get what i want. The solution is to create all the button in one function

Who is online

Users browsing this forum: No registered users and 11 guests