Click here to Login





                                                   Counting bars after a condition has been met

  0

0
umair
2013-02-26 01:37:48


Hi, I want to count how many bars occurred between two conditions and what the maximum value is between the two conditions:

Condition 1 = cross(a,b) Upward cross (price increases from bottom to up)

and then later when the price drops:

Condition 2 = cross(b,a) Downward cross (price decreases from top to bottom)

I want to know:

1) how many bars occurred between the two conditions
2) what the maximum potential profit/ max value was between these two values. For example:

When condition 1 cross occurred the price was 100. The price then increased to 110. Later the price dropped back down to 100.

Max potential profit = (110/100) -1
# of bars = bars that occurred from condition 1 to condition 2 (180 degrees)

Any idea how I should go about testing this? I know how to create the cross variables but am lost on counting the bars and potential profit.



QuantShare
2013-02-27 13:02:36

  1

1/ Use "barssince" to get the number of bars that occurred between the two conditions.

Example:

a = close;
b = sma(close, 250);
c = cross(a, b);
d = cross(b, a);
nb = BarsSince(c);


2/ To get the highest value that occurred since a condition is met, use the following function: Highest and Lowest value over a dynamic period

Example:
e = hhvllv(0, close, BarsSince(c));

After that you can easily calculate your maximum potential profit.

f = (e / ref(close, nb)) - 1;








Highest and Lowest value over a dynamic period (by QuantShare, uploaded several months ago)
No notes

Rate an item Rate an item Rate an item Rate an item Rate an item Number of downloads Notes Report an item

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 Consecutive Trading Bars Condition was True
Number of Trading Bars to Fill a Gap Up
Large price and volume gain after consolidation
% bars in last N trading days where stock close price increased
Percentage of Bars a Trading rule Generates Buy/Sell Signals

How-to Lessons
How to add future bars to plan for market scenarios
How to change volume bar colors when the price closes down
How to draw an horizontal segment line using QS language
How to add custom position-based metrics to your trading system
How to perform a basic quantitative analysis using the S&P 500

Related Forum Threads
close next bar with intraday bars
Speed of script execution for symbols with many bars
Regarding trading after market hours
Trailing Stop With Condition
How to get Bars since highest high?

Blog Posts
True portfolio simulation applied to trading systems
9 mistakes you should avoid when backtesting an end-of-day stock ...
How to choose which technical indicators to use in your trading s...
Example of a trading system implemented in QuantShare Software
How to simulate options strategies









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.