Click here to Login





                                                   bars since entry in QS language?

  0

0
BWBerg
2015-01-13 10:01:13


How to count the number of bars since entry of a long or short position in QS language?

thks



BWBerg
2015-01-13 10:05:23

  0

Sorry ... should have searched before posting...

Looks like this is my answer:

barssince(buy)




Kyra Packens
2015-01-15 03:32:53

  0

I believe that barssince(buy) will gives you the number of bars since your last buy _signal_, but that isn't necessarily the number of bars since a position was entered. If you need to know that (eg, to keep your system from exiting a position before N bars pass) you will need to use an advanced money management script.

Good news though -- I think I read somewhere that exposing position status in the QS language for simulations is on the short list of things to implement.



QuantShare
2015-01-15 05:07:46

  0

Yes, this was the function you are looking for.


Kiran
2016-03-19 13:05:30

  0

So reg the issue Kyra raised above, if i have only 1 position per symbol (no pyramiding), will barssince(buy) in Quantscript measure the position hold time for the symbol being evaluated in the backtest? Want to avoid writing MM for this simple function if i can.


QuantShare
2016-03-21 03:46:43

  0

It would work only in certain cases. This is because the QS formula is used to generate signals but the real backtesting (entering/selling positions) is occurring after that. So you could get the number of bars since the "buy" rule was true but depending on your formula, that "buy" signal may or may not have been used by the backtester.


Kiran
2016-04-13 13:38:00

  0

I have a simple timing script on 1 symbol (SPY) that Buys when Price>SMA, Sells 10 days later.
It doesn't seem to execute the barssince(buy)>10; correctly, because the Trades tab shows positions are held for 4-6 weeks (variable time periods).
- why isn't the barssince(buy)>10 work correctly in this scenario?

/// script
Optimize("fastper", 5,75,10);
Optimize("slowper", 50,200,25);
Optimize("holdper",10,30,10);

Buy = (Close > SMA(Close,fastper) && Close > SMA(Close,slowper));
Sell = barssince(buy)>holdper;
//Sell = (Close < SMA(Close,fastper) || Close < SMA(Close,slowper)) && barssince(buy)>holdper;



QuantShare
2016-04-14 04:35:04

  0

Because each time the "buy" is true, the "barssince(buy)" counts bars since that new "buy" bar. Just plot it in a chart and you will better understand. If there is a "buy" signal every 5 bars then the position will never exit.

It is important to understand that QS formulas are used to generate buy/sell signals only. After that the simulator will perform a true-portfolio backtest using these signals. Therefore you cannot reference a trade in a QS formula because they do not exist yet.

In your example, you can replace the sell rule by an N-bar stop loss.



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
Number of bars since the beginning of the month
Stop Loss for the N-first Trading Bars only
Drawdown Since Trading Signal
Days Since Inception Filter
Number of Trading Bars to Fill a Gap Up

How-to Lessons
How to add future bars to plan for market scenarios
How to add custom position-based metrics to your trading system
How to plot arrows below/above candlesticks on a chart
How to download new quotes when selecting a chart
How to filter stocks in a market composite

Related Forum Threads
How to get Bars since highest high?
Entry conditions and fields
Entry Signal Rejection Criteria
No. of bars in a different timeframe
MM Staggered Entry and Exit

Blog Posts
A simple but useful way to display distances in a chart
Money Management: Scale-in Trading Strategy
How to create a trading system, screen and composite using earnin...
Day Trading: A trading system that combines intraday and EOD data
Basic trading system implemented using the money management tool









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.