【发布时间】:2016-06-02 10:04:34
【问题描述】:
我是编码新手,我正在尝试用 C# 为 NinjaScript / NinjaTrader 编写一些代码,希望有人能提供帮助。 我有一个变量“tovBullBar”,它在三分钟内计算某种类型的价格柱的一些值。在此期间可能会出现不止一个这些柱形图。这些值都计算正确,我可以在输出窗口中看到它们。我正在尝试使用一个数组来识别该时期内具有 Min 计算值的条形图,以便该值可以包含在我对 netLvtTOV 的最终计算中。但是,我的最终计算始终以该期间的最后一个“tovBullBar”值结束,而不是具有最小值的那个。你能看看我的代码,看看你能不能告诉我哪里出错了?
我已经对数组中的最多 10 个元素进行了编码,但几乎可以肯定它们会更低,并且每 3 分钟会有所不同。看过这里的一些帖子后,我想我应该使用动态列表(稍后我将不得不考虑一下),但没有理由认为它不应该与数组一起使用,只要我的元素数量定义比我需要的要多。
谢谢!
#region Using declarations
using System;
using System.Linq;
#endregion
#region Variables
//Declare an array that will hold data for tovBullBar
private double[] tovBull;
private int length = 10;
#endregion
protected override void Initialize()
{
//specify the number of elements in the array, which is the
integer called length
tovBull = new double[length];
}
protected override void OnBarUpdate()
{
//the array now contains the number length of object references that need to be set to instances of objects
for (int count = 0; count<length; count++)
tovBull[count]=tovBullBar;
//Do a for loop to find the minimum for the tovBull
double tovBullBarMin = tovBull[0];
for (int count = 0; count < tovBull.Length; count++)
if (tovBullBarMin > tovBull[count])
tovBullBarMin = tovBull[count];
netLvtTOV = Math.Round((tovBearBar + tovBullBarMin + lvtBullBar)
Print (Time.ToString()+" "+"ArrayLength:"+tovBull.Length);
}
【问题讨论】: