15,966,305 members
1.00/5 (1 vote)
See more:
I am learning C#, however, I am having trouble understanding how to write equations. I am trying to calculate the trend of price and what momentum the price has. The code looks like this and does not compile:

C#
```#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
#endregion

// This namespace holds all indicators and is required. Do not change it.
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class TrendMomentum : Indicator
{
#region Variables
// Wizard generated variables
private int fastG = 9; // Default setting for FastG
private int slowG = 34; // Default setting for SlowG
private int momentumLg = 13; // Default setting for MomentumLg
//private bool UseMomentum = True; // Default setting for use Momentum
// User defined variables (add any user defined variables below)

public int TrAvg = 13;
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Overlay				= false;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
HL2[0]		= (High[0] + Low[0])/2;            // Line 53
HLC3[0]		= (High[0] + Low[0] + Close[0])/3; // Line 54
FastGG[0]	= EMA(HLC3[0], fastG);             // Line 55
SlowGG[0]	= WMA(HL2[0], slowG);              // Line 56
Value[0]	= FastGG[0] - SlowGG[0];           // Line 57
PTrend.Set(10 * WMA(Value[0], WMADL));  //Calculate Trend - Line 58

PTrEMA.Set(EMA(Ptrend.Set[0], TrAvg)); //Calculate an average of Trend - Line 60

Momo[0]	= Close[0] - Close[MomentumLg];             // Line 62

PMomentum.Set(10 * WMA(Momo[0], SlowG));  // Calculate Momentum - Line 64

//}

}
NinjaScript File	Error	Code	Line	Column
Indicator\TrendMomentum.cs	The name 'HL2' does not exist in the current context	CS0103 - click for info	53	4
Indicator\TrendMomentum.cs	The name 'HLC3' does not exist in the current context	CS0103 - click for info	54	4
Indicator\TrendMomentum.cs	The name 'FastGG' does not exist in the current context	CS0103 - click for info	55	4
Indicator\TrendMomentum.cs	The name 'HLC3' does not exist in the current context	CS0103 - click for info	55	20
Indicator\TrendMomentum.cs	The name 'SlowGG' does not exist in the current context	CS0103 - click for info	56	4
Indicator\TrendMomentum.cs	The name 'HL2' does not exist in the current context	CS0103 - click for info	56	20
Indicator\TrendMomentum.cs	The name 'FastGG' does not exist in the current context	CS0103 - click for info	57	15
Indicator\TrendMomentum.cs	The name 'SlowGG' does not exist in the current context	CS0103 - click for info	57	27
Indicator\TrendMomentum.cs	The name 'WMADL' does not exist in the current context	CS0103 - click for info	58	43
Indicator\TrendMomentum.cs	The name 'Ptrend' does not exist in the current context	CS0103 - click for info	60	28
Indicator\TrendMomentum.cs	The best overloaded method match for 'NinjaTrader.Data.DataSeries.Set(double)' has some invalid arguments	CS1502 - click for info	60	13
Indicator\TrendMomentum.cs	Argument '1': cannot convert from 'NinjaTrader.Indicator.EMA' to 'double'	CS1503 - click for info	60	24
Indicator\TrendMomentum.cs	The name 'Momo' does not exist in the current context	CS0103 - click for info	62	4
Indicator\TrendMomentum.cs	The name 'Momo' does not exist in the current context	CS0103 - click for info	64	28```
Posted
Updated 19-Nov-13 3:16am
v4
BillWoodruff 18-Nov-13 21:55pm
Look to me like you are studying how software called NinjaTrader works.

Since you paid a lot for NinjaTrader, why not post a message to the company ?
Richard MacCutchan 19-Nov-13 4:53am
What errors do you get and where do they occur?

## Solution 1

You can't just grab a single file and expect it to work all on it's own: go back to where you got the file, and get the whole project. The chances are that you need to find and include (at a minimum) the Indicator class which (presumably) defines the missing variables as part of teh base class.