Click here to Login





How to draw an horizontal segment line using QS language

Updated on 2020-01-10 11:25:47

Share |

This lesson will show you how to draw an horizontal line that starts at a particular bar in the past and ends at the last bar.
The line will show the last 25 bars low (25 is approx. a month).

- First we need to calculate the 25 bars low using the "llv" function
- Next we need to get the low at the last bar and this is done using the "lastvalue" function
- Next we will add a condition that will return the low if the analyzed bar is within the last 25 bars or zero otherwise
- Next we will convert each zero into NaN (Not a numeric) so that the line is not displayed at any bar that has zero as value

For the above step, you will need to download the following function: ZeroToNan

- Finally, we will plot the line and give it a red color using the "plot" function

Here is the complete code:

a = llv(low, 25);
a = lastvalue(a);
a = iff(count() > TotalBars() - 25, a, 0);
a = zerotonan(a);
plot(a, "", colorRed);










no reviews (Log in)







Other how-to articles




How to plot a stock using different periods in the same chart





How to draw distances on a chart?





How to automatically draw Fibonacci Retracement for each new stock?





How to perform a basic quantitative analysis using the S&P 500





How to optimize a neural network using a genetic algorithm





How to get stocks for a particular index using the global script





How to debug a trading system using the money management tool





How to calculate the average of a time series using the money management tool





How to create a custom trendline







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