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

[amibroker] Re: Detect new bar



PureBytes Links

Trading Reference Links

It's funny, I was just looking in the feedback database, and Dennis Brown had similar code, except he added the symbol name to the static var, which is nice. See

http://www.amibroker.com/feedback/view_bug.php?bug_id=1729

You need to be a user and have a user id/password for the member's area to view feedback as far as I can tell.
--- In amibroker@xxxxxxxxxxxxxxx, "Gordon" <gordon@xxx> wrote:
>
> Hi All,
> 
> I had posted something about detecting new bars, and sidartha70 responded with some good thoughts. I said I would post the code, so here is the snippet I use to detect that the bar has changed. Please note, for this to work, you want to have the timestamp for a bar correspond with the start and not the end of the bar (a configurable option).
> 
> // -- Prepare to write file. File will contain price information my
> //    order entry app will use to put an order in through NT
> sHdr = "Instrument,TimeStamp,H,L,TradeDirection,LLV4,HHV4,TickSize";
> tInt = Interval(2);
> sFName = "C:\\Documents and Settings\\grose\\My Documents\\NinjaTrader 6.5\\AB-" + Name() + "-" + tInt;
> 
> // -- Detect new bar
> LastDateTimeNum = StaticVarGet("LastDateTimeNum");
> // -- Initialize if necessary
> if (IsEmpty(LastDateTimeNum) OR IsNull(LastDateTimeNum)) 
> {  
>   StaticVarSet("LastDateTimeNum", LastValue(DT));
>   LastTimeNum = StaticVarGet("LastDateTimeNum");
>   fh = fopen(sFName + ".log", "w");
>   if (fh) {
>     fputs(sHdr + "\r\n", fh);
>     fclose(fh);
>   }
>   _TRACE("Initializing LastDateTimeNum: " + WriteVal(LastDateTimeNum, formatDateTime));
> }
> 
> // -- Detect that bar has changed. I limit this code to work only if
> //    using RT database, e.g. eSignal in my case
> if (LastValue(DT) != LastDateTimeNum AND StrFind(GetDatabaseName(), "eSignal") >= 0) 
> {
> 
>   StaticVarSet("LastDateTimeNum", LastValue(DT));
> 
>   // -- Originally, I worked with BarIndex() and could
>   //    get funky results seeming to have to do with 
>   //    timing. The ValueWhen() approach has worked consistently.
>   LastBarOpen = LastValue(ValueWhen(DT==LastDateTimeNum, O));
>   LastBarHigh = LastValue(ValueWhen(DT==LastDateTimeNum, H));
>   LastBarLow = LastValue(ValueWhen(DT==LastDateTimeNum, L));
>   LastBarClose = LastValue(ValueWhen(DT==LastDateTimeNum, C));
>   LastBarLLV4 = LastValue(ValueWhen(DT==LastDateTimeNum, LLV(L, 4)));
>   LastBarHHV4 = LastValue(ValueWhen(DT==LastDateTimeNum, HHV(H, 4)));
>   TradeDir = WriteIf(LastBarClose > LastBarOpen, "long", "short");
>    
>   sLine = Name() + "," + WriteVal(LastDateTimeNum, formatDateTime) + "," + 
>       WriteVal(LastBarHigh) + "," + WriteVal(LastBarLow) + "," + 
>       TradeDir + "," + WriteVal(LastBarLLV4) + "," + WriteVal(LastBarHHV4) + ",.25";
> 
>   fh = fopen(sFName + ".txt", "w");
> 
>   if (fh) {
>     fputs(sHdr + "\r\n", fh);
>     fputs(sLine, fh); 
>     fclose(fh);
>   }
> 
> }
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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

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/