In the Advanced Money Management script I can get the current bar date using the following function: Divers.CurrentDate.
Is there a way to get the previous n bar Date?
As not all weekdays are trading days, I can't find a strait forward way to get the previous n bar date.
I was trying to create a custom function (BarDateTime) and return the Date string in the result vector, but when I try to call my custom function with ParseFormula, the function always returns 0;
int n = (int)N[0];
for(int i = 0;i<cFunctions.Date.Length;i++)
{
int shift = i + n;
if(shift > 0 && shift < cFunctions.Date.Length)
{
result.SetValue(i, cFunctions.Date[shift].ToString());
}
else
{
result.SetValue(i, String.Empty);
}
}
---------------------------------------------------------------------------
This is how I try to call in the Money Management script using the Data.ParseFormula:
TimeSeries twoDaysBeforeToday = Data.ParseFormula("a = BarDateTime(2);").GetTimeSeries(symbol, "a");
twoDaysBeforeToday[0] is always 0 even if I write the BarDateTime function result to the Global.Trace then I can see that I have valid values in the result object.
Another solution, would be to create a list in the Global event and store the Divers.CurrentDate date on each "OnEndPeriod" event.
Then you can access the previous N item of the list easily.
Thank you for your response.
The solution I have found looks more flexible than the one with "OnEndPeriod" because it can be used with bars in past and in the future as well. With the "OnEndPeriod" you can access only the previous bars but not the future bars.
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.