One easy way to do this is via creating a function.
This may seem rather complicated, but once you get the hang of creating functions any idea is possible. I taught myself via the tutorials, downloading and examining functions other people had created, and using online c# tutorials, as my c was pretty rusty.
So the following code appears to work
VectorD close = cFunctions.Close;
VectorD SMA = TA.Sma(50);
bool fail = false;
if (result.Length > (int)Bars[0] )
{
for( int i = (result.Length - (int)Bars[0] - 2) ; i < result.Length ; i++)
{
if ( close[i] > SMA[i]) fail = true;
}
result[result.Length - 1] = fail ? 0 : 1;
}
A variable needs to be created called "Bars" which represents the number of days to look back. So if you called this function SMAUnder , in a dynamic watchlist you would only need one line "filter = SMAUnder(5);" (looking back 5 trading days) you could even add another variable to pass the function the desired SMA #.
If you can't get this working, I would do as I mentioned above, go through the tutorials, download and examine functions others have created from the sharing server to answer questions that the tutorials don't cover, learn c#!
I replied to this not to step you through how to create a function but to show you that if you have ideas' then to really get the most from Quantshare, you will need to get up to speed with creating functions, it took me a while and I'm still learning, but for me the freedom to code idea's makes Quantshare an extremely powerful package (still looking for that winning idea...).
David,
Thank you so much. You are correct, I need to learn functions. I did a lot of Visual Basic programming back many years ago. I have been tinkering with Python lately. I should be able to get a handle on C#. Thanks for giving me a great starting point, and the encouragement.
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.