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

[amibroker] Re: find today's dailybar high and low from intraday bar-> Pl help



PureBytes Links

Trading Reference Links

your point B is correct.

The actual root cause of the problem that i am trying to solve is a limitation that exists in AFL.
At this point only the HLC values can be correctly transulated from higher to lower timeframes without looking into future. I want to be able to calculate the indicator values without looking into future even if it means manually calculating the indicator values.

Lets try a simple use case

Buy when CCI() - Ref(CCI()) >14
when i forward test it, i would get the signal intraday.
In attached screenshot, get it exactly @ 2.50
 http://screencast.com/t/YvvOFGexvea

backtesting this one will give me the buy signal @ 9.30 because timeframe changes in AFL looks into the future.

Ticker  Trade   Date    Close
AAPL    Short   22/09/2008 15:55        130.83
AAPL    Short   23/09/2008 9:30 132.15
AAPL    Short   23/09/2008 9:35 132.51

What i am attempting to do is to figure out a way to avoid looking into the future because it is not possible in the real market to do so.

Additinal issue with this prob is that i could have several cases where the CCI difference>14  would have triggered during intraday and then reversed later during the day. In the current AFL process, i would not be considering those signals resulting in mismatches between the real life scenarios and testing scenarios.

The code i used is below.



 TimeFrameSet( inDaily) ;
 
 CCIval=CCI(14);
 CCIValYesterday=Ref(CCIVal,-1);
 CCIDiff=((CCIval-Ref(CCIval,-1)));
 Short_signal=CCIDiff<-15;
 TimeFrameRestore();
 
 Filter=Short=TimeFrameExpand(Short_signal,inDaily,expandLast);
 
 CCIVal_Expanded=TimeFrameExpand(CCIval,inDaily,expandLast);
 CCIDiff_Expanded=TimeFrameExpand(CCIDiff,inDaily,expandLast);
 CCIValYesterday_Expanded=TimeFrameExpand(CCIValYesterday,inDaily,expandLast);
 
 AddColumn(CCIVal_Expanded,"CCIVal_Expanded",1.5);
 AddColumn(CCIDiff_Expanded,"CCIDiff_Expanded",1.5);
 AddColumn(CCIValYesterday_Expanded,"CCIVal_Expanded",1.5);


