{"id":1662,"date":"2008-03-09T22:52:13","date_gmt":"2008-03-09T22:52:13","guid":{"rendered":"http:\/\/www.amibroker.org\/userkb\/2008\/03\/09\/button-rotate\/"},"modified":"2008-03-10T01:25:52","modified_gmt":"2008-03-10T01:25:52","slug":"button-rotate","status":"publish","type":"post","link":"http:\/\/www.amibroker.org\/editable_userkb\/2008\/03\/09\/button-rotate\/","title":{"rendered":"Button Rotate"},"content":{"rendered":"

A ButtonRotate function is like a ParamToggle() but with multiple states. The ButtonRotate function returns the label displayed on the button, and selects the next label each time you click the button. In the example below the ButtonRotate is used to select the next action, which can be Buy, Sell, Short, Cover, Cash, or Reverse. The end result of using this function is similar to using the ParamList() however it is much quicker to use. When the action is selected the order can be transmitted using the Transmit ButtonTrigger().The function returns the displayed label; sometimes the label can be used directly in PlaceOrder(), at other times you may have to use an if() comparison to know which action to perform. For debugging purposes the Title shows the returned values: <\/p>\n

\nrotatebutton.png<\/a><\/p>\n

The ButtonRotate() is listed below for discussion. There is no need to copy this because it is included in the Include file at the end of this post.<\/p>\n

<\/span>function <\/span>ButtonRotate<\/span>( <\/span>LabelStr<\/span>, <\/span>BackColorStr<\/span>, <\/span>TextColorStr <\/span>)\r{\r    global <\/span>ColNumber<\/span>, <\/span>RowNumber<\/span>, <\/span>ColName<\/span>, <\/span>ColExpanded<\/span>;\r\r    if ( <\/span>ColExpanded <\/span>)\r    {\r        <\/span>ColName <\/span>= <\/span>VarGetText<\/span>( <\/span>"ColName" <\/span>);\r        <\/span>RowNumber <\/span>= <\/span>Nz<\/span>( <\/span>kStaticVarGet<\/span>( <\/span>"RowNumber" <\/span>+ <\/span>ColName <\/span>) ) + <\/span>1<\/span>;\r        <\/span>kStaticVarSet<\/span>( <\/span>"RowNumber" <\/span>+ <\/span>ColName<\/span>, <\/span>RowNumber <\/span>);\r        <\/span>Rotate <\/span>= <\/span>GetButtonClick<\/span>( <\/span>ColNumber<\/span>, <\/span>RowNumber <\/span>);\r        if ( <\/span>Rotate <\/span>OR <\/span>IsNull<\/span>( <\/span>StaticVarGet<\/span>(<\/span>"RotateInit"<\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber <\/span>) ) )\r        {\r            <\/span>RotateIndex <\/span>= <\/span>Nz<\/span>( <\/span>kStaticVarGet<\/span>( <\/span>"RotateIndex" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber <\/span>) );\r            if ( <\/span>StrExtract<\/span>( <\/span>LabelStr<\/span>, <\/span>RotateIndex <\/span>+ <\/span>1<\/span>) != <\/span>"" <\/span>) <\/span>RotateIndex<\/span>++;\r            else <\/span>RotateIndex <\/span>= <\/span>0<\/span>;\r            <\/span>kStaticVarSet<\/span>( <\/span>"RotateIndex" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>RotateIndex <\/span>);\r\r            <\/span>Label <\/span>= <\/span>StrExtract<\/span>( <\/span>LabelStr<\/span>, <\/span>RotateIndex <\/span>);\r\r            if ( <\/span>StrExtract<\/span>( <\/span>BackColorStr<\/span>, <\/span>RotateIndex <\/span>) == <\/span>"" <\/span>) <\/span>BackColor <\/span>= <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>BackColorStr<\/span>, <\/span>0 <\/span>) );\r            else <\/span>BackColor <\/span>= <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>BackColorStr<\/span>, <\/span>RotateIndex <\/span>) );\r\r            if ( <\/span>StrExtract<\/span>( <\/span>TextColorStr<\/span>, <\/span>RotateIndex <\/span>) == <\/span>"" <\/span>) <\/span>TextColor <\/span>= <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>TextColorStr<\/span>, <\/span>0 <\/span>) );\r            else <\/span>TextColor <\/span>=     <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>TextColorStr<\/span>, <\/span>RotateIndex <\/span>) );\r\r            <\/span>kStaticVarSetText<\/span>( <\/span>"Label" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>Label <\/span>);\r            <\/span>kStaticVarSet<\/span>( <\/span>"TextColor" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>TextColor <\/span>);\r            <\/span>kStaticVarSet<\/span>( <\/span>"BackColor" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>BackColor <\/span>);\r                <\/span>StaticVarSet<\/span>(<\/span>"RotateInit"<\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>True<\/span>);\r        }\r    }\r    <\/span>Label     <\/span>= <\/span>kStaticVarGetText<\/span>( <\/span>"Label" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>);\r    return <\/span>Label<\/span>;\r}\r<\/span><\/pre>\n

