logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
marco1971  
#1 Posted : Tuesday, March 15, 2016 3:31:03 PM(UTC)
marco1971

Rank: Newbie

Groups: Registered Users, Subscribers
Joined: 3/15/2016(UTC)
Posts: 1

Hi,

I'd like to test a system where a buy or sell order is given by a custom indicator. I need this one is below or above zero for "at least" a certain number of bars. How can I do this with the barssince function?

Let's name A my indicator, is it correct, for example: barssince(A<0)>"number of bars"? And can I optimize the variable "numer of bars.

Thank you

Regards

Marco1971

MS Support  
#2 Posted : Tuesday, March 15, 2016 5:10:43 PM(UTC)
MS Support

Rank: Advanced Member

Groups: Moderators, Registered, Registered Users, Subscribers
Joined: 10/8/2010(UTC)
Posts: 1,929

Thanks: 85 times
Was thanked: 154 time(s) in 150 post(s)

Should work to use the opposite condition, you may also want to use 'or equal to' to rule out if the value is exactly 0:

BarsSince(A<=0)>=3

Another option might be to Sum the condition over a number of periods, i.e.:

Sum(A>0,3)>=3

Whenever a condition is true, it would return a value of 1, so summing a true over 3 periods should equal 3 if true for 3 periods in a row. This may be more reliable in some cases where there might not be a perfect opposite condition to consider. You can Optimize numerical values in the system tester by using OPT1, OPT2, etc. and then defining the range of numbers you want to test between within the Optimizations tab.

As in the example above:

BarsSince(A<=0)>=OPT1

or in my example:

Sum(A>0,OPT1)>=OPT1

Edited by user Tuesday, March 15, 2016 5:15:37 PM(UTC)  | Reason: Not specified

Users browsing this topic
Similar Topics
Barssince Stoch Osc (Basic Coding Techniques)
by sevenvironment 6/14/2023 8:16:05 AM(UTC)
barssince() has problems when the condition never happened (MetaStock)
by yonyon191719 12/9/2018 10:33:25 PM(UTC)
Moving Average and Barssince (Basic Coding Techniques)
by JayB 3/4/2017 4:21:50 PM(UTC)
BarsSince and Cross (Formula Assistance)
by stinkray 8/4/2016 6:53:24 AM(UTC)
BarsSince sintax (Formula Assistance)
by Leverage 7/22/2015 1:41:11 PM(UTC)
How can i find barssince of event cross(macd(),0) by nth=2 (Formula Assistance)
by atitats 12/4/2014 6:29:39 AM(UTC)
Fun with BarsSince event (Advanced Coding Techniques)
by Lloyd_au 4/16/2014 9:18:07 AM(UTC)
BarsSince event (Formula Assistance)
by Gherkin 3/31/2014 11:16:52 PM(UTC)
How can i omit the current bar in a BARSSINCE function? (MetaStock)
by xrousaios 11/8/2013 10:24:21 AM(UTC)
barssince() (MetaStock)
by Flexi 11/27/2011 6:25:15 AM(UTC)
StockRSI Modify (BarsSince) (Formula Assistance)
by GameTime 2/12/2011 12:09:09 PM(UTC)
BarsSince() help (Formula Assistance)
by v.trader 5/9/2010 1:44:05 PM(UTC)
question of Barssince and Sum function (Formula Assistance)
by metaken 3/3/2009 7:59:38 AM(UTC)
Barssince, Max% DD question (Basic Coding Techniques)
by zigzag 2/18/2009 11:14:45 AM(UTC)
Basic Barssince Question (Formula Assistance)
by AMSH 2/17/2009 2:59:45 PM(UTC)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.