GUI button control for Time frames

Hello,

Is there any example of GUI button control for toggling between different time frames?

Thank you

with the help of previous related topics on GUI and chat GPT i came up with the below. However I see that when one Gui button is selected the other buttons should be in off state. How to solve the error.

// Define GUI toggle buttons for each timeframe
GuiToggle("1 Min", 1, 10, 10, 40, 20, 1);
GuiToggle("5 Min", 2, 60, 10, 40, 20, 0);
GuiToggle("15 Min", 3, 110, 10, 40, 20, 0);
GuiToggle("30 Min", 4, 160, 10, 40, 20, 0);
GuiToggle("60 Min", 5, 210, 10, 40, 20, 0);

// Check which toggle button is checked
selectedTimeframe = Null;
for (i = 1; i <= 5; i++) {
    if (guigetcheck(i)) {
        selectedTimeframe = i;
        break; // Exit the loop if a button is checked
    }
}

// Set the selected time frame based on the checked button
if (selectedTimeframe != Null) {
    if (selectedTimeframe == 1) {
        TimeFrameSet(in1Minute);
    } else if (selectedTimeframe == 2) {
        TimeFrameSet(in5Minute);
    } else if (selectedTimeframe == 3) {
        TimeFrameSet(in15Minute);
    } else if (selectedTimeframe == 4) {
        TimeFrameSet(in30Minute);
    } else if (selectedTimeframe == 5) {
        TimeFrameSet(inHourly);
    }
}

// Plot the OHLC and volume based on the selected time frame
PlotOHLC(Open, High, Low, Close, "Price Chart", colorBlack, style = styleCandle | styleOwnScale);
Plot(V, "Volume", colorWhite, styleHistogram);

@amisur, replace the first part of the code with:

// Define GUI toggle buttons for each timeframe
GuiRadio("1 Min", 1, 10, 20, 40, 20, notifyClicked );
GuiRadio("5 Min", 2, 60, 20, 40, 20, notifyClicked);
GuiRadio("15 Min", 3, 110, 20, 40, 20, notifyClicked);
GuiRadio("30 Min", 4, 160, 20, 40, 20, notifyClicked);
GuiRadio("60 Min", 5, 210, 20, 40, 20, notifyClicked);

But based on the posted code it's not clear to me why you use the TimeFrameSet() function.

TimeFrame functions are NOT intended to replace Periodicity setting

If you want to change the active interval of the chart you have to use an OLE call as there is no AFL function that does it.
In such a case, please see this example.

1 Like

Thank you for the guidance. Example on OLE helped me.

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.