Indicator Development questions

Indicators coded by community members
Message
Author
soheil
Posts: 3
Joined: Wed Sep 24, 2008 12:29 am

Indicator Development questions

#1 Postby soheil » Mon Jul 20, 2009 11:49 pm

Hi Everyone,
I have three main questions to develop an indicator: :shock:

1- as stated in the indicator manual, there is no need for us to take care of the way application take care of history data, i mean there is no need to write a loop to go through all the bars that the indicator needs to calculate when we first start running the indicator. but how is FT deal with this? does it start from far left and go all the way to the current bar or vice-versa?

2- the "index" variable is used to identify where the current bar is and also can be used to calculate the shift. when the indicator is calculating the history, how can we identify which bar is calculated? in other words, what is the current value of the index when history calculation is happening?

3- i want to get the current bar, then move back in the history for a defined shift value and then search for a value from the shift bar all the way to the current bar, how can i do this?

Thanks a lot for your help here. :?:

User avatar
Tantalus
Posts: 302
Joined: Fri Mar 23, 2007 3:51 pm
Contact:

Re: Indicator Development questions

#2 Postby Tantalus » Tue Jul 21, 2009 1:12 am

soheil wrote:Hi Everyone,
I have three main questions to develop an indicator: :shock:

1- as stated in the indicator manual, there is no need for us to take care of the way application take care of history data, i mean there is no need to write a loop to go through all the bars that the indicator needs to calculate when we first start running the indicator. but how is FT deal with this? does it start from far left and go all the way to the current bar or vice-versa?

Yes, that's it. FT starts with the earliest bar, then each successive bar all the way to the current bar.

2- the "index" variable is used to identify where the current bar is and also can be used to calculate the shift. when the indicator is calculating the history, how can we identify which bar is calculated? in other words, what is the current value of the index when history calculation is happening?

If I understand your question correctly, the 'index' value starts at the value given in the system variable Bars, and decrements at every bar it calculates until it reaches the current bar, which always has the index 0.

3- i want to get the current bar, then move back in the history for a defined shift value and then search for a value from the shift bar all the way to the current bar, how can i do this?


The value of the current bar is found by calling the Close() function ( or Open, Low, High as you desire) with the argument 0. Then use a loop to go from the bar you want to start with and decrement every time through the loop:

for k := 25 downto 0 do
value := Close(k);
Tantalus Research - Developing 21st Century Trading Systems.

dackjaniels
Posts: 151
Joined: Tue Feb 24, 2009 1:03 pm

Re: Indicator Development questions

#3 Postby dackjaniels » Tue Jul 21, 2009 12:04 pm

soheil wrote:Hi Everyone,
I have three main questions to develop an indicator: :shock:

1- as stated in the indicator manual, there is no need for us to take care of the way application take care of history data, i mean there is no need to write a loop to go through all the bars that the indicator needs to calculate when we first start running the indicator. but how is FT deal with this? does it start from far left and go all the way to the current bar or vice-versa?

As Tantalus already said, it starts at the first bar (far left) and works towards the most recent bar (far right).

2- the "index" variable is used to identify where the current bar is and also can be used to calculate the shift. when the indicator is calculating the history, how can we identify which bar is calculated? in other words, what is the current value of the index when history calculation is happening?

Example: A chart has 150 existing bars on it. We add an indicator and the calculate procedure executes on the first bar of the chart. At this point the no of bars is 150 and the index of this first bar is always bars-1, or 150-1 = 149. The next (second) bar has an index of 148, the next 147....and son on until the most recent bar is calculated where the index is 0.

If you had say, some global variable that needed resetting whenever the first bar is calculated (i.e. indicator is added to chart, indicator properties are changed or start button is pressed) you can do so like this:

Code: Select all

if (index = bars-1)
{
(Reset global variable)
{


It is also useful to understand how to identify the number of the bar currently being calculated. For this we can use bars-index. e.g. if we wanted to place a dot over the tenth bar in the chart we could use:


Code: Select all

if (bars-index = 10)
{
(Code to draw dot)
}


3- i want to get the current bar, then move back in the history for a defined shift value and then search for a value from the shift bar all the way to the current bar, how can i do this?

Code: Select all

int definedshiftvalue == 10;
int shiftindex == (index+definedshiftvalue)-1 //so if index is 0, shiftindex will be 9, a range of ten bars including the most recent bar (index 0)

for (i==shiftindex, i>=index , i--)
{
(Code to check values passing i as the index value where required e.g. Close(i)
}


Thanks a lot for your help here. :?:


My C++ syntax may not be 100% correct but you should get the idea.

Steve

soheilpro
Posts: 13
Joined: Mon Mar 23, 2009 12:53 pm

#4 Postby soheilpro » Tue Jul 21, 2009 6:20 pm

Thank you very much for your assistance here. :D


Return to “Indicators”

Who is online

Users browsing this forum: No registered users and 21 guests