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

Re: [amibroker] Using timeframeset with looping code



PureBytes Links

Trading Reference Links

Graham,

I think the problem with
   if(C[i]>x[i-1])
Is that the formula finds the highest close in the data and then it just
STAYS there. (Highest close greater than yesterday's previous higher close -
see 3/10/2000 using ^RUT as an example.) The x array gets to 603.81 and just
stays there because we are comparing to the previous stored high and not
comparing today's close with yesterday's close.

I did move your initialization outside of the TimeFrameCompress statement
and I compressed x since the docs say only price arrays are compressed.

Here's my variation of your code with some plot statements added so I could
visualize.

/////////////////////////
numweeks = LastValue( Cum( DayOfWeek() > Ref(DayOfWeek(),1)));
 
x = C; //Moved before TimeFrameSet. This causes fixed values to
//appear instead of Empty values when testing against x[i-1]
 
TimeFrameCompress(x,inWeekly);
//Help says TimeFrameSet only affects price arrays

TimeFrameSet(inWeekly);
 
for(i = 1; i < BarCount; i++)
{
  if(C[i] > C[i-1]) //Using > x[i-1] gives highest high in data
     x[i] = C[i];
  else
     x[i] = x[i-1];
}
 
TimeFrameRestore();
 
xx = TimeFrameExpand( x, inWeekly );
 
