[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Help needed for AFL Ver2



PureBytes Links

Trading Reference Links

What bar are you talking about? The first bar in the database, the 
first bar of the day or the first bar where a buy condition exists? 

If it is the first bar of the day you could try this:
tod = timenum();
buyprice = iif(tod == 093000, c, 0);

if you want the first bar when buy is true then:
buyprice = iif(buy, c, 0);

or if you are using something that returns a value of c at that instant 
of time, such as an EMA crossing then:
buyprice = iif(buy, emaval, 0); here C may = emaval or be very close.

Remember that AB cycles through your indicator code many times a second 
and remembers nothing of the last pass, so of you want to capture the 
value of C at the first instance then you have to put that value in a 
static variable:

if(lastvalue(buy) { staticvarset("pricevalue", lastvalue(C); } would 
save C at the instant that buy first becomes true.
or lastvalue(of whatever)

The static var will save the value until you reset/change it or until 
AB is closed. As I said AB cycles through your indicator so the next 
time it has a buy the code above would change pricevalue so you have to 
add logic to prevent if from changing until you want it to change. 

If you are using this with real time data note that C is the value of 
the last tick that AB sees and that it can and does change many times a 
second. That C will change with each tick until the bar is complete. 
Then it starts filling the next bar.

Barry

--- In amibroker@xxxxxxxxxxxxxxx, "vishy_sharma" <vishy_sharma@xxx> 
wrote:
>
> Hi,
> If I want to execute a piece of code in my system only on first bar, 
> what should be the conditional statement.
> Also those variables which I have initialized in that block for first 
> bar, will they be present for 2nd bar and so on.
> Do I need to declare those variables global or there is some other 
way.
> 
> regards
> vishal
>




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/