slider (int number, int pos, int min, int max, string name, string tooltip) : var
Returns the current position of one of the four sliders; optionally also gives the slider an initial position, range, name, and tooltip. Depending on the selected asset or other conditions, different slider positions can be preset at the beginning.
||The number of the slider: 0 for the Period slider, 1..3 for the 3 user-specific sliders.
||Optional initial position of the slider (default = 0). The position is set when the script is run the first time.
||Optional minimum and maximum positions of the slider, left and right.
||Optional name for the slider that is displayed in the main panel (f.i. "Panic"), or 0 for not changing the name.
||Optional tool tip text to describe the slider function, or 0 for not changing the tool tip.
Current value of the slider.
Slider1 .. Slider3
Variable containing the current value of the 3 user-specific sliders. The slider can be moved at runtime by setting those variables to a different value.
- For defining a slider initial position, range, name, and tooltip, the slider function must be called in the first run of a strategy. The Period slider has fixed parameters and is hard-wired to the BarPeriod variable. Only its initial position (pos) can be set. The other three sliders can be freely set and redefined.
- The sliders jump to their default positions (pos parameter) when the script is started the first time, or when [Script], [Asset], or [Edit] was clicked. Otherwise the sliders keep their previous position. For testing a script with a certain slider position, click [Test], wait until the sliders appear, then click [Stop], put the sliders to the desired position and click [Test] again. In [Trade] mode the sliders are stored in the .trd file and thus always 'remember' their last position.
- The slider positions can be read and set at runtime through the BarPeriod, Slider1, Slider2, and Slider3 variables. Those variables can also be used to optimize the slider positions for a certain strategy with the optimize function. Directly setting the BarPeriod, Slider1, Slider2, and Slider3 variables moves the slider to the variable value. This way the script can display numerical values to the user while running.
- In [Test] mode the sliders could be used to set up time periods, buy/sell thresholds, or stop/profit distances. In [Trade] mode, the sliders could be used for entering separate thresholds for buying long and short, or to set the number of lots per trade. This way the strategy can be adapted in real time to the expectation of rising or falling prices, or to the risk.
- Aside from the sliders, a panel with entry fields can also be used for user input.
Lots = slider(1,2,1,10,"Lots","Lots per Trade");
Stop = PIP*slider(2,15,0,30,"Stop","Stop Loss in PIPs");