Plot(xx,"xx",colorBlue,styleOwnScale); //This is expanded to daily
Plot(C,"Close",colorRed,styleOwnScale);
Plot(TimeFrameExpand(x,inWeekly),"x
expanded",colorBlack,styleOwnScale|styleHistogram);
Plot(x,"x not expanded",colorLightOrange,styleOwnScale|styleArea);
/*Can't Plot x (a weekly array) on a daily chart. I think it gives
bogus results. I don't know what it's plotting, but it
just doesn't seem logical.
*/

GraphXSpace = 10;
 
Filter=1;
AddColumn(C,"close",1.3);
AddColumn(xx,"expanded weekly",1.3);
AddColumn(x,"weekly",1.3);

/////////////////////////
-- 
Terry


From: kaveman perth <kavemanperth@xxxxxxxxx>
Reply-To: amibroker@xxxxxxxxxxxxxxx
Date: Mon, 11 Oct 2004 06:35:19 +0800
To: amibroker@xxxxxxxxxxxxxxx
Subject: Re: [amibroker] Using timeframeset with looping code

I have done a bit more experimenting and sometimes it works others not

this works for 1 to barcount

numweeks = LastValue( Cum( DayOfWeek()>Ref(DayOfWeek(),1) ) );

TimeFrameSet(inWeekly);
//x[BarCount-numweeks-1]=C[BarCount-numweeks-1];
x[0]=C[0];
for(i=1;i<BarCount;i++)
//for(i=BarCount-numweeks;i<BarCount;i++)
{
if(C[i]>C[i-1])
{
x[i]=C[i];
}
else
{
x[i]=x[i-1];
}
}

//{x[i]=C[i];}

TimeFrameRestore();

xx = TimeFrameExpand( x, inWeekly );

Filter=1;
AddColumn(C,"close",1.3);
AddColumn(x,"x",1.3);
AddColumn(xx,"xx",1.3);


but replacing this line it needs the start at numweeks
if(C[i]>x[i-1])




On Sun, 10 Oct 2004 09:18:48 -0600, Terry <magicth@xxxxxxxxxxx> wrote:
> 
> Graham,
> 
> I do this same task and it works OK for me.
> 
> First I do TimeFrameSet(inWeekly) and do some trend calculations.
> Then I save weekly values into arrays.
> Then I do TimeFrameExpand( x, inWeekly, expandPoint) which serves my purpose
> and gives Empty values for all days except Friday.
> Then I loop through those values to determine my weekly trend.
> I really donıt see why youıre gettng empty values since the default
> expansion is expandLast which puts Fridayıs close into every day of the
> week.
> 
> Hereıs that section of code:
> 
> /*   Find Weekly Trend   */
> 
> wc = TimeFrameCompress(C,inWeekly); //Get weekly values
> 
> //Initialize trend 1 = Long, 0 = No change, -1 = Short
> trend = IIf(wc> Ref(wc,-1) AND wc> Ref(wc,-2),1,IIf(wc< Ref(wc,-1) AND wc <
> Ref(wc,-2),-1,0));
> wc = TimeFrameExpand(wc,inWeekly);
> trend = TimeFrameExpand(trend,inWeekly,expandPoint); //Just the last day of
> the week
> wtrend = trend; //Just for visual confirmation
> //Now, if the current week is not over, neutralize the trend status
> //This is necessary as Amibroker thinks the current day is the close of the
> week.
> if (NOT EOW[BarCount-1] AND NOT expiry[BarCount-1]) trend[BarCount-1] = 0;
> 
> /*   Make daily trend signals and Confirm all trend changes   */
> 
> Confirm = False;
> for( i = 3; i < BarCount; i++ )
> { //if no profit by 2nd day, reverse trend
>     if (Confirm[i-2] AND (NDXc[i] - wc[i])*trend[i-1] < 0)
>     {
>          trend[i] = trend[i-1]*-1;
>          Confirm[i] = False;
>     }
>     else
>     { //if no trend change, continue prior trend. If needed Confirm -3 days
> insures we continue whatever was decided above at -2
>          if (Confirm[i-3] OR trend[i] == 0 OR IsNull(trend[i]))
>          {
>               trend[i] = trend[i-1]; //Continue the trend
>               Confirm[i] = False; //Turn confirm signal off
>          }
>          else
>          { //if Trend changed (values of -1 + 1 or 1 + -1) trend value is
> OK as is (from weekly)
>               if (trend[i] + trend[i-1] == 0)
>                    Confirm[i] = True; //Flag the change
>          }
>     }
> }
> 
> --
> Terry
> 
> From: kaveman perth <kavemanperth@xxxxxxxxx>
> Reply-To: amibroker@xxxxxxxxxxxxxxx
> Date: Sun, 10 Oct 2004 18:41:51 +0800
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Using timeframeset with looping code
> 
> I cannot seem to get the timeframeset to work with any code that contains
> loops.
> I want to explore on weekly values for setups, then trade on daily
> values breaking the weekly setups. This is especially important as I
> am trying to backtest for this code. Rather than post a long code that
> would take time to work through I have put together a simple formula
> that will return the highest close, just purely as an example. I can
> get values if I set the AA settings to weekly, but if put to daily I
> get empty cells in the exploration.
> Can someone help me on how to get this to work
> 
> TimeFrameSet(inWeekly);
> x[0]=C[0];
> for(i=1;i<BarCount;i++)
> { if(C[i]>x[i-1])
> { x[i]=C[i];
> }
> else
> { x[i]=x[i-1];
> } }
> TimeFrameRestore();
> 
> xx = TimeFrameExpand( x, inWeekly );
> 
> Filter=1;
> AddColumn(C,"close",1.3);
> AddColumn(x,"x",1.3);
> AddColumn(xx,"xx",1.3);
> 
> --
> Cheers
> Graham
> http://e-wire.net.au/~eb_kavan/
> 
> Check AmiBroker web page at:
> http://www.amibroker.com/
> 
> Check group FAQ at:
> http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> 
> Yahoo! Groups Sponsor
> 
> ADVERTISEMENT
> <http://us.ard.yahoo.com/SIG=12997ege5/M=295196.4901138.6071305.3001176/D=g
> roups/S=1705632198:HM/EXP=1097491313/A=2128215/R=0/SIG=10se96mf6/*http://com
> panion.yahoo.com>
> 
> 
> Yahoo! Groups Links
> * To visit your group on the web, go to:
> * http://groups.yahoo.com/group/amibroker/
> *
> * To unsubscribe from this group, send an email to:
> * amibroker-unsubscribe@xxxxxxxxxxxxxxx
> <mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
> *
> * Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
> <http://docs.yahoo.com/info/terms/> .
> 
> 
> 
> 
> [Non-text portions of this message have been removed]
> 
> 
> Check AmiBroker web page at:
> http://www.amibroker.com/
> 
> Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html
> Yahoo! Groups Links
> 
> 
> 
> 
> 


-- 
Cheers
Graham
http://e-wire.net.au/~eb_kavan/


Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at:
http://groups.yahoo.com/group/amibroker/files/groupfaq.html


Yahoo! Groups Sponsor
 
 ADVERTISEMENT
 <http://us.ard.yahoo.com/SIG=129s20ho9/M=295196.4901138.6071305.3001176/D=g
roups/S=1705632198:HM/EXP=1097534123/A=2128215/R=0/SIG=10se96mf6/*http://com
panion.yahoo.com>  


Yahoo! Groups Links
* To visit your group on the web, go to:
* http://groups.yahoo.com/group/amibroker/
*  
* To unsubscribe from this group, send an email to:
* amibroker-unsubscribe@xxxxxxxxxxxxxxx
<mailto:amibroker-unsubscribe@xxxxxxxxxxxxxxx?subject=Unsubscribe>
*  
* Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> .




------------------------ Yahoo! Groups Sponsor --------------------~--> 
$9.95 domain names from Yahoo!. Register anything.
http://us.click.yahoo.com/J8kdrA/y20IAA/yQLSAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

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

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