Click here to Login

                                                   Sample Code from Beginner


Amritendu Maji
2017-07-07 11:55:24

I am trying to write a simple system that ranks all the stocks in the portfolio based on ROC and then buys the number 1 stock out of a portfolio, when the S&P500 close crosses over its 50 day SMA.
Here is the code. Does it make sense?

Also, it will sell when the reverse happens with the S&P500.

Thank you,

Optimal_SMATime = 50;
a0 = sma(GetSeries("^GSPC", close), Optimal_SMATime);
b0 = GetSeries("^GSPC", close);

Rule1 = cross(b0, a0);

Optimal_rocTime = 50;
Rule2 = comp(Roc(close,Optimal_rocTime), "rank") == 1;

Rule3 = cross(a0, b0);

buy = Rule1 && Rule2;
sell = Rule3;

2017-07-08 05:27:57


This looks perfect.

No more messages


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"


Trading Items
News data for US companies from Google RSS feed
Stock Picks from Wikinancial
Lagged Data From a Custom Database
Market cap, ROE, ROA and Forward PE for U.S. Stocks - Fundamental...
Stock News from Articles, Bloggers, Columnists, Traders and Analy...

How-to Lessons
How to run a screen or a watchlist from a script
How to generate buy/sell signals from a trading system
How to import trading items from other accounts
How to get trading orders from a portfolio programmatically
How to add trades from one portfolio to another one

Related Forum Threads
Reuse optimization parameters from Strategy script in Money Mgmt
Newby's questions -symbol lists, code etc. ...
Creat a Composite Index from few stock symbol
code to get todays date
Code for built-in TA functions

Blog Posts
How to Backtest a Strategy from a Chart
Reading and Exporting Data from QuantShare to Excel Programmatica...
How to Send Commands to QuantShare from Excel or Other Applicatio...
How to filter quotes data from high and low price spikes
Diversify your portfolio by investing in stocks from various indu...

Create an account
Affiliate Program
Contact Us
Trading Forum
How-to Lessons
About Us
Terms of Use

Copyright 2021
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
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.