Skip to content

RATCHET() Function

By Optuma Team · Updated 2018-12-07

The RATCHET() function allows a script to be plotted that moves only in one direction, similar to a trailing stop. Once a level has been reached a script with an upwards ratchet can not lower in price - only move up. If the price on which the ratchet up is based moves lower then the line will appear horizontal.

Similarly the ratchet down can only set lower prices, and can’t increase in value. When the price moves higher the line will appear horizontal.

Ratchet Function Sample

Because the ratchet function is based on a starting date, the best way to use it is in conjunction with the the POINTS() function based on the mouse-click position, along with the Bar Variable feature.

The example above for the Ratchet Up is 2% below the low of the bar that is clicked on. The red line trails up with each higher low, and moves horizontally when the lows are lower.

//Get the mouse-click date
$v=POINTS().Point1.DateTime;
//Calculate the 2% below the low on the date of the mouse-click
RATCHET(LOW() * 0.98, START=$v)

The green Ratchet Down is 2% above the high, and trails down:

//Get the mouse-click date
$v=POINTS().Point1.DateTime;
//Calculate the 2% above the high on the date of the mouse-click
RATCHET(HIGH() * 1.02, START=$v, DIRECTION=Down)

To save the tools to your toolbox open the Script Manager window under the Settings menu. Save the script and make sure the Use as an Indicator box is ticked, and applied to the Same View:

Save to Tool Box

Once saved you will be able to apply it from your toolbox, and change the colour, line style, thickness, etc as required and Save Settings as Default under Actions so that the changes are remembered for next time, and then add a them to a toolbar button.

Choose which categories of cookies you allow. Strictly-necessary cookies are always on. You can change this any time via the "Cookie Settings" link in the footer.

  • Functional

    Remember preferences like dismissed banners and your dark-mode choice.

  • Analytics

    Help us understand how the site is used so we can improve it.

  • Marketing

    Measure our advertising and help us reach people who may be interested in Optuma.