Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

"Bars Since" Indicator
 Post subject: "Bars Since" Indicator Post rating: 0   New post Posted: Thu 29 Oct, 2009, 22:43 

User rating: 0
Joined: Wed 21 Oct, 2009, 04:47
Posts: 22
Hi there,

I was wanting to have an indicator that tells me how many bars ago a condition was met. For example, if a fast moving average crosses over a slow one, the "bars ago" indicator would read 0 at that point. As time bars are added, this count would increase until the next cross-over occurred. You would be able to use this 'bars ago' number to various reasons such as to reference the price at the time the cross-over occurred. eg.

double priceWhenCrossOverOcurred = ClosePrice[currentBarIndex-barsAgoIndicator[currentBarIndex]]


or you could use it to determine how many bars have elapsed since the cross-over:

if ( barsAgoIndicator[currentBarIndex] < 5 )
{
// Less than 5 periods have elapsed since the cross over, do something..
}


Is there an example somewhere of how to do this? From the current Indicator framework, I'm not sure how to best fit this in. The indicators are based on a 'lookback' value, however you don't know how far to look back to find the last cross-over.

Thanks.


 
 Post subject: Re: "Bars Since" Indicator Post rating: 0   New post Posted: Fri 30 Oct, 2009, 08:55 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,

You can set unstablePeriod, which will add another Math.max(100, 4*lookback) candles. For charts you can also set recalculateForAll property in IndicatorInfo. This will force indicator recalculation for all available data set which is usually 2 times bigger than max number of candles on the screen. Also you can try to set bigger lookback


 
 Post subject: Re: "Bars Since" Indicator Post rating: 0   New post Posted: Fri 06 Nov, 2009, 00:21 

User rating: 0
Joined: Wed 21 Oct, 2009, 04:47
Posts: 22
Thanks, I was wondering exactly what 'unstable period' did. Although what happens if you are still unsure whether the lookback will contain the information you need?
The example I can think of is the pivot indicator (discussed here viewtopic.php?f=6&t=1398). Say you wanted the last close price @ Friday 4:00PM NY Time. First, you need to ensure you have data that far back. If you're in a tick timeframe, there's no way of knowing how many bars back this is?


 
 Post subject: Re: "Bars Since" Indicator Post rating: 0   New post Posted: Fri 06 Nov, 2009, 09:09 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Unstable period gives some additional candles to allows indicator to "stabilize". For EMA indicator, it can have different values depending on which candle do you start calculation and comes to one line with time. Here is more info on this - https://ta-lib.org/d_api/ta_setunstableperiod.html

Pivot indicator will be available in next version. To support it we are adding new type of inputs where you can set specific period or even instrument. There will be more info on this when new demo version will be deployed


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com