I have the date. what the best way to find barindex using com

i am working on a system using the com. I have the date i just need to locate the barindex,

1 Like

https://www.amibroker.com/guide/afl/lookup.html

1 Like

that for afl look up i need to do it in vb and ole

@nickhere, you might want to check out the lookup function in VB.

Since your question was so generic, and asked in the AB forum, we just assumed you needed help in AmiBroker AFL.

Try searching on some VB forums for more detailed help in what you need to do there.

1 Like

It seems that you don't like to provide too much information...

I suppose that you should define a method to "send" the COM object the DATENUM() array (https://www.amibroker.com/guide/afl/datenum.html).
Then you can calculate with your date value the expression: 10000 * (year - 1900) + 100 * month + day
and search the resulting value in the array received. The bar index is the index of the result in the matrix.

1 Like

@nickhere,

You can use example 2 from this document as a guide:

https://www.amibroker.com/newsletter/01-2000.html

You can get the number of quotes for the selected symbol and retrieve each date/time into an array. Search the array to find a given date/time and the array index should equal the bar number.

1 Like

ok i am redoing my code to avoid the use of VB. I am creating a DLL
I just need a example of how to do it in the dll

assume the date is a string
in this format
05/03/2014
just find me the barnum

The ADK documentation demonstrates how to call an afl function from your plugin (afl plugins only, not data plugins) using gSite.CallFunction.

Here is one way to get what you want:

  1. Parse your date string and calculate the DateNum (10000 * (year - 1900) + 100 * month + day).
  2. Retrieve the DateNum array by calling the afl function from your dll.
  3. Search the array for the DateNum you calculated. The array index is the Bar number.

You will get more help here if you post your dll code with more specific details about what is not working.

1 Like

this is what i have in my dll
I read the date from a external file
let say the date is 05/03/2014 in a string format

how do i call the lookup function
c1=gSite.CallFunction("lookup", 3, arg);

How do i set the args
would this return the barnum for the date

WIth all due respect, you would be far better off if you used just AFL not C++. Writing DLLs in C++ is not recommended for people without earlier C++ exposure. The possibilities of "shooting yourself in a foot" using C++ are 100x greater than in AFL.

Everything can be done in AFL and really you do NOT need DLLs at all.

1 Like

cant do what i want to do in afl. the code mostly in c++. just tell me how to set up the arg from a string date and ticker to get bar num

@fxshrat has provided a detailed example of how to construct the arguments in one of your previous threads:

https://forum.amibroker.com/t/how-do-i-determine-if-a-variable-exist/1117/21

If you want to use the Lookup function you will need to convert your date string to an encoded DateTime. You can use StrToDateTime to accomplish that.

You will also need to retrieve the BarIndex array. Keep in mind that BarIndex may not equal the array item index if QuickAFL is turned on. The Lookup function is also affected by QuickAFL. You can use SetBarsRequired() in your afl to control how many bars are loaded.

BarIndex array, encoded DateTime and mode are the arguments passed to the Lookup function.

3 Likes

Thank you i figure that out i needed a date convert

you know all you had to to was post this
args[0].type = VAR_FLOAT;
args[0].string = "01/11/2011";

AmiVar convertstr = gSite.CallFunction("StrToDateTime", 1, args); //convert to datenum
AmiVar bindex= gSite.CallFunction("BarIndex", 0, 0);


AmiVar args1[3];
args1[0].array = bindex.array;
args1[1].array = convertstr.array;
args1[2].type = VAR_FLOAT;
args1[2].val = 0;
AmiVar mybarnum = gSite.CallFunction("Lookup", 3, args1);

instead of going thru how i need to learn c++ more or how i need to explain more what i was doing

1 Like

Nick, you should really rethink your attitude. Tomasz is not your pal whom you can tell what to do or teach him how he should behave on the forum which he has brought to life. Show some respect to the person who has been developing this software for over 20 years and every day has to deal with requests from dozens of users - among them users who clearly lack good manners...

8 Likes

First C++ development is not in the scope of AmiBroker tech support. Secondly, as I pointed out earlier, as all this can be done (easier) in AFL, so I see no reason to use C++.

The DLL interface is NOT provided for end users. It is provided for plugin vendors who are professional, experienced C++ developers. DLL interface is offered free, documented but comes "as is" and does not come with support.

From time to time I may offer guidance or advice or help if somebody builds a plugin for many people to use (such as data vendor), but still C++ proficiency is a precondition to build DLLs.

PS. The code that you posted contains a number of basic programming errors (such as not initializing all elements of struct/union). This is what I meant that it would be easier for you to use AFL instead of C++. C++ does not check many things and does not do the homework for you and it does not forgive any errors. That is why it is not good choice for end users. If I explained you one error, then immediately after you would face dozens of others. That is not the way to go. C/C++ is difficult for many people and outside the scope of this forum. AFL is infinitely easier for end users and protects you from mistakes in so many ways.

AFL code for what you want to do is easily derived from example given in docs http://www.amibroker.com/f?lookup

InputDate = "2011-04-05";
biatdate = Lookup( BarIndex(), _DT( InputDate ), -1 );
Title = "BarIndex value at (or before) " + InputDate + " is " + biatdate; 
3 Likes

I was hoping to release the code for public use but the attitude and support i get here . make me want to forget about it. the code I wrote is basically a addon to tell you projected price of the underlying in the future. Right now it tell me it has a 95% chance of a stock hittting a 5% target in 60 bars. I use the dll to grab data from the watchlist where the pattern was before. I do respect tomez but not all his opinions. it kind of like people for or against TRUMP,

I am not so much about error checking in the code as getting it to work first. I also go back and improve on it later. (speed and putting in error checks)

also the code is not ready to even go opensource yet to get help from other user.