本文介绍了方程的C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在学习C#,但是,我无法理解如何编写方程式。我试图计算价格的趋势和价格的动力。代码看起来像这样,不编译: #region使用声明 使用系统; 使用 System.ComponentModel; 使用 System.Diagnostics; 使用 System.Drawing; 使用 System.Drawing.Drawing2D; 使用 System.Xml.Serialization; 使用 NinjaTrader.Cbi; 使用 NinjaTrader.Data; 使用 NinjaTrader.Gui.Chart; #endregion // 此命名空间包含所有指标,是必需的。请勿更改它。 命名空间 NinjaTrader.Indicator { /// < 摘要 > /// 输入这里新定制指标的描述 /// < / summary > [说明( 在此处输入新自定义指标的说明)] public class TrendMomentum:指标 { #region变量 // 向导生成的变量 private int fastG = 9 ; // FastG的默认设置 private int slowG = 34 ; // SlowG的默认设置 private int wmadl = 1 ; // Wmadl的默认设置 private int momentumLg = 13 ; // MomentumLg的默认设置 // private bool UseMomentum = True; //使用Momentum的默认设置 // 用户定义的变量(添加任何用户定义的变量)下面) public int TrAvg = 13 ; #endregion /// < summary > /// 此方法用于配置指标和在加载任何条形数据之前调用一次。 /// < / summary > protected 覆盖 void Initialize() { Add( new Plot(Color.FromKnownColor(KnownColor.Gold),PlotStyle.Line, PTrend)); 添加(新 Plot(Color.FromKnownColor(KnownColor.Ivory),PlotStyle.Line, PTrEMA)); 添加( new Plot(Color.FromKnownColor(KnownColor.Green),PlotStyle.Line, PMomentum)); 添加(新行(Color.FromKnownColor(KnownColor.Yellow), 0 , Plot0)); Overlay = false ; } /// < 摘要 > /// 在每个条形更新事件(传入标记)上调用 /// < / summary > protected override void OnBarUpdate() { // 使用此方法计算指标值。通过将'Close [0]'替换为下方,为每个 // 下图分配值您自己的公式。 HL2 [ 0 ] =(高[ 0 ] +低[ 0 ])/ 2; // 第53行 HLC3 [ 0 ] =(高[ 0 ] +低[ 0 ] +关闭[ 0 ])/ 3; // 第54行 FastGG [ 0 ] = EMA(HLC3 [ 0 ],fastG); // 第55行 SlowGG [ 0 ] = WMA(HL2 [ 0 ],slowG); // 第56行 值[ 0 ] = FastGG [ 0 ] - SlowGG [ 0 ]; // 第57行 PTrend.Set( 10 * WMA(值[ 0 ],WMADL)); // 计算趋势 - 第58行 PTrEMA.Set(EMA(Ptrend) .Set [ 0 ],TrAvg)); // 计算趋势的平均值 - 第60行 Momo [ 0 ] =关闭[ 0 ] - 关闭[MomentumLg]; // 第62行 PMomentum.Set( 10 * WMA(Momo [ 0 ],SlowG)); // 计算动量 - 第64行 // } } NinjaScript文件错误代码行列指标\ TrendMomentum.cs名称' HL2'不存在 in 当前上下文CS0103 - 单击 info 53 4 Indicator\TrendMomentum.cs名称' HLC3'不存在 当前上下文CS0103 - 单击 info 54 4 Indicator\TrendMomentum.cs名称' FastGG'不存在 当前上下文CS0103 - 单击获取 info 55 4 Indicator\TrendMomentum.cs名称' HLC3'不存在 当前上下文CS0103 - 单击 info 55 20 Indicator \ TrendMomentum.cs名称' SlowGG'不存在 in 当前上下文CS0103 - 单击 info 56 4 Indicator\TrendMomentum.cs名称' HL2'不存在当前上下文中的class =code-keyword> CS0103 - 单击 info 56 20 Indicator\TrendMomentum.cs名称' FastGG'不存在 当前上下文CS0103 - 单击 info 57 15 Indicator\TrendMomentum.cs名称 ' SlowGG'不存在 当前上下文CS0103 - 单击 for info 57 27 Indicator\TrendMomentum。 cs名称' WMADL'不存在 the cu rrent context CS0103 - 单击 info 58 43 Indicator\TrendMomentum.cs名称' Ptrend'不存在 当前上下文CS0103 - 单击 info 60 28 Indicator\TrendMomentum.cs最佳重载方法匹配 ' NinjaTrader.Data.DataSeries.Set(double)'有一些无效的参数CS1502 - 点击 for info 60 13 Indicator\TrendMomentum.cs参数' 1':无法转换 from ' NinjaTrader.Indicator.EMA' to ' double' CS1503 - 点击 info 60 24 Indicator\TrendMomentum.cs名称' Momo'不存在 当前上下文CS0103 - 单击 info 62 4 Indicator\TrendMomentum.cs名称' Momo'不存在 当前上下文CS0103 - 单击 info 64 28 解决方案 你不能只抓住一个文件,并期望它自己完成所有工作:回到你获得文件的地方,然后获得整个项目。您可能需要查找并包含(至少)指标类,该指标类(可能)将缺失的变量定义为基类的一部分。 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:#region Using declarationsusing System;using System.ComponentModel;using System.Diagnostics;using System.Drawing;using System.Drawing.Drawing2D;using System.Xml.Serialization;using NinjaTrader.Cbi;using NinjaTrader.Data;using NinjaTrader.Gui.Chart;#endregion// This namespace holds all indicators and is required. Do not change it.namespace NinjaTrader.Indicator{ /// <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 wmadl = 1; // Default setting for Wmadl 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() { Add(new Plot(Color.FromKnownColor(KnownColor.Gold), PlotStyle.Line, "PTrend")); Add(new Plot(Color.FromKnownColor(KnownColor.Ivory), PlotStyle.Line, "PTrEMA")); Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "PMomentum")); Add(new Line(Color.FromKnownColor(KnownColor.Yellow), 0, "Plot0")); 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 53HLC3[0]= (High[0] + Low[0] + Close[0])/3; // Line 54FastGG[0]= EMA(HLC3[0], fastG); // Line 55SlowGG[0]= WMA(HL2[0], slowG); // Line 56Value[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 60Momo[0]= Close[0] - Close[MomentumLg]; // Line 62PMomentum.Set(10 * WMA(Momo[0], SlowG)); // Calculate Momentum - Line 64//} }NinjaScript FileErrorCodeLineColumnIndicator\TrendMomentum.csThe name 'HL2' does not exist in the current contextCS0103 - click for info534Indicator\TrendMomentum.csThe name 'HLC3' does not exist in the current contextCS0103 - click for info544Indicator\TrendMomentum.csThe name 'FastGG' does not exist in the current contextCS0103 - click for info554Indicator\TrendMomentum.csThe name 'HLC3' does not exist in the current contextCS0103 - click for info5520Indicator\TrendMomentum.csThe name 'SlowGG' does not exist in the current contextCS0103 - click for info564Indicator\TrendMomentum.csThe name 'HL2' does not exist in the current contextCS0103 - click for info5620Indicator\TrendMomentum.csThe name 'FastGG' does not exist in the current contextCS0103 - click for info5715Indicator\TrendMomentum.csThe name 'SlowGG' does not exist in the current contextCS0103 - click for info5727Indicator\TrendMomentum.csThe name 'WMADL' does not exist in the current contextCS0103 - click for info5843Indicator\TrendMomentum.csThe name 'Ptrend' does not exist in the current contextCS0103 - click for info6028Indicator\TrendMomentum.csThe best overloaded method match for 'NinjaTrader.Data.DataSeries.Set(double)' has some invalid argumentsCS1502 - click for info6013Indicator\TrendMomentum.csArgument '1': cannot convert from 'NinjaTrader.Indicator.EMA' to 'double'CS1503 - click for info6024Indicator\TrendMomentum.csThe name 'Momo' does not exist in the current contextCS0103 - click for info624Indicator\TrendMomentum.csThe name 'Momo' does not exist in the current contextCS0103 - click for info6428 解决方案 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. 这篇关于方程的C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-11 00:26