Log in to see Cloud of Tags

**Main Page**- Category List
- Knowledge Base
- Traders Tips
- Indicator documentation
- Addin examples

Log in to search

```
DataSeries SMI (Bars bars, int period1, int period2, int period3, string description)
public static SMI Series(Bars bars, int period1, int period2, int period3)
```

bars | A Bars object to apply SMI to |

period1 | First smoothing period (for the highest/lowest range) |

period2 | Second smoothing period (for smoothing the distance of today's close from the midpoint of the range) |

period3 | Third smoothing period (final smoothing; usually, period3 is equal to period2) |

Begin by selecting the desired range. We use n = 10.

Then calculate the midpoint price M of the highest high and the lowest low in the range:

M = (HighMAX + LowMIN) / 2

where

HighMAX = the highest high in the range LowMIN = the lowest low in the range

Next calculate the difference (or “distance”) D of today’s closing price from the midpoint of the range:

D = CPTODAY – M

where CPTODAY = today’s closing price

Then smooth the value of D twice with an exponential moving average. We use a three-period EMA:

DS1 = EMA(3)(D) DS2 = EMA(3)(DS1)

Next, smooth the difference between the maximum high and minimum low twice, using the same EMA as before, and divide the second smoothed result by 2:

DHL = EMA(3)(HighMAX - LowMIN) DHL2 = EMA(3)(DHL) / 2

Finally, calculate the SMI:

SMITODAY = 100 * (DS2 / DHL2)

```
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
using Community.Indicators;
```

namespace WealthLab.Strategies
{
public class SMIDemo : WealthScript
{
private StrategyParameter paramPeriod1;
private StrategyParameter paramPeriod2;
private StrategyParameter paramPeriod3;
public SMIDemo()
{
paramPeriod1 = CreateParameter("Period 1", 10, 2, 20, 1);
paramPeriod2 = CreateParameter("Period 2", 3, 2, 10, 1);
paramPeriod3 = CreateParameter("Period 3", 3, 2, 20, 1);
}
protected override void Execute()
{
int per1 = paramPeriod1.ValueInt;
int per2 = paramPeriod2.ValueInt;
int per3 = paramPeriod3.ValueInt;
SMI smi = SMI.Series( Bars,per1,per2,per3 );

for(int bar = GetTradingLoopStartBar(smi.FirstValidValue * 3); bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
if( CrossUnder( bar, smi, -40 ) )
SellAtMarket( bar+1, LastPosition );
}
else
{
if( CrossOver( bar, smi, 40 ) )
BuyAtMarket( bar+1 );
}
}
ChartPane sPane = CreatePane( 40,true,true );
PlotSeries( sPane, smi, Color.Fuchsia, LineStyle.Solid, 2 );
DrawHorzLine( sPane, 40, Color.Green, LineStyle.Dashed, 1 );
DrawHorzLine( sPane, -40, Color.Red, LineStyle.Dashed, 1 );
HideVolume();
}
}
}