first bar in a Indicator

 

Hello,


can anybody tell me how to find the first Bar of a indicator?

I want to calculate a the first value in a specific way, and afterwards calculate every new indicator value an basis of the previous.


thank you for help

 

Hello rinc

I may be not understanding your question but...

A chart has historic value sets (OHLCVT). The number of these available to your program is known by the identifier Bars.

Bars-1 is the oldest accessable value set and 0 is the newest currently forming with incoming data tics.

Given above, Bars-1 will have a different value when currently forming bar is complete (Time[0] changes) since there is one more 'Bar' in the historic range but the use of [Bars-1] will still map the oldest value set.

hth

 

thank you fbj,


I know the identifier Bars, but it does not realy help:

I am coding a indicator and only for the first bar i want to do a special calculation AND this calculation may only be done once in the whole programm!


int start()                         // Special function start()
{
int i, // Bar index
Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
if(/*it is the first bar in the chart*/)
{
//this instruction may only be done ONCE!
//do something e.g.
Buf_0[i] = 2;
}
else
{
//do another thing e.g.
Buf_0[i]=Buf_0[i+1] + 0.01;
}
i--; // Calculating index of the next bar
}
//--------------------------------------------------------------------
return; // Exit the special funct. start()
}
 

rinc

Well, again - I'm still confused. Please be specific. English is confusing at best.

.

many permutations to achieve whatever it is you want by use of boolean's with global or local scope or even init() can be employed, so many diff ways are there to use.

.

1. "I want to calculate a the first value in a specific way, and afterwards calculate every new indicator value an basis of the previous"

Once per start() entry?

a. at top of start() declare local scoped boolean flag and initialize to false: where required, test flag -> if false: set flag true; do once only stuff

next time start() entered, above repeats,...

.

2. "I am coding a indicator and only for the first bar i want to do a special calculation AND this calculation may only be done once in the whole programm!"

Once/first iteration of while loop?

a. in start() above while loop: declare local scoped boolean flag and initialize to false: inside while loop, at top test flag -> if false: set flag true; do once only stuff and following iterations will be executed due to test for false failing... ie, else {..} runs.

next time start() entered, above repeats,...

.

Once per program run?

ie, once only when indicator attached to chart.

a. use init() -> do once only stuff, or

b. declare source file global scoped boolean flag and initialize to false -> in start():test flag -> if false: set flag true; do once only stuff

above not repeated until indicator removed,recompiled etc. Basically not repeated until indicator static memory is reset to compile time values.

.

if any of above still not what you after then you must invent another way to cleary describe what you want to do, suggest pseudo english text

otherwise some other person that understand what you want might help.

 
rinc:

int start()                         // Special function start()
{
int i, // Bar index
Counted_bars; // Number of counted bars
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=Bars-Counted_bars-1; // Index of the first uncounted
while(i>=0) // Loop for uncounted bars
{
if(i==
Bars-Counted_bars-1)
{
//this instruction may only be done ONCE!
//do something e.g.
Buf_0[i] = 2;
}
else
{
//do another thing e.g.
Buf_0[i]=Buf_0[i+1] + 0.01;
}
i--; // Calculating index of the next bar
}
//--------------------------------------------------------------------
return; // Exit the special funct. start()
}

I think you want this maybe, possibly, perhaps.

Reason: