[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

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@xxx> 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/