Click here to Login





                                                   Multiple days under SMA 50

  1

0
Rodney
2021-02-27 21:58:05


Hello,
I am trying to screen for symbols for the previous N days, where the close of every bar is under the sma(50).

var4 = ref(close,1)<sma(50);
var5 = ref(close,2)<sma(50);
var6 = ref(close,3)<sma(50);
var7 = ref(close,4)<sma(50);
var8 = ref(close,5)<sma(50);
var9 = ref(close,6)<sma(50);

filter = var4 and var5 and var6 and var7 and var8 and var9;

Is there a more efficient way to do this?

Thanks,



David
2021-03-03 23:01:35

  1

Best Answer
Hi

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...).

Cheers




Rodney
2021-03-05 17:53:23

  0

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.

Have a great day.



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










QuantShare

Trading Items
Time Under Water - Drawdown
GMMA - Guppy Multiple Moving Average
Minimum Number of Days Between Two Events
Next Split Ex-Date In Days
5x5 SMA & RSI Forex Strategy

How-to Lessons
How to quickly download the most recent EOD data for your stocks
How to remove non-active securities
How to import trading data from CSV files
How to create a screen
How to plot a stock using different periods in the same chart

Related Forum Threads
Composite tickers under custom database
Trading System using multiple time frames
Multiple quote databases with same symbols?
Count Down Days
days naming

Blog Posts
Compare Multiple Securities in a Single Chart
Technical Analysis Using Multiple Timeframes
Technical Analysis Using Multiple Timeframes - Second Part
Correlation Between Multiple Trading Systems
Backtesting trading strategies using intraday data









QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



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.