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

Re: [amibroker] Re: Intrabar entries



PureBytes Links

Trading Reference Links

Hi Brian,

what you suggested seems to be correct logically but it is a lot of work to 
code and to test it that way.
TimeFrameXXXs and ATR(5) will give you the required result.

If you have a multitimeframe system you have to backtest it in the shorter 
timeframe on the database with the same shorter bar interval. That solves 
the backtesting problem.

Regards,

Y


--------------------------------------------------
From: "brian_z111" <brian_z111@xxxxxxxxx>
Sent: Wednesday, May 27, 2009 12:14 PM
To: <amibroker@xxxxxxxxxxxxxxx>
Subject: [amibroker] Re: Intrabar entries

> Hi Yofa,
>
> I'm not certain about it because I am still doing it 'in me head' bit I 
> think the Timeframe functions will do a better job, than my suggestion, 
> for intraday scanning because it will show the intraday build, as the data 
> comes in, but not so for BackTesting where the compression will crunch 
> everything to the EOD values.
>
> I have had challenges, in the past, with TimeframeSet etc because it also 
> crunches any indicators in use .... in some charts I found that I had to 
> rewrite the RT indicators to make them suitable for compression so it 
> doesn't always work out.
>
> However I still have more to learn about compression so maybe it is easier 
> than I think.
>
> --- In amibroker@xxxxxxxxxxxxxxx, "Yofa" <jtoth100@xxx> wrote:
>>
>> Hi,
>>
>> use TimeFrameSet and TimeFrameRestore to calculate daily data!
>>
>> Y
>>
>> --------------------------------------------------
>> From: "brian_z111" <brian_z111@xxx>
>> Sent: Wednesday, May 27, 2009 6:11 AM
>> To: <amibroker@xxxxxxxxxxxxxxx>
>> Subject: [amibroker] Re: Intrabar entries
>>
>> > Correction.
>> >
>> > Example:
>> >
>> > IF you want ATR for 5 daily bars in 5 min RT -
>> >
>> > - use NewDay to mark the start of each daily bar
>> > - one day == 78 bars (careful with this if days have data missing)
>> > - use HHV(newday) to get the intraday H and L
>> > - find the previous close (close of lastbar before NewDay)
>> > - use ValueWhen to get PrevC, H and L for lookback 'daily' bars
>> > - manually calc the TrueRange for each 'daily bar' (geatest of H - L OR
>> > PrevClose - L OR
>> > PrevClose - H)
>> > - and then average the result from each of the last 5 'days'
>> > - include the current RT build as day 1
>> >
>> >
>> >
>> >
>> > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:
>> >>
>> >> nizar.mahri
>> >>
>> >> Re the previous discussions on this issue ... I think the difficulties 
>> >> of
>> >> comms via the internet contribute more to detracting from an outcome
>> >> rather than the degree of difficulty of the code.
>> >>
>> >>
>> >> I have done a good deal of thinking about the correspondence between
>> >> intraday bars (any reasonable period) and daily  bars ... I haven't
>> >> written much code though as I do most of the tesing in my head.
>> >> So, I do understand your trade quite well.
>> >>
>> >> I am very sorry but I don't think I can write any code examples at the
>> >> moment, however some comments might help you.
>> >>
>> >> From Barry's comments:
>> >>
>> >> Barry is writing an example for AT and I believe it is correct.
>> >> I agree with his definition that we are considering the intraday 
>> >> 'build'
>> >> of the daily bar ... that is what I call it.
>> >> The 'build' changes with time ... if it can only change in one 
>> >> direction
>> >> e.g. Sum(V) I call that a progressive indicator (it uses lookback
>> >> periods.... compare that to a dynamic indicator e.g. an UpBar which is
>> >> contained in a single timeframe.
>> >>
>> >> His objective is to 'latch' the intraday signal, using a StaticVar, so
>> >> that intraday 'bounce' won't produce on again/off again signals for 
>> >> the
>> >> AT engine (or whatever is is called).
>> >>
>> >> I don't autotrade but I guess this is a major consideration in AT
>> >> systems.
>> >>
>> >> He does say that it is not for backtesting.
>> >>
>> >>
>> >>
>> >> For Scanning/BT use:
>> >>
>> >> - IMO you should do this in the RT database of your choice (5 min bars
>> >> etc)
>> >>
>> >> - the intraday timing improves granularity
>> >> - as soon as all your ducks are in a row you have to buy (system 
>> >> rules)
>> >> and AB will only let you into one trade per symbol ... even if one of
>> >> your indicators is dynamic and bounces off again it is too late to 
>> >> pull
>> >> out of the trade (this is the BT equivalent of the AT latched buy
>> >> signal).
>> >> - scanning large numbers of stocks RT may be a problem but since you 
>> >> were
>> >> formerly trading this system EOD it seems a big step to then go to 30 
>> >> sec
>> >> timeframes for a refined intraday entry
>> >> - smaller RT timeframes will give you a more accurate entry with the
>> >> progressive indicators e.g. Open to Close % change but cause 'bounce'
>> >> with your dynamic indicators e.g. UpBar (a 5 min UpBar may disappear 
>> >> into
>> >> a the 'smoothed' 15 min bar.
>> >> - Since your exit is a volatility trailing stop it should be possible 
>> >> to
>> >> translate that into the corresponding RT code.
>> >>
>> >> Looking at your indicators they seem to be a progressive build 
>> >> starting
>> >> from the daily open so your barsince(newday) code should be doing the
>> >> trick for you.... at a guess I would say you are stuck on the idea of
>> >> compressing RT bars into daily bars and somehow seeing it all there 
>> >> but
>> >> there is absolutely no need for that approach.
>> >>
>> >> Example:
>> >>
>> >> IF you want ATR for 5 daily bars in 5 min RT -
>> >> - use NewDay to mark the start of each daily bar
>> >> - one day == 78 bars
>> >> - use HHV(newday) to get the intraday H and L
>> >> - manually calc the TrueRange for each 'daily bar' (geatest of H - L 
>> >> OR
>> >> O - L OR  O - H)
>> >> - and then average the result from each of the last 5 'days'
>> >> - include the current RT build as day 1
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >> --- In amibroker@xxxxxxxxxxxxxxx, "nizar.mahri@" <nizar.mahri@> wrote:
>> >> >
>> >> > Brian.
>> >> >
>> >> > This is what Barry over at the AT board said in response to a 
>> >> > similar
>> >> > request, I think it may be helpful in my case here.
>> >> >
>> >> > One thing you need to realize is that using intraday data as it 
>> >> > comes
>> >> > in reduces the need to use the formula as you have it designed or
>> >> > even the necessity to use smaller time frames. When data comes in
>> >> > Close is the last tick value. We usually think of close as the price
>> >> > at the end of the bar. But when intraday data is building a bar the
>> >> > last tick is the close and when the next one comes in that is the
>> >> > close, etc., until the end of the bar. Then it is set in concrete.
>> >> > The fist tick to come in is the open. The highest and lowest are the
>> >> > high and low tick so far. The next tick may be higher or lower. Just
>> >> > stop and think about that for a minute. It tool a while before it 
>> >> > got
>> >> > past all my white hair.
>> >> >
>> >> > I am assuming again but I think you intend to use this in auto
>> >> > trading mode. If so you are looking for the first tick that meets or
>> >> > exceeds your entry price. Then you need to change the formula to:
>> >> >
>> >> > LastC = LastValue(c);
>> >> > // when your set up is reached set BuySetup True
>> >> > BuySetup = Ref(Open,0) < EntryPrice AND LastC > EntryPrice;
>> >> > // if buySetup is true save your target price
>> >> > if(LastValue(BuySetup))
>> >> > StaticVarSet("BuyTarget", LastC + yourStopDelta);
>> >> > // when C >= to your target price you send a buy order
>> >> > Buy = LastC >= StaticVarGet("BuyTarget");
>> >> > // set the buy value when you sent the order
>> >> > BuyPrice = iif(buy, LastC, 0);
>> >> >
>> >> > Using a static var will save the setup condition because the next
>> >> > tick may make the condition false and you could miss the trade or 
>> >> > set
>> >> > the trade at a later time. Setting it in a static will eliminate the
>> >> > need to use shorter time frames to see the condition. High might 
>> >> > work
>> >> > here but I think AFL will wait until the end of the bar to act on > 
>> >> > H
>> >> > logic. Using static vars will allow you to send the order mid bar,
>> >> > which is what I think you want to do.
>> >> >
>> >> > Set BuyPrice to the last C because you want to catch the actual 
>> >> > value
>> >> > where the trade was triggered and transmitted to TWS.
>> >> >
>> >> > The rub to what I just wrote is that it will not back test. But in 
>> >> > my
>> >> > opinion back testing is a waste of time once you have your design
>> >> > completed, optimized and back tested on static out of sample blocks
>> >> > of data. If you want to back test this and get really close to 
>> >> > actual
>> >> > trade value create a new database for tick data. You can run two
>> >> > instances of AB, one for tick data and another instance for minute
>> >> > data. I do this often to capture data to use in BarReplay, which is
>> >> > an awesome place to do debugging. I use 5 second data rather than
>> >> > tick data. I think IB only sends tick data three times a second so 5
>> >> > second data may be more accurate.
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > --- In amibroker@xxxxxxxxxxxxxxx, "nizar.mahri@" <nizar.mahri@> 
>> >> > wrote:
>> >> > >
>> >> > > Hi Brian,
>> >> > >
>> >> > > Let me explain further.
>> >> > >
>> >> > > What Im looking to do is trade high volume breakouts.
>> >> > > So the entry is just a mix of HHV, %increase, UpBar, Increase in
>> >> > > volume, and sufficient liquidity.
>> >> > > So if previous bar criteria meets the above, i buy on the next bar
>> >> > > open. I have backtested this using Daily bars.
>> >> > >
>> >> > > Though the strategy is profitable, on the majority of occassions, 
>> >> > > a
>> >> > > considerable chunk of the move happens in that first bar (between 
>> >> > > the
>> >> > > initial breakout maybe and the close ie. in the first few hours)
>> >> > >
>> >> > > So what Im trying to do here is, instead of waiting for the close,
>> >> > > and entering tomorrow, I want to buy AS SOON AS the current bar
>> >> > > (daily) meets the requirements for %change, liquidity, volume, 
>> >> > > HHV,
>> >> > > etc. ie. Mid-bar.
>> >> > >
>> >> > > So ideally I would want to auto-run an exploration every
>> >> > > 30-60seconds, for example, and each time the scan catches a stock 
>> >> > > in
>> >> > > which todays bar, treating the LAST price as the close, meets my
>> >> > > criteria, then I enter right then and there, or as soon as
>> >> > > practicable.
>> >> > >
>> >> > > Hope that makes it clearer.
>> >> > >
>> >> > > Thanks.
>> >> > >
>> >> > > Nizar.
>> >> > >
>> >> > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> 
>> >> > > wrote:
>> >> > > >
>> >> > > > >snip< you can only access H and L bars dailybars from intraday.
>> >> > > > >You cannot access any of the daily indicators intraday in your
>> >> > > > >backtesting.>snip<
>> >> > > >
>> >> > > > I think it can be done (subject to the actual problem because 
>> >> > > > some
>> >> > > > case studies might exceed my capabilities).
>> >> > > > I didn't post any example code because I am in the middle of 
>> >> > > > some
>> >> > > > theoretical work on PowerFactor (will post to the Zboard if it
>> >> > > > works out) and also because, in your prev posts you didn't
>> >> > > > stipulate which indicator you wanted to use to get in and out 
>> >> > > > using
>> >> > > > RT bars (possibly you can't say because it will reveal too much
>> >> > > > about your system ... which is understandable).
>> >> > > >
>> >> > > > Example:
>> >> > > >
>> >> > > > EOD strategy = Buy on Close and Sell on Close the next day (1 
>> >> > > > bar);
>> >> > > >
>> >> > > > In RT the same strategy can be applied by:
>> >> > > >
>> >> > > > RT EOD trade equivalent = Buy on Close (last intraday bar) and 
>> >> > > > Sell
>> >> > > > on Close (entry bar + 78 bars);
>> >> > > >
>> >> > > > Isn't it the same thing, expressed in different timeframes 
>> >> > > > (without
>> >> > > > tricky timeframe compression ... well tricky for me anyway).
>> >> > > >
>> >> > > > I always consider that macrobars e.g. weekly, are an 
>> >> > > > approximation
>> >> > > > of the corresponding microbars e.g. daily.
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > >
>> >> > > > --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
>> >> > > > >
>> >> > > > > let me know when you find a way to do it. check my earlier 
>> >> > > > > posts
>> >> > > > > on the same issue.
>> >> > > > > you can only access H and L bars dailybars from intraday. You
>> >> > > > > cannot access any of the daily indicators intraday in your
>> >> > > > > backtesting.
>> >> > > > >
>> >> > > > >
>> >> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "nizar.mahri@" 
>> >> > > > > <nizar.mahri@>
>> >> > > > > wrote:
>> >> > > > > >
>> >> > > > > > Hi,
>> >> > > > > >
>> >> > > > > > I currently have my system set up as below.
>> >> > > > > > The way its set up is as an EOD system.
>> >> > > > > >
>> >> > > > > > Now I want to modify it to have intraday entries.
>> >> > > > > > So as soon as todays bar meets the system entry criteria (in
>> >> > > > > > terms of price% change, volume, and liquidity) then enter
>> >> > > > > > immediately (ie. don't wait for the close).
>> >> > > > > >
>> >> > > > > > How would i do that?
>> >> > > > > >
>> >> > > > > > Thanks.
>> >> > > > > >
>> >> > > > > > Nizar.
>> >> > > > > >
>> >> > > > > > settradedelays( 1, 1, 1, 1 );
>> >> > > > > >
>> >> > > > > > LBP = Param("ATR Look Back", 10, 5, 50, 1);;
>> >> > > > > > Multi = Param("ATR Multiple", 2, 1, 5, 0.1);;
>> >> > > > > > Pr = Close;
>> >> > > > > > AT = ATR(LBP);
>> >> > > > > >
>> >> > > > > > Entry1 = Indicator1;
>> >> > > > > > Entry2 = Indicator2;
>> >> > > > > > Entry3 = Indicator3;
>> >> > > > > > Entry4 = Indicator4;
>> >> > > > > > Entry5 = Indicator5;
>> >> > > > > >
>> >> > > > > > Buy = Entry1 && Entry2 && Entry3 && Entry4 && Entry5;
>> >> > > > > > BuyPrice = Open;
>> >> > > > > > trailARRAY = Null;
>> >> > > > > > trailstop = 0;
>> >> > > > > > Longtriggerbar = 0;
>> >> > > > > >
>> >> > > > > > for( i = 1; i < BarCount; i++ )
>> >> > > > > > {
>> >> > > > > >
>> >> > > > > > if( trailstop == 0 AND Buy[ i ] )
>> >> > > > > > {
>> >> > > > > > trailstop = Pr[ i ] - Multi * AT[i];
>> >> > > > > > Longtriggerbar = i;
>> >> > > > > > }
>> >> > > > > > else Buy[ i ] = 0; // remove excess buy signals
>> >> > > > > >
>> >> > > > > > if( trailstop > 0 AND Low[ i ] < trailstop  and i !=
>> >> > > > > > Longtriggerbar)
>> >> > > > > > {
>> >> > > > > > Sell[ i ] = 1;
>> >> > > > > > SellPrice[ i ] = trailstop;
>> >> > > > > > trailstop = 0;
>> >> > > > > > }
>> >> > > > > >
>> >> > > > > > if( trailstop > 0 )
>> >> > > > > > {
>> >> > > > > > trailstop = Max( Pr[ i ] - Multi * AT [i], trailstop );
>> >> > > > > > trailARRAY[ i ] = trailstop;
>> >> > > > > > }
>> >> > > > > >
>> >> > > > > > }
>> >> > > > > >
>> >> > > > > >
>> >> > > > > > Plot( Close,"Price",colorBlack,styleBar);
>> >> > > > > > Plot( trailARRAY,"trailing stop level", colorRed );
>> >> > > > > >
>> >> > > > > > // Rank trades according to ATR if insufficient capital
>> >> > > > > >
>> >> > > > > > PositionScore = 100-ATR(10);
>> >> > > > > >
>> >> > > > > > // Divide capital into 4 positions
>> >> > > > > > // Plot equity chart
>> >> > > > > >
>> >> > > > > > NumPos = 4;
>> >> > > > > > SetOption("MaxOpenPositions",NumPos);
>> >> > > > > > PositionSize = -100/NumPos;
>> >> > > > > >
>> >> > > > > > Plot(C,"C",colorBlack,styleCandle);
>> >> > > > > > e = Equity();
>> >> > > > > > Plot(e,"Equity",colorGreen,styleLine | styleOwnScale);
>> >> > > > > >
>> >> > > > >
>> >> > > >
>> >> > >
>> >> >
>> >>
>> >
>> >
>> >
>> >
>> > ------------------------------------
>> >
>> > **** 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
>> >
>> >
>> >
>> >
>>
>
>
>
>
> ------------------------------------
>
> **** 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
>
>
>
> 


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

**** 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/