Referring to the above code you’ll see the usual ColExpanded<\/i> variable that determines whether this button will be displayed. A RotateInit <\/em>var is used to detect whether the button has been initialized, i.e., whether is was assigned colors and text. Each time the function is called the RotateIndex <\/em>incremented. This index is used to extract the proper label and color from the csv encoded options in the string argument for the function.<\/p>\n

The code below demonstrates how the ButtonRotate is used. Note that for brevity I used digits to indicate colors. You can also use constants like ColorRed, ColorBlue, etc. <\/p>\n

<\/span>#include <ControlPanelInclude-004.afl>\r\r<\/span>global <\/span>ColNumber<\/span>;\r<\/span>RequestTimedRefresh<\/span>(<\/span>1<\/span>);\r<\/span>ButtonHeight            <\/span>= <\/span>Param<\/span>(<\/span>"Button Height"<\/span>,<\/span>20<\/span>,<\/span>5<\/span>,<\/span>200<\/span>,<\/span>1<\/span>); \r<\/span>ButtonWidth             <\/span>= <\/span>Param<\/span>(<\/span>"Button Width"<\/span>,<\/span>120<\/span>,<\/span>5<\/span>,<\/span>200<\/span>,<\/span>1<\/span>); \r<\/span>PanelYoffset             <\/span>= <\/span>Param<\/span>(<\/span>"Button Row Offset (px)"<\/span>,<\/span>10<\/span>,<\/span>0<\/span>,<\/span>Status<\/span>(<\/span>"pxheight"<\/span>),<\/span>1<\/span>); \r<\/span>PanelXoffset            <\/span>= <\/span>Param<\/span>(<\/span>"Button Column Offset (px)"<\/span>,<\/span>10<\/span>,<\/span>0<\/span>,<\/span>Status<\/span>(<\/span>"pxwidth"<\/span>),<\/span>1<\/span>); \r<\/span>FontRatio               <\/span>= <\/span>Param<\/span>(<\/span>"Font: ButtonHeight ratio"<\/span>,<\/span>2<\/span>,<\/span>1<\/span>,<\/span>20<\/span>,<\/span>0.1<\/span>);\r<\/span>DoubleClickInterval    <\/span>= <\/span>Param<\/span>(<\/span>"Double Click Max. Interval"<\/span>,<\/span>330<\/span>,<\/span>1<\/span>,<\/span>1000<\/span>,<\/span>1<\/span>);\r\r<\/span>ButtonColumnBegin<\/span>( <\/span>"1" <\/span>);\r<\/span>ButtonHeader<\/span>( <\/span>"HEADER"<\/span>, <\/span>colorBlue<\/span>, <\/span>colorBlue<\/span>,<\/span>colorWhite<\/span>);\r<\/span>ButtonText<\/span>( <\/span>"TRADING ENABLED"<\/span>, <\/span>colorYellow<\/span>, <\/span>colorBlue<\/span>);\r\r<\/span>Action<\/span>=<\/span>ButtonRotate<\/span>( <\/span>"BUY,SELL,SHORT,COVER,CASH,REVERSE"<\/span>, <\/span>"6,5,1,3,2,4"<\/span>, <\/span>"2,3,4,5,6,1" <\/span>);\r<\/span>Transmit <\/span>= <\/span>ButtonTrigger<\/span>( <\/span>"TRANSMIT"<\/span>, <\/span>colorBrightGreen<\/span>, <\/span>colorRed<\/span>, <\/span>colorBlack<\/span>);\r<\/span>ButtonColumnEnd<\/span>( );\r\r<\/span>ClickCoordinates <\/span>= <\/span>Nz<\/span>(<\/span>StaticVarGet<\/span>(<\/span>"ClickCoordinates"<\/span>));\rswitch( <\/span>ClickCoordinates <\/span>)\r    {\r    case <\/span>101<\/span>:\r    <\/span>\/\/ Perform Button task 101 here\r    <\/span>break;\r    case <\/span>102<\/span>:\r    <\/span>\/\/ Perform Button task 102 here\r    <\/span>break;\r    <\/span>\/\/ etc.\r    <\/span>}\r\r<\/span>Plot<\/span>(<\/span>C<\/span>,<\/span>""<\/span>,<\/span>1<\/span>,<\/span>128<\/span>);\r\r<\/span>Title <\/span>= <\/span>"\\n"<\/span>+\r<\/span>"Button Coordinates: "<\/span>+<\/span>ClickCoordinates<\/span>+<\/span>"\\n"<\/span>+\r<\/span>"Action: "<\/span>+<\/span>Action<\/span>+<\/span>"\\n"<\/span>+<\/span><\/pre>\n

