How to initial variable when a new data come in

Found a problem,
Because my system is using an RT-data system,
Initially, the system initializes each variable array.

So every time a new K stick comes in, there is no way to initialize them, causing program execution errors.
What function can be called when the system has a new k-bar data coming in

@junjun I do not understand your question.

Maybe you should post a short code example and comment it to explain what variables are not initialized (or do you want to re-initialize) when a new bar (tick or other) comes from you RT-data source (additionally, let us know what kind of RT feed plugin are you using).

1 Like

Because my program will default to the array initial value is 0 that the value has not been used, but because AB sometimes produces some abnormal initial value like 2.xxxxxe-43 value, so I will add a place where the program starts

For ( i = 0 ; i < barcount ; i++ ) {
Data[i] = 0 ;
}

To set the value in the array to 0

So that I can work in the program

HighPoint[i] = myNumber ;

Later in the program, you can use it

If (HighPoint[i] > 0 ) {
.....
}

Do what I want to do

But since I use RealTime Data, whenever a new bar data arrives, HighPoint[lastbar] > 0 may fail if the program is not re-executed.

My RT feed plugin was written by myself and I currently only use 1 min K intraday because of the speed of 1min K and Amibroker's reaction.

I don't know what is K stick or k-bar data. Besides similarily to Beppe, I also don't understand the point of your two posts. You haven't described the issue clearly enough.

You don't need to use loop for that. Just write Data = 0;

You should definitely read these threads to learn why it is important to properly initialize arrays - not to get some random "garbage" (uninitialized RAM content):

https://www.amibroker.com/guide/h_understandafl.html
https://www.amibroker.com/guide/a_mistakes.html

If AmiBroker's reaction is slow when you use your plugin, then something is definitely wrong with your plugin or your AFL code. You can't blame Amibroker for that, because it is the fastest and lightest technical analysis software on the market.

2 Likes

What I want to ask is that the last K-bar is 9:00.
When a new K-stick comes in with 9:01 data,
The system will execute which function, or the entire afl will be executed again

like MT4/5 they have a function call is ontick() , when a new tick arrivals the function will be call
not entire afl to executed again
2.
If I only use Data = 0 to initialize a variable, how do I distinguish?
Data = 0
Data1 = 0

Data => is an array
Data1 => is a simple variable

I agree with you, AB is indeed the fastest and lightest technical analysis software on the market.

When and how often AFL code is executed:
http://www.amibroker.com/kb/2015/02/03/when-and-how-often-afl-code-is-executed/

How to execute part of the formula only when new bar is added:
http://www.amibroker.com/kb/2015/11/29/how-to-execute-part-of-the-formula-only-when-new-bar-is-added/

You should read about data types in AFL, variables, arrays, accessing array elements using [ ] - subscript operator etc:

https://www.amibroker.com/guide/a_language.html
https://www.amibroker.com/guide/keyword/typeof.html
https://www.amibroker.com/guide/h_understandafl.html

In general it is a little strange for me, that you wrote your own plugin lacking such crucial (and basic) knowledge - about how AFL works. No wonder, that it might not work as you expected.

2 Likes