RATCHET() Function

Author: Optuma Team Last updated: Dec 7, 2018 01:43

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
//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
//Calculate the 2% above the high on the date of the mouse-click</span>  

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.