我是編程新手,我試圖在C#中爲NinjaScript/NinjaTrader編寫一些代碼,我希望有人可以提供幫助。 我有一個變量「tovBullBar」,它可以在三分鐘內爲某種類型的價格欄計算一些值。這段期間可能會發生多於一個這樣的障礙。這些值都是正確計算的,我可以在輸出窗口中看到它們。我試圖用一個數組來標識那個時期Min計算值的條,這樣這個值可以包含在我最後的netLvtTOV計算中。但是,我的最終計算結果始終是最後一個「tovBullBar」值,而不是最小值。你能看看我的代碼,看看你能告訴我我哪裏出錯了嗎?C#在NonjaScript中找到Min的最小值
我已經編碼了多達10個元素的數組,但他們幾乎肯定會更低,並會在每3分鐘的時間內變化。看過這裏的一些帖子後,我想我應該使用一個動態列表(我將不得不在後面討論),但是看到沒有理由爲什麼它不應該與數組一起工作,只要元素的數量爲I定義比我需要的更多。
謝謝!
#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);
}
我已經使用了您建議的代碼行,並且它們有助於分配正確的數組值到我的最終計算。但我仍然有一個主要問題。在第一個信號之後的3分鐘內TOVBullBar沒有出現,而不是在最終計算中爲tovBullBarMin指定值0,代碼將回顧3分鐘開始前的時間段並獲取最後一個tovBullBar值用於計算。我試圖在3分鐘結束時使用Array.Clear來停止這一操作,但不工作。將嘗試發佈代碼。 – GeorgeW
第一行之後的行:'if(check && Time [0] = firstSig.AddMinutes(3 )) \t \t \t { \t \t \t Array.Clear(tovBull,0,tovBull.Length); \t \t \t打印(時間[0] +「最終信號」); \t \t \t check = false;' –
GeorgeW
如何定義啓動3分鐘時鐘的BarEvent,因爲這隻能在lvtBullBar之後啓動?目前它似乎正在計算所有條形圖,所以ArrayLength是800+,對於每個3分鐘的塊,如果只計算tovBullBars,它應該不超過7個最大值。謝謝! – GeorgeW