### Sample strategy with charts

Video: A more in-depth look at Seetu, including an Exponential Moving Average (EMA) trading strategy that is not meant to make money, but which - surprisingly - does.

Example 9. Strategy: Sample strategy with charts

```      /*

This is an example of a basic Seetu program. The trading system is purely an example meant to teach the language,
and NOT meant to make money. This goal of this program is to demonstrate common components of Seetu code.

By the way, this area that you are reading (starting with slash-star and ending with star-slash)
is a multi-line comment. Comments like these are ignored by Seetu.

*/

// Any line that starts with two slashes, like this one, is a single-line comment
// which is also ignored by Seetu.

// Let's start with some common ideas you will often find in Seetu programs:

// Delay entry/exit by one bar
SetTradeDelays( 1, 1, 1, 1 );

// When we examine back-tested results of our trading strategy,
// results are based on the fact that we start our backtest with \$100,000 dollars.
// We specify this as follows:

SetOption( "initialequity", 100000 );

// Round a number of shares traded to 100.
SetOption("RoundLotSize",100);

// We can also specify that each trade we place will be 25% of available equity.
SetPositionSize( 25, spsPercentOfEquity );

// Now for the trading system itself. It is based on an Exponential Moving Average, or EMA.
// Here are the rules.

/*
- Buy when EMA averages crosses, AND the current HIGH is highest for 50 bars
- Sell when EMA averages crosses back
*/

// Set EMA periods to varibles.
// We can change them easily on this single place when testing different periods.
LongEMAPeriods = 50;
ShortEMAPeriods = 5;

// Calculate and save average and recent highest high value
// ---------------------------------------------------------------------
// This section calculates useful values that we will use told decide when to buy and sell.
//
// First, the longer moving average
// Set the variable name LongMA to be the Exponential Moving Average of the last several CLOSEs.
// How many closes?
// A number of periods (variable name LongEMAPeriods) is set to 50.
// So we are setting LongMA to the exponential moving average of the last 50 closes.
LongMA = CalcEMA( Close, LongEMAPeriods );

// Shorter MA is calculated in a similar fashion, but only uses the last 5 CLOSEs.
// (The number 5 is stored in the ShortEMAPeriods variable.)
ShortMA = CalcEMA( Close, ShortEMAPeriods );

// What is the highest HIGH in the last 50 bars?
LastHigh = GetRecentHighest( High, LongEMAPeriods );

// ---------------------------------------------------------------------
// Remember the strategy: "Buy when EMA averages crosses, AND the current HIGH is highest for 50 bars."
// Here's how we say that in Seetu language:

Buy = Cross( ShortMA, LongMA ) AND High > Ref( LastHigh, -1 );

// This part of the statement above:
// 	High > Ref( LastHigh, -1 )
// means: this bar's HIGH must be greater than the greatest HIGH over the last LongEMAPeriods bars
//
// If we had instead used H==LastHigh . . . that would have required the current high is equal to the previous high

// Sell logic:
Sell = Cross( LongMA, ShortMA );

// Remove surplus trade signals to have less rows in Scan and Exploration

// Exploration:
/*
Exploration is based on the Filter variable.
Exploration includes just those rows where Filter is TRUE.
*/

// In this particular case we restrict the Exploration window to display only those rows where Buy or Sell signals occur.
Filter = Buy OR Sell;

// Add some columns to Exploration grid