If i am going to use this as a strategy to backtest, 
--- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@xxx> wrote:
>
> Seede,
> 
> I don't think I can go any further with this.
> 
> In any case it is still not clear to me:
> 
> a) What you want to use for your RT indicator - CCI(14) OR some version of CustomisedCCI.
> 
> b) Once you have your RT indicator what you expect to see in daily bars - CCI is an overbought/oversold oscillator so how would that translate from RT into a daily report (bar) - perhaps you want to see it as a daily bar as the day progresses (OHLC of the CCI)?
> 
> I am sorry but I can't come to an understanding of exactly what you want in that regard.
> 
> 
> > > I have AAPL on the bar replay running 5 minute step on daily chart. i am
> outputting the HLC and CCI values to file so i know how the cci was evolving
> during the day.
> > > I now compared the results with the custom cci value formula that i derived
> it with your earlier post using 5 minute timeframe filter. you can see the
> results that the daily HLC values matched but not the cci values
> > > left hand side is the file output from the barreplay. RHS is the result from
> analysis window.
> 
> I have never used BarReplay or CCI but my understanding is that the HLC values match because in daily view they are gathered from the intraday range while CCI(14) is looking back 14 daily periods.
> 
> IMO you need to clarify these points before anyone can help you.
> 
> I apologize for not being able to do more, or better.
> 
> brian_z
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
> >
> > Hi Brian
> > I use DTN IQ as sevice provider but my market hours are set to 9:30 to 3.55 on 5 minute bars. so i dont worry about pre and post market data.
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:
> > >
> > > Seede,
> > > 
> > > Well, at least we are making some progress (we seem to have isolated the problem)?
> > > 
> > > Thanks for the effort and detail you put into your response ... that certainly makes it easier for people to help.
> > > 
> > > I can't dig in right now but I will go over it at some stage, if the challenge isn't meet successfully before then.
> > > 
> > > I haven't run any code, or anything like that, but off the top of my head I would have thought that the periods are dynamic so you need to use periods = barssince(NewDay); instead of a static number i.e. 14.
> > > 
> > > I also expect out of hours bars to cause trouble with this kind of 'indicator' used in this way (with RT).
> > > 
> > > To confirm:
> > > 
> > > - who is your data provider (I have eS and can get AAPL current 5 min if I need to matchup to you)?
> > > - your data must have out of hours bars (especially if it is AAPL or any other US major?
> > > - for, say, the US market (AAPL) .... when do you want to start, and end, your intraday .... 1630 hr previous day, midnight, 0930 etc?
> > > - say you want the CCI intraday build to work in market hours only then you want it to start with bar 0930 + bar 0935 and then progress from there 0930 + 0935 + 0940 -----> 1600 hours?
> > > 
> > > 
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
> > > >
> > > > Brian
> > > > Thanks for your input. Let me throw more light on the prob by giving an example.
> > > > 
> > > > I have AAPL on the bar replay running 5 minute step on daily chart. i am outputting the HLC and CCI values to file so i know how the cci was evolving during the day.
> > > > I now compared the results with the custom cci value formula that i derived it with your earlier post using 5 minute timeframe filter. you can see the results that the daily HLC values matched but not the cci values
> > > > left hand side is the file output from the barreplay. RHS is the result from analysis window.
> > > >  http://screencast.com/t/21WjjMiT
> > > > 
> > > > IMHO: A true backtesting process should use the actual prices as possible.
> > > > I just dont know what to do.
> > > > 
> > > > The code used:
> > > > 
> > > > Analysis:
> > > > 
> > > > 
> > > > newday= Day()!=Ref(Day(),-1);
> > > > 
> > > > highestofday=HighestSince(newday,H,1);
> > > > LowestOfDay=LowestSince(newday,L,1);
> > > > 
> > > > 
> > > > Typical = (highestofday + LowestOfDay + Close)/3;  //use the current close
> > > > SMATP=MA(typical,14);
> > > > meanDeviation=0;
> > > > for(i=-1;i>-14;i--){
> > > > meanDeviation += abs(SMATP-Ref(Typical,i));
> > > > }
> > > > 
> > > > 
> > > > CustomCCI=(Typical-SMATP)/(.015*meanDeviation);
> > > > 
> > > > AddColumn(highestofday,"highestofdayarray");
> > > > AddColumn(LowestOfDay,"LowestOfDayarray");
> > > > AddColumn(C,"currentclose");
> > > > AddColumn(CustomCCI,"CustomCCI");
> > > > 
> > > >  
> > > >   
> > > > Filter=True;
> > > > 
> > > > barreplaycode
> > > > write2file = ParamToggle( "Write 2 file ", "false|True", 0 );
> > > > 
> > > > if ( write2file )
> > > > {
> > > >     pt = GetPlaybackDateTime(); // new function to retrieve playback position date/time,
> > > > //returns zero if bar replay is NOT active
> > > > 
> > > >     if ( pt )
> > > >     {
> > > >         pt = DateTimeToStr( pt );
> > > >     }
> > > >     else
> > > >     {
> > > >         pt = "";
> > > >     }
> > > > 
> > > > 
> > > > 
> > > >     string2write = pt + StrFormat( "Interval %6.0f,high %3.2f , low %3.2f,close %3.2f, CCI %3.4f\n", Interval(), LastValue( H ), LastValue( L ), LastValue( C ), LastValue( CCI( 14 ) ) );
> > > > 
> > > >     if ( StaticVarGetText( "prevwrite" ) !=  string2write )
> > > >     {
> > > > // prevent duplicte lines becauase the write processis faster than barreplay.
> > > > 
> > > >         // string2write ="Interval=" +   Interval() +  "Date" + NumToStr(LastValue( DateNum() ),8,False) + " Time" + LastValue( TimeNum() )   +  "CCI=" + LastValue( CCI( 14 ) + "/n" ) ;
> > > >         fh = fopen( "c:\\temp\\myfile.txt", "a" );
> > > > 
> > > >         if ( fh )
> > > >         {
> > > >             fputs( string2write, fh );
> > > >             fclose( fh );
> > > >             StaticVarSetText( "prevwrite", string2write );
> > > >         }
> > > >         else
> > > >         {
> > > >             _TRACE( "cannot open file" );
> > > >         }
> > > > 
> > > >     }
> > > > 
> > > > 
> > > > 
> > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:
> > > > >
> > > > > If that is what you want to do then I think that the following is the easy way to do that:
> > > > > 
> > > > > Periods = BarsSince(NewDay);
> > > > > YourIndicator = CCI(Periods);
> > > > > 
> > > > > OR maybe something along these lines will work:
> > > > > 
> > > > > Newday = TimeNum() >= 093000;//assumes market normal trading hours starts at 0930.
> > > > > 
> > > > > Periods = BarsSince(NewDay);
> > > > > YourIndicator = CCI(Periods);
> > > > > 
> > > > > This is for RT charts ... you might have to make it a condition that the first two bars have been built, in RT, because deviation from the mean, for one bar, will be zero which might crash the maths at the start of the (intra) day.
> > > > > 
> > > > > Compression only comes into it if you want to see the intraday CCI build in daily view.
> > > > > 
> > > > > 
> > > > > Here is a link with a reasonable explanation of CCI and an Excel example for anyone who is interested.
> > > > > 
> > > > > http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:commodity_channel_index_cci
> > > > > 
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:
> > > > > >
> > > > > > I am finding it difficult to respond because your logic doesn't match what you are trying to do (unless I am misunderstanding what it is that you are aiming for).
> > > > > > 
> > > > > > > basically, i cam trying to get the Daily CCI value as it evolves >during the intraday chart.
> > > > > > 
> > > > > > To achieve this:
> > > > > > 
> > > > > > 1) (use the code as suggested by Rajiv, or similar)
> > > > > > 
> > > > > > 
> > > > > > newday= day()!=ref(day(),-1);
> > > > > > highestoftheday=highestsince(newday,H,1);
> > > > > > 
> > > > > > 2) do the same for the low
> > > > > > 3) Calculate the progressive intraday typical value
> > > > > > 
> > > > > > Typical =  (highestoftheday + lowestoftheday + close)/3;//use the current close
> > > > > > 
> > > > > > 4) manually calculate CCI using the steps outlined in the AB helpmanual/indicators/CCI notes -
> > > > > > 
> > > > > > - calculate MA(typical)
> > > > > > - calculate deviation from mean typical value
> > > > > > - * 0.15
> > > > > > - divide relevant steps above
> > > > > > 
> > > > > > Bingo!
> > > > > > 
> > > > > > If your RT data contains out of hour trades you might need to add a caveat to exclude bars with after hours timestamps.
> > > > > > 
> > > > > > Is that what you want to do?
> > > > > > 
> > > > > > If you are trying to do something else I am sorry but I can't understand what it is from your statements.
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
> > > > > > >
> > > > > > > I am in desperate need of some help here. i dont want to think that it is impossible.
> > > > > > > 
> > > > > > > basically, i cam trying to get the Daily CCI value as it evolves during the intraday chart.
> > > > > > > 
> > > > > > > my attempt is below.
> > > > > > > 
> > > > > > > So i came up with the idea that i can build the daily cci values using run time
> > > > > > > values from intraday. i can build it using
> > > > > > > CCIa formula
> > > > > > > 
> > > > > > > TimeFrameSet( inDaily ); // switch to 5 minute frame
> > > > > > > Typical=(C+H+L)/3;
> > > > > > > 
> > > > > > > TimeFrameRestore();
> > > > > > > 
> > > > > > > realtimecci=CCIa( Typical, 14 );
> > > > > > > here i did not expand the Typical to 5 minute bars and so the array has the
> > > > > > > daily bars values.
> > > > > > > 
> > > > > > > As long as i can update the last bar with the intraday =(C+H+L)/3 i will keep
> > > > > > > getting realtime CCI daily values as the bar progresses for backtesting.
> > > > > > > 
> > > > > > > Hope this explains why i am looking for the HLC values as a number as i need to
> > > > > > > use it as a number
> > > > > > > 
> > > > > > > 
> > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
> > > > > > > >
> > > > > > > > In the case you have shown, the valuewhen returns an array. i want the actual low value as a number.
> > > > > > > > 
> > > > > > > > The background behind this is that i am trying to plot the daily CCI value as the bar progresses during the day while backtesting. For a true backtesting of the strategy, i need to know the values of the indicators as the bar progresses over time. there is not way that i can get it automaticlaly with ab.
> > > > > > > > 
> > > > > > > > Accoring to AB support
> > > > > > > >  If you want to calculate "what daily CCI would be on each of the intraday  bars" - then you can't use TimeFrame functions for that, as they return EOD  values of the OHLC arrays (of course daily Open is known since the start of  the day).  So you would need to calculate such indiators in some form of a FOR loop (or perhaps 2 nested loops). Unfortunatelly I don't have any ready-to-use  example of such code I could share and writing such fomrula on demand from  scratch exceeds the range of free support we are able to offer (see: http://www.amibroker.com/freesupport.html).
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > after breaking my head over it for more than weeks, here is my almost completed code except for a small bit.
> > > > > > > > 
> > > > > > > > use CCIa to do the cci formula and pass in a array with daily prices. so i get the daily price from timeframeset and do not expand it so that i will have the daily price arrays.
> > > > > > > > my idea is to change the last value of the daily array with the current HLC values from daily bar.
> > > > > > > > 
> > > > > > > > So i came up with the idea that i can build the daily cci values using run time values from intraday. i can build it using 
> > > > > > > > CCIa formula
> > > > > > > > 
> > > > > > > > TimeFrameSet( inDaily ); // switch to 5 minute frame 
> > > > > > > > Typical=(C+H+L)/3;
> > > > > > > > 
> > > > > > > > TimeFrameRestore();
> > > > > > > > 
> > > > > > > > realtimecci=CCIa( Typical, 14 ); 
> > > > > > > > here i did not expand the Typical to 5 minute bars and so the array has the daily bars values. 
> > > > > > > > 
> > > > > > > > As long as i can update the last bar with the intraday =(C+H+L)/3 i will keep getting realtime CCI daily values as the bar progresses for backtesting.
> > > > > > > > 
> > > > > > > > Hope this explains why i am looking for the HLC values as a number as i need to use it as a number
> > > > > > > > 
> > > > > > > > 
> > > > > > > >  
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "brian_z111" <brian_z111@> wrote:
> > > > > > > > >
> > > > > > > > > Hi Seede,
> > > > > > > > > 
> > > > > > > > > Does this help.
> > > > > > > > > 
> > > > > > > > > (I think you can substitute the High or Low, or any required bar specific value, for TimeNum())
> > > > > > > > > 
> > > > > > > > > //AA Settings should be on an intraday timeframe e.g. 5 min
> > > > > > > > > //Run the scan then use X_ATC_IntradayHLL to report on the data
> > > > > > > > > //and export it to a spreadsheet for graphing
> > > > > > > > > 
> > > > > > > > > Buy = Sell = 0;
> > > > > > > > > 
> > > > > > > > > Sym = Name();
> > > > > > > > > 
> > > > > > > > > DL = TimeFrameGetPrice( "L",inDaily,0);
> > > > > > > > > BSL = BarsSince(L == DL);
> > > > > > > > > ILT = ValueWhen(BSL == 0, TimeNum()/10000,1);
> > > > > > > > > 
> > > > > > > > > I uded it at the Zboard and the full code is downloadable via file links there.
> > > > > > > > > 
> > > > > > > > > http://zboard.wordpress.com/2009/03/02/342/
> > > > > > > > > 
> > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
> > > > > > > > > >
> > > > > > > > > > An additional question. the highestoftheday returns a array. i want to get the specific value of the highestoftheday. i tried lastvalue but it was returning the values incorectly. 
> > > > > > > > > > appreciate any additional help.
> > > > > > > > > > Seede
> > > > > > > > > > 
> > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "murthysuresh" <money@> wrote:
> > > > > > > > > > >
> > > > > > > > > > > thanks a lot. u are a genius.
> > > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, Rajiv Arya <rajivarya87@> wrote:
> > > > > > > > > > > >
> > > > > > > > > > > > 
> > > > > > > > > > > > newday= day()!=ref(day(),-1);
> > > > > > > > > > > > 
> > > > > > > > > > > > highestoftheday=highestsince(newday,H,1);
> > > > > > > > > > > > 
> > > > > > > > > > > >  
> > > > > > > > > > > > 
> > > > > > > > > > > > Rajiv
> > > > > > > > > > > >  
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > To: amibroker@xxxxxxxxxxxxxxx
> > > > > > > > > > > > From: money@
> > > > > > > > > > > > Date: Thu, 21 May 2009 12:48:34 +0000
> > > > > > > > > > > > Subject: [amibroker] Re: find today's dailybar high and low from intraday bar
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > As per the docs below , it will give the last bar of the range in the AA window. I am looking for the highest high of the day from the intraday bars as the bar progreses.
> > > > > > > > > > > > 
> > > > > > > > > > > > http://www.amibroker.com/guide/afl/afl_view.php?name=SELECTEDVALUE
> > > > > > > > > > > > 
> > > > > > > > > > > > --- In amibroker@xxxxxxxxxxxxxxx, "jorgen_wallgren" <jorgen.wallgren@> wrote:
> > > > > > > > > > > > >
> > > > > > > > > > > > > I am relatively new at this, but shouldn't this give you what you want:
> > > > > > > > > > > > > 
> > > > > > > > > > > > > H0 = SelectedValue(TimeFrameGetPrice("H", inDaily, 0));
> > > > > > > > > > > > > L0 = SelectedValue(TimeFrameGetPrice("L", inDaily, 0));
> > > > > > > > > > > > > 
> > > > > > > > > > > > > Regards,
> > > > > > > > > > > > > 
> > > > > > > > > > > > > Jorgen
> > > > > > > > > > > > >
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > _________________________________________________________________
> > > > > > > > > > > > Insert movie times and more without leaving Hotmail®.
> > > > > > > > > > > > http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd1_052009
> > > > > > > > > > > >
> > > > > > > > > > >
> > > > > > > > > >
> > > > > > > > >
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>




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

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