As always, here follows the revised Include file with the ButtonRotate() included.<\/p>\n

<\/span>\/\/ ControlPanelInclude-004.afl\r<\/span>procedure kStaticVarSet<\/span>( <\/span>SName<\/span>, <\/span>SValue <\/span>)         \r    {\r    <\/span>ChartID <\/span>= <\/span>GetChartID<\/span>();\r    <\/span>InIndicator <\/span>= <\/span>Status<\/span>(<\/span>"Action"<\/span>) == <\/span>1<\/span>;\r    if( <\/span>InIndicator <\/span>) <\/span>StaticVarSet<\/span>(<\/span>Sname<\/span>+<\/span>ChartID<\/span>, <\/span>Svalue<\/span>); \r    }\r\rfunction <\/span>kStaticVarGet<\/span>( <\/span>SName <\/span>)                     \r    { \r    <\/span>ChartID     <\/span>= <\/span>GetChartID<\/span>();\r    Var = <\/span>StaticVarGet<\/span>(<\/span>Sname<\/span>+<\/span>ChartID<\/span>);\r    return Var;\r    }\r\r<\/span>procedure kStaticVarSetText<\/span>( <\/span>SName<\/span>, <\/span>SValue <\/span>)     \r    { \r    <\/span>ChartID     <\/span>= <\/span>GetChartID<\/span>();\r    <\/span>InIndicator <\/span>= <\/span>Status<\/span>(<\/span>"Action"<\/span>) == <\/span>1<\/span>;\r    if( <\/span>InIndicator <\/span>) <\/span>StaticVarSetText<\/span>(<\/span>Sname<\/span>+<\/span>ChartID<\/span>, <\/span>Svalue<\/span>); \r    }\r\rfunction <\/span>kStaticVarGetText<\/span>( <\/span>SName <\/span>)                 \r    { \r    <\/span>ChartID <\/span>= <\/span>GetChartID<\/span>();\r    return <\/span>StaticVarGetText<\/span>(<\/span>Sname<\/span>+<\/span>ChartID<\/span>); \r    }\r\rfunction <\/span>NewColumn<\/span>()\r    {\r    <\/span>VarSet<\/span>(<\/span>"ColNumber"<\/span>, <\/span>0<\/span>);\r    }\r\rfunction <\/span>GetButtonClick<\/span>( <\/span>ColNumber<\/span>, <\/span>RowNumber <\/span>)\r    {\r    global <\/span>PanelYoffset<\/span>, <\/span>PanelXoffset<\/span>, <\/span>ButtonHeight<\/span>, <\/span>ButtonWidth<\/span>;\r    <\/span>LButtonDown <\/span>= <\/span>GetCursorMouseButtons<\/span>() == <\/span>9<\/span>;\r    <\/span>Click <\/span>= <\/span>False<\/span>;\r    if( <\/span>LButtonDown <\/span>)\r        {\r        <\/span>ULButtonX     <\/span>= <\/span>PanelXoffset <\/span>+ (<\/span>ColNumber<\/span>-<\/span>1<\/span>) * <\/span>ButtonWidth<\/span>;\r        <\/span>LRButtonX    <\/span>= <\/span>ULButtonX <\/span>+ <\/span>ButtonWidth<\/span>;\r        <\/span>ULButtonY     <\/span>= (<\/span>RowNumber <\/span>-<\/span>1<\/span>) * <\/span>ButtonHeight <\/span>+ <\/span>PanelYoffset<\/span>;\r        <\/span>LRButtonY    <\/span>= <\/span>ULButtonY <\/span>+ <\/span>ButtonHeight<\/span>;\r        <\/span>MouseCoord     <\/span>= <\/span>Nz<\/span>(<\/span>StaticVarGet<\/span>(<\/span>"ClickCoordinates"<\/span>));\r        if( <\/span>MouseCoord <\/span>== <\/span>0 <\/span>AND <\/span>LButtonDown <\/span>)\r            {\r            <\/span>MousePx <\/span>= <\/span>GetCursorXPosition<\/span>( <\/span>1 <\/span>);\r            <\/span>MousePy <\/span>= <\/span>GetCursorYPosition<\/span>( <\/span>1 <\/span>);\r            if( <\/span>MousePx <\/span>> <\/span>ULButtonX <\/span>AND <\/span>MousePx <\/span>< <\/span>LRButtonX <\/span>AND <\/span>MousePy <\/span>> <\/span>ULButtonY <\/span>AND <\/span>MousePy <\/span>< <\/span>LRButtonY <\/span>)\r                {\r                <\/span>StaticVarSet<\/span>(<\/span>"ClickCoordinates"<\/span>,<\/span>ColNumber<\/span>*<\/span>100<\/span>+<\/span>RowNumber<\/span>);\r                <\/span>Click <\/span>= <\/span>1<\/span>;\r                }\r            }\r        }\r    return <\/span>Click<\/span>;\r    }\r\rfunction <\/span>ButtonColumnBegin<\/span>( <\/span>ColName <\/span>) \r    {\r    global <\/span>FontRatio<\/span>, <\/span>ColName<\/span>, <\/span>ColNumber<\/span>, <\/span>ButtonHeight<\/span>, <\/span>ButtonWidth<\/span>, <\/span>PanelXoffset<\/span>, <\/span>PanelYoffset<\/span>, <\/span>Colname<\/span>;\r    <\/span>ColNumber <\/span>= <\/span>VarGet<\/span>(<\/span>"ColNumber"<\/span>);\r    if( <\/span>IsEmpty<\/span>( <\/span>ColNumber <\/span>) ) \r        {\r        <\/span>VarSet<\/span>(<\/span>"ColNumber"<\/span>,<\/span>1<\/span>);\r        <\/span>StaticVarSet<\/span>(<\/span>"ClickCoordinates"<\/span>,<\/span>0<\/span>);\r        }\r    else <\/span>VarSet<\/span>(<\/span>"ColNumber"<\/span>, ++<\/span>ColNumber<\/span>);\r    <\/span>ColName <\/span>= <\/span>ColName<\/span>+<\/span>GetChartID<\/span>();\r    <\/span>kStaticVarSet<\/span>(<\/span>"RowNumber"<\/span>+<\/span>ColName<\/span>, <\/span>0<\/span>);\r    <\/span>VarSetText<\/span>(<\/span>"ColName"<\/span>,<\/span>ColName<\/span>);\r    <\/span>GfxSetOverlayMode<\/span>( <\/span>0 <\/span>);\r    <\/span>GfxSelectFont<\/span>( <\/span>"Tahoma"<\/span>, <\/span>ButtonHeight<\/span>\/<\/span>FontRatio<\/span>, <\/span>800 <\/span>); \r    <\/span>GfxSelectPen<\/span>( <\/span>colorBlack <\/span>); \r    <\/span>GfxSetBkMode<\/span>( <\/span>1 <\/span>);\r    }\r\rfunction <\/span>ButtonHeader<\/span>( <\/span>Label<\/span>, <\/span>backColor1<\/span>, <\/span>BackColor2<\/span>, <\/span>TextColor<\/span>)\r    {\r    global <\/span>ColNumber<\/span>, <\/span>RowNumber<\/span>, <\/span>ColExpanded<\/span>, <\/span>Colname<\/span>;\r    <\/span>RowNumber <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>"RowNumber"<\/span>+<\/span>ColName<\/span>))+<\/span>1<\/span>;\r    <\/span>kStaticVarSet<\/span>(<\/span>"RowNumber"<\/span>+<\/span>ColName<\/span>, <\/span>RowNumber<\/span>);\r    <\/span>SingleClick <\/span>= <\/span>GetButtonClick<\/span>( <\/span>ColNumber<\/span>, <\/span>RowNumber <\/span>);\r    <\/span>BackColor <\/span>= <\/span>backColor1<\/span>;\r    <\/span>ColExpanded <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>ColName<\/span>+<\/span>"ColExpanded"<\/span>));\r    if( <\/span>SingleClick <\/span>) \r        {\r        <\/span>BackColor <\/span>= <\/span>backColor2<\/span>; \r        <\/span>ColExpanded <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>ColName<\/span>+<\/span>"ColExpanded"<\/span>));\r        if( <\/span>ColExpanded <\/span>) <\/span>kStaticVarSet<\/span>(<\/span>ColName<\/span>+<\/span>"ColExpanded"<\/span>, <\/span>False<\/span>);\r        else <\/span>kStaticVarSet<\/span>(<\/span>ColName<\/span>+<\/span>"ColExpanded"<\/span>, <\/span>True<\/span>);\r        }\r    <\/span>ColExpanded <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>ColName<\/span>+<\/span>"ColExpanded"<\/span>));\r    <\/span>kStaticVarSetText<\/span>(<\/span>"Label"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>Label<\/span>);\r    <\/span>kStaticVarSet<\/span>(<\/span>"TextColor"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>TextColor<\/span>);\r    <\/span>kStaticVarSet<\/span>(<\/span>"BackColor"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>backColor<\/span>);\r    }\r\rfunction <\/span>ButtonText<\/span>( <\/span>Label<\/span>, <\/span>backColor<\/span>, <\/span>TextColor<\/span>)\r    {\r    global <\/span>ColNumber<\/span>, <\/span>RowNumber<\/span>, <\/span>Colname<\/span>;\r    <\/span>ColExpanded <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>ColName<\/span>+<\/span>"ColExpanded"<\/span>));\r    if( <\/span>ColExpanded <\/span>)\r        {\r        <\/span>ColName <\/span>= <\/span>VarGetText<\/span>(<\/span>"ColName"<\/span>);\r        <\/span>RowNumber <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>"RowNumber"<\/span>+<\/span>ColName<\/span>))+<\/span>1<\/span>;\r        <\/span>kStaticVarSet<\/span>(<\/span>"RowNumber"<\/span>+<\/span>ColName<\/span>, <\/span>RowNumber<\/span>);\r        <\/span>kStaticVarSetText<\/span>(<\/span>"Label"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>Label<\/span>);\r        <\/span>kStaticVarSet<\/span>(<\/span>"TextColor"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>TextColor<\/span>);\r        <\/span>kStaticVarSet<\/span>(<\/span>"BackColor"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>backColor<\/span>);\r        }\r    }\r\rfunction <\/span>ButtonTrigger<\/span>( <\/span>Label<\/span>, <\/span>backColor1<\/span>, <\/span>BackColor2<\/span>, <\/span>TextColor<\/span>)\r    {\r    global <\/span>ColNumber<\/span>, <\/span>RowNumber<\/span>, <\/span>ColName<\/span>;\r    <\/span>ColExpanded <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>ColName<\/span>+<\/span>"ColExpanded"<\/span>));\r    if( <\/span>ColExpanded <\/span>)\r        {\r        <\/span>ColName <\/span>= <\/span>VarGetText<\/span>(<\/span>"ColName"<\/span>);\r        <\/span>RowNumber <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>"RowNumber"<\/span>+<\/span>ColName<\/span>))+<\/span>1<\/span>;\r        <\/span>kStaticVarSet<\/span>(<\/span>"RowNumber"<\/span>+<\/span>ColName<\/span>, <\/span>RowNumber<\/span>);\r        <\/span>Trigger <\/span>= <\/span>GetButtonClick<\/span>( <\/span>ColNumber<\/span>, <\/span>RowNumber <\/span>);\r        if( <\/span>Trigger <\/span>) <\/span>BackColor <\/span>= <\/span>backColor2<\/span>; else <\/span>BackColor <\/span>= <\/span>backColor1<\/span>;\r        <\/span>kStaticVarSetText<\/span>(<\/span>"Label"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>Label<\/span>);\r        <\/span>kStaticVarSet<\/span>(<\/span>"TextColor"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>TextColor<\/span>);\r        <\/span>kStaticVarSet<\/span>(<\/span>"BackColor"<\/span>+<\/span>ColName<\/span>+<\/span>RowNumber<\/span>, <\/span>backColor<\/span>);\r        }\r    else <\/span>Trigger <\/span>= <\/span>0<\/span>;\r    return <\/span>Trigger<\/span>;\r    }\r\rfunction <\/span>ButtonRotate<\/span>( <\/span>LabelStr<\/span>, <\/span>BackColorStr<\/span>, <\/span>TextColorStr <\/span>)\r{\r    global <\/span>ColNumber<\/span>, <\/span>RowNumber<\/span>, <\/span>ColName<\/span>, <\/span>ColExpanded<\/span>;\r\r    if ( <\/span>ColExpanded <\/span>)\r    {\r        <\/span>ColName <\/span>= <\/span>VarGetText<\/span>( <\/span>"ColName" <\/span>);\r        <\/span>RowNumber <\/span>= <\/span>Nz<\/span>( <\/span>kStaticVarGet<\/span>( <\/span>"RowNumber" <\/span>+ <\/span>ColName <\/span>) ) + <\/span>1<\/span>;\r        <\/span>kStaticVarSet<\/span>( <\/span>"RowNumber" <\/span>+ <\/span>ColName<\/span>, <\/span>RowNumber <\/span>);\r        <\/span>Rotate <\/span>= <\/span>GetButtonClick<\/span>( <\/span>ColNumber<\/span>, <\/span>RowNumber <\/span>);\r        if ( <\/span>Rotate <\/span>OR <\/span>IsNull<\/span>( <\/span>StaticVarGet<\/span>(<\/span>"RotateInit"<\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber <\/span>) ) )\r        {\r            <\/span>RotateIndex <\/span>= <\/span>Nz<\/span>( <\/span>kStaticVarGet<\/span>( <\/span>"RotateIndex" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber <\/span>) );\r            if ( <\/span>StrExtract<\/span>( <\/span>LabelStr<\/span>, <\/span>RotateIndex <\/span>+ <\/span>1<\/span>) != <\/span>"" <\/span>) <\/span>RotateIndex<\/span>++;\r            else <\/span>RotateIndex <\/span>= <\/span>0<\/span>;\r            <\/span>kStaticVarSet<\/span>( <\/span>"RotateIndex" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>RotateIndex <\/span>);\r\r            <\/span>Label <\/span>= <\/span>StrExtract<\/span>( <\/span>LabelStr<\/span>, <\/span>RotateIndex <\/span>);\r\r            if ( <\/span>StrExtract<\/span>( <\/span>BackColorStr<\/span>, <\/span>RotateIndex <\/span>) == <\/span>"" <\/span>) <\/span>BackColor <\/span>= <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>BackColorStr<\/span>, <\/span>0 <\/span>) );\r            else <\/span>BackColor <\/span>= <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>BackColorStr<\/span>, <\/span>RotateIndex <\/span>) );\r\r            if ( <\/span>StrExtract<\/span>( <\/span>TextColorStr<\/span>, <\/span>RotateIndex <\/span>) == <\/span>"" <\/span>) <\/span>TextColor <\/span>= <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>TextColorStr<\/span>, <\/span>0 <\/span>) );\r            else <\/span>TextColor <\/span>=     <\/span>StrToNum<\/span>( <\/span>StrExtract<\/span>( <\/span>TextColorStr<\/span>, <\/span>RotateIndex <\/span>) );\r\r            <\/span>kStaticVarSetText<\/span>( <\/span>"Label" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>Label <\/span>);\r            <\/span>kStaticVarSet<\/span>( <\/span>"TextColor" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>TextColor <\/span>);\r            <\/span>kStaticVarSet<\/span>( <\/span>"BackColor" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>BackColor <\/span>);\r                <\/span>StaticVarSet<\/span>(<\/span>"RotateInit"<\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>, <\/span>True<\/span>);\r        }\r    }\r    <\/span>Label     <\/span>= <\/span>kStaticVarGetText<\/span>( <\/span>"Label" <\/span>+ <\/span>ColName <\/span>+ <\/span>RowNumber<\/span>);\r    return <\/span>Label<\/span>;\r}\r\r\rfunction <\/span>ButtonColumnEnd<\/span>()\r    {\r    global <\/span>ButtonHeight<\/span>, <\/span>ButtonWidth<\/span>, <\/span>PanelYoffset<\/span>, <\/span>PanelXoffset<\/span>, <\/span>ColNumber<\/span>, <\/span>RowNumber<\/span>, <\/span>ColName<\/span>;\r    <\/span>ChartIDStr     <\/span>= <\/span>NumToStr<\/span>(<\/span>GetChartID<\/span>(),<\/span>1.0<\/span>,<\/span>False<\/span>);\r    <\/span>ULButtonX         <\/span>= <\/span>PanelXoffset <\/span>+ (<\/span>ColNumber<\/span>-<\/span>1<\/span>) * <\/span>ButtonWidth<\/span>;\r    <\/span>LRButtonX        <\/span>= <\/span>ULButtonX <\/span>+ <\/span>ButtonWidth<\/span>;\r    for( <\/span>Row <\/span>= <\/span>1<\/span>; <\/span>Row <\/span><= <\/span>RowNumber<\/span>; <\/span>Row<\/span>++ ) \r        {\r        <\/span>ULButtonY         <\/span>= (<\/span>Row<\/span>-<\/span>1<\/span>) * <\/span>ButtonHeight <\/span>+ <\/span>PanelYoffset<\/span>;\r        <\/span>LRButtonY        <\/span>= <\/span>ULButtonY <\/span>+ <\/span>ButtonHeight<\/span>;\r        <\/span>Label     <\/span>= <\/span>kStaticVarGetText<\/span>(<\/span>"Label"<\/span>+<\/span>ColName<\/span>+<\/span>Row<\/span>);\r        <\/span>TextColor     <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>"TextColor"<\/span>+<\/span>ColName<\/span>+<\/span>Row<\/span>));\r        <\/span>BackColor     <\/span>= <\/span>Nz<\/span>(<\/span>kStaticVarGet<\/span>(<\/span>"BackColor"<\/span>+<\/span>ColName<\/span>+<\/span>Row<\/span>));\r        <\/span>GfxSelectSolidBrush<\/span>( <\/span>BackColor<\/span>);\r        <\/span>GfxRectangle<\/span>( <\/span>ULButtonX<\/span>, <\/span>ULButtonY<\/span>, <\/span>LRButtonX<\/span>, <\/span>LRButtonY <\/span>); \r        <\/span>GfxSetBkColor<\/span>( <\/span>BackColor<\/span>);\r        <\/span>GfxSetTextColor<\/span>( <\/span>TextColor <\/span>);\r        <\/span>GfxDrawText<\/span>( <\/span>Label<\/span>, <\/span>ULButtonX<\/span>, <\/span>ULButtonY<\/span>, <\/span>LRButtonX<\/span>, <\/span>LRButtonY<\/span>, <\/span>32 <\/span>| <\/span>1 <\/span>| <\/span>4<\/span>);\r        }<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"

A ButtonRotate function is like a ParamToggle() but with multiple states. The ButtonRotate function returns the label displayed on the button, and selects the next label each time you click the button. In the example below the ButtonRotate is used to select the next action, which can be Buy, Sell, Short, Cover, Cash, or Reverse. […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[134],"tags":[],"_links":{"self":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1662"}],"collection":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/comments?post=1662"}],"version-history":[{"count":0,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/posts\/1662\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/media?parent=1662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/categories?post=1662"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amibroker.org\/editable_userkb\/wp-json\/wp\/v2\/tags?post=1662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}