Tutorial Indicator as Forest


Forest Chart
To display indicators as a forest chart, the indicator code has to be adapted accordingly. In the following tutorial, we show you how to set up a Momentum indicator as a forest chart with the needles in two different colors, depending on their direction.

The "normal" Momentum Indicator

You can find the normal Momentum Indicator in the list of all indicators in the Toolbox. Right-click the indicator to open the context menu and choose Edit. The editor with the indicator's equilla code opens.

Meta:
    Synopsis( "The Momentum indicator utilizes price and volume statistics for predicting the strength or weakness of a current market and any overbought or oversold conditions, and may indicate turning points within the market." ),
    ShortCode( "MOM" ),
    SubChart( True );

Inputs:
    Price( Close ),
    Period( 10, 1 ),
    ShowAlerts( False );


DrawLine( Momentum( Price, Period ), "MOM" );
DrawLine( 0, "Zero Line", StyleDot );

CheckForCrossAlert( Plot1, 0, "Momentum", "Zero Line", ShowAlerts );

// *** Copyright SystemSoft GmbH ***
// *** www.tradesignal.com ***

Copy the Momentum Indicator code as basis for the new indicator

  1. Click on New Indicator in the Related Tasks area of the toolbox to start a new indicator. Call it Momentum Forest.
  2. Copy the equilla code of the Momentum indicator into the new, empty editor window.
To do so, select the complete code with CTRL+A. Then copy the contents with CTRL+C. Click into the new, empty editor window and press CTRL+V to insert the copied contents. Alternatively, you can find all these functions in the context menu of the editor, which you can open by right-clicking the editor window.

Editing the Momentum Forest indicator for display as a forest chart


HTML Editor with Indicator Code
First, you have to delete some lines in the code we do not want to use:
  • ShowAlerts( False ); (make sure that the line above ends with a semicolon ";")
  • CheckForCrossAlert( Plot1, 0, "Momentum", "Zero Line", ShowAlerts );
Then you need two variables for your indicator:
  • one variable to save the momentum calculation
  • one variable to save the color setting for the forest display
For this, enter the following lines beneath the Inputs area:
Variables:
momValue, forestColor;


Below this, enter the formula for the Momentum calculation:

//Calculate Momentum
momValue = Momentum( Price, Period );


Now you need the condition for the needle colors. If the Momentum rises in comparison to the previous day, the needle should be displayed in green; otherwise, the needle should be red.

//Set color depending on the change in comparison to the previous day
if momValue > momValue[1] then
    forestColor = DarkGreen
else
    forestColor = Red;


To display the result as forest chart, you have to substitute the first DrawLine line with the following:

//Drawing command with color variable
DrawForest(0, momValue,"Zero","MomentumUp",thick,forestColor,true);


The color of the needle is given by the dynamically set variable forestColor. The base line remains unchanged.

In the META area of the code you can now edit the synopsis and enter a specific ShortCode. With the latter, you can later call up your new indicator from the command line.

Compiling and applying the Momentum Forest Indicator

Meta:
    Synopsis( "The Momentum Forest is a variation of the Momentum Indicator, displaying the values in Forest fashion with color coding for up/down development. The Momentum indicator utilizes price and volume statistics for predicting the strength or weakness of a current market and any overbought or oversold conditions, and may indicate turning points within the market." ),
    ShortCode( "MOMF" ),
    SubChart( True );

Inputs:
    Price( Close ),
    Period( 10, 1 );


Variables:
    momValue, forestColor;


//Calculate Momentum
momValue = Momentum( Price, Period );

//Set color depending on the change in comparison to the previous day
if momValue > momValue[1] then
forestColor = DarkGreen
else
forestColor = Red;

//Drawing command with color variable
DrawForest(0, MomValue,"Zero","MomentumUp",thick,forestColor,true);
DrawLine( 0, "ZeroLine", StyleDot)

// *** Copyright tradesignal GmbH ***
// *** www.tradesignal.com ***


Compile the indicator by pressing the F7 key or by clicking the Compile Script button in the Equilla menu in the toolbar.

The indicator is now available in the indicator list in the toolbox. From there, you can apply it to a chart by either pulling it into a chart via drag&drop or by selecting Apply from the context menu.