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

[amibroker] Re: Projecting prices


  • Date: Fri, 26 Feb 2010 14:54:05 -0000
  • From: "mbausys" <mbausys@xxxxxxxxx>
  • Subject: [amibroker] Re: Projecting prices

PureBytes Links

Trading Reference Links

Mike,

This works fine in exploration, however the code does not allow for system backtest. Any hints how it could be adjusted?


Thanks,

Marius

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> See if this helps:
> 
> http://finance.groups.yahoo.com/group/amibroker/message/125149
> 
> Mike
> 
> --- In amibroker@xxxxxxxxxxxxxxx, "mbausys" <mbausys@> wrote:
> >
> > So is there anyone who could help with this issue?
> > Obviously, an alternative solution is to use open prices for Bollinger Bands instead of Closing, but that's not a perfect answer...
> > 
> > 
> > --- In amibroker@xxxxxxxxxxxxxxx, "mbausys" <mbausys@> wrote:
> > >
> > > Hi all,
> > > 
> > > I'll try to clarify a couple of points:
> > > 1. The general idea is to trade Bollinger Bands. For simplicity, let take only long side. I would enter a trade intraday if the price drops below nine day bottom Bollinger Band ( BBandBot( C, 9, 2 ) ).
> > > 
> > > 2. My purpose is to backtest this simple trading system. The problem is that I can't set buy condition as
> > > Buy = L < BBandBot( C, 9, 2 )
> > > because the band moves intraday and the actual signal might have not occurred intraday although it would be generated by this trading rule. For instance, if the EOD low only touches EOD BBandBot( C, 9, 2), then it means that when the price was at low intraday, the band was definitely lower and I wouldn't have got a trading signal and hence wouldn't have entered the trade.
> > > 
> > > 3. In order to solve this problem, I need to find a price level at which the signal would actually be generated intraday. Then that level would be used as Buyprice. I've worked on this issue and come up with a solution, which works fine, however it's extremely slow and there should definitely be a way for simplifying this.
> > > 
> > > P = C; // P = my target price level
> > > BBB = BBandBot( P, 9, 2 );
> > > MAV = MA( P, 9 ); // MAV just stand for moving average
> > > for( i = 8; i < BarCount; i++ )
> > > {
> > > 		Lo = L[i];
> > > 		Hi = H[i];
> > > 		if( P[i] > BBB[i] )
> > > 		{
> > > 			do
> > > 			{
> > > 			P[i] = P[i] - 0.01;
> > > 			MAV[i] = ( P[i] + C[i-1] + C[i-2] + C[i-3] + C[i-4] + C[i-5] + C[i-6] + C[i-7] + C[i-8] ) / 9;
> > > 			Var[i] = ( ( P[i] - MAV[i] )^2 + ( C[i-1] - MAV[i] )^2 + ( C[i-2] - MAV[i] )^2 + ( C[i-3] - MAV[i] )^2 + ( C[i-4] - MAV[i] )^2
> > > 			+ ( C[i-5] - MAV[i] )^2 + ( C[i-6]  - MAV[i] )^2 + ( C[i-7]  - MAV[i] )^2 + ( C[i-8] - MAV[i] )^2 ) / 9;
> > > 			STD[i] = sqrt( Var[i] );
> > > 			BBB[i] = MAV[i] - 2 * STD[i];
> > > 			}
> > > 			while ( P[i] > BBB[i] AND Lo[i] < P[i] );
> > > 		}
> > > 		else
> > > 		{
> > > 			do
> > > 			{
> > > 			P[i] = P[i] + 0.01;
> > > 			MAV[i] = ( P[i] + C[i-1] + C[i-2] + C[i-3] + C[i-4] + C[i-5] + C[i-6] + C[i-7] + C[i-8] ) / 9;
> > > 			Var[i] = ( ( P[i] - MAV[i] )^2 + ( C[i-1] - MAV[i] )^2 + ( C[i-2] - MAV[i] )^2 + ( C[i-3] - MAV[i] )^2 + ( C[i-4] - MAV[i] )^2
> > > 			+ ( C[i-5] - MAV[i] )^2 + ( C[i-6]  - MAV[i] )^2 + ( C[i-7]  - MAV[i] )^2 + ( C[i-8] - MAV[i] )^2 ) / 9;
> > > 			STD[i] = sqrt( Var[i] );
> > > 			BBB[i] = MAV[i] - 2 * STD[i];
> > > 			}
> > > 			while ( P[i] < BBB[i] AND Hi[i] > P[i] );
> > > 		}
> > > }
> > > 
> > > This procedure find the needed price level but it takes ages to complete a backtest procedure. I would greatly appreciate if someone could help me to simplify the process and make it more efficient. Thanks a lot!
> > > 
> > > 
> > > Regards,
> > > 
> > > Marius
> > > 
> > > 
> > > --- In amibroker@xxxxxxxxxxxxxxx, "Steve Dugas" <sjdugas@> wrote:
> > > >
> > > > Hi - AB allows you to define BuyPrice, SellPrice, etc.  So if you have your 
> > > > signals defined as price crossing BB, couldn't you just say
> > > > 
> > > > BuyPrice = BBandTop() or whatever?
> > > > 
> > > > Steve
> > > > 
> > > > ----- Original Message ----- 
> > > > From: "mbausys" <mbausys@>
> > > > To: <amibroker@xxxxxxxxxxxxxxx>
> > > > Sent: Friday, February 12, 2010 7:13 AM
> > > > Subject: [amibroker] Re: Projecting prices
> > > > 
> > > > 
> > > > > Steve,
> > > > >
> > > > > What I want to do with this code is for it to allow me enter a trade 
> > > > > exactly at the price which triggers a signal. In particular, I use 
> > > > > Bollinger Bands and want trades to be executed at the price at which it 
> > > > > equals Bollinger Bands. The price might then reverse and in EOD chart the 
> > > > > closing price would be inside Bollinger Bands. However, I would know that 
> > > > > the signal would have been generated intraday and I could have entered a 
> > > > > position. I'm not proficient with Amibroker coding yet so the required 
> > > > > twist might be very simple. Thank you for your help.
> > > > >
> > > > >
> > > > > Marius
> > > > >
> > > > > --- In amibroker@xxxxxxxxxxxxxxx, "Steve Dugas" <sjdugas@> wrote:
> > > > >
> > > > >
> > > > >>
> > > > >> Hi - What did you have in mind?  Fred can correct me if I'm wrong, but I
> > > > >> always imagined it was written for someone who wanted to trade at the 
> > > > >> close
> > > > >> but only gets EOD data. By the time you do the nightly data download and 
> > > > >> see
> > > > >> a new signal, the markets are closed and you can only trade NDO. With 
> > > > >> this
> > > > >> code you can predict the price needed to trigger a signal, then put on 
> > > > >> CNBC
> > > > >> or QuoteTracker to see if your price point has been met and trade just 
> > > > >> prior
> > > > >> to today's close. For backtests, just set trade price to close and trade
> > > > >> delay to zero, you should only need to predict the price for real-time
> > > > >> trading.
> > > > >>
> > > > >> Steve
> > > > >>
> > > > >> ----- Original Message ----- 
> > > > >> From: "mbausys" <mbausys@>
> > > > >> To: <amibroker@xxxxxxxxxxxxxxx>
> > > > >> Sent: Thursday, February 11, 2010 4:10 PM
> > > > >> Subject: [amibroker] Re: Projecting prices
> > > > >>
> > > > >>
> > > > >> >
> > > > >> >
> > > > >> > Thanks a lot for posting this. I'd like to ask how it would be possible 
> > > > >> > to
> > > > >> > use this process in a backtest procedure as it only determines a 
> > > > >> > required
> > > > >> > price for tomorrow. Please correct me if I'm wrong.
> > > > >> >
> > > > >> >
> > > > >> > Regards,
> > > > >> >
> > > > >> > Marius
> > > > >> >
> > > > >> >
> > > > >> > --- In amibroker@xxxxxxxxxxxxxxx, "Ara Kaloustian" <ara1@> wrote:
> > > > >> >>
> > > > >> >> Thanks Steve
> > > > >> >>
> > > > >> >> A
> > > > >> >>   ----- Original Message ----- 
> > > > >> >>   From: Steve Dugas
> > > > >> >>   To: amibroker@xxxxxxxxxxxxxxx
> > > > >> >>   Sent: Monday, April 10, 2006 10:53 AM
> > > > >> >>   Subject: Re: [amibroker] Projecting prices
> > > > >> >>
> > > > >> >>
> > > > >> >>   Hi Ara,
> > > > >> >>
> > > > >> >>   Your question rang a bell with me, so I searched my saved e-mails 
> > > > >> >> and
> > > > >> >> found this code that Fred was kind enough to post a couple of years 
> > > > >> >> ago.
> > > > >> >> Maybe it will be helpful for you?
> > > > >> >>
> > > > >> >>   Steve
> > > > >> >>
> > > > >> >>   // ***********************************************
> > > > >> >>   //
> > > > >> >>   // An all purpose routine to find the price
> > > > >> >>   // necessary to move an indicator to a GOAL.
> > > > >> >>   //
> > > > >> >>   // This should work for virtually any indicator,
> > > > >> >>   // built in or otherwise.  It's demonstrated
> > > > >> >>   // here using RSI & BBand's ...
> > > > >> >>   //
> > > > >> >>   // Note: It will appear to use future quotes
> > > > >> >>   // because of the down shifting of the
> > > > >> >>   // price array, but obviously it can't
> > > > >> >>   // "know" tomorrows price.  There's
> > > > >> >>   // probably a way to rectify this but
> > > > >> >>   // I was more concerned with the rest
> > > > >> >>   // of the process.
> > > > >> >>   //
> > > > >> >>   // The maximum iterations have arbitrarily been
> > > > >> >>   // set to 200 which is undoubtedly overkill
> > > > >> >>   // as I've yet to see anything take 200 even
> > > > >> >>   // when tolerance was set to 0 on datastreams
> > > > >> >>   // with very high prices.
> > > > >> >>   //
> > > > >> >>   // For real usage the saving of i in j and the
> > > > >> >>   // accuracy calculation can be tossed as they
> > > > >> >>   // were only put in for demonstration purposes
> > > > >> >>   //
> > > > >> >>   // ***********************************************
> > > > >> >>   //
> > > > >> >>   // This Routine requires the following things
> > > > >> >>   //
> > > > >> >>   // P0 = A price array or synthetic
> > > > >> >>   //
> > > > >> >>   // Goal = The goal value of the indicator
> > > > >> >>   //
> > > > >> >>   // Acc = An accuracy level for the calculations
> > > > >> >>   //
> > > > >> >>   //   Set this to the order of magnitude
> > > > >> >>   //   that you want.  For example if you want
> > > > >> >>   //   accuracy in calculated price to within
> > > > >> >>   //   0.01 then set it 0.01.  It can even
> > > > >> >>   //   be set to 0 which will force AB to
> > > > >> >>   //   calculate until it can't find any
> > > > >> >>   //   further improvements (Usually between
> > > > >> >>   //   150-170 iterations) but this is semi
> > > > >> >>   //   useless as improvements relative to
> > > > >> >>   //   price granularity have long since
> > > > >> >>   //   been gone by.
> > > > >> >>   //
> > > > >> >>   //   The lower you set it the longer it
> > > > >> >>   //   will take but it's pretty quick
> > > > >> >>   //   (Usually between 15-30 iterations)
> > > > >> >>   //   unless you set it at 0.
> > > > >> >>   //
> > > > >> >>   // ***********************************************
> > > > >> >>   //
> > > > >> >>   // Note: Some goals are virtually unattainable on
> > > > >> >>   // the next bar, especially on the downside
> > > > >> >>   // as they would require a negative price
> > > > >> >>   // which is what this routine will show if
> > > > >> >>   // that is what is required.
> > > > >> >>   //
> > > > >> >>   // ***********************************************
> > > > >> >>
> > > > >> >>   P0   = C;
> > > > >> >>
> > > > >> >>   Acc  = 0.0001;
> > > > >> >>
> > > > >> >>   LVBI = LastValue(BarIndex());
> > > > >> >>   Mult = 1;
> > > > >> >>
> > > > >> >>   // ***********************************************
> > > > >> >>   // Shift Price up by n orders of magnitude to make
> > > > >> >>   // it >= 1.  This is useful to increase
> > > > >> >>   // accuracy on very low priced datastreams
> > > > >> >>   // such as the JY.
> > > > >> >>   // ***********************************************
> > > > >> >>   for (i = 0; i < 10; i++)
> > > > >> >>   {
> > > > >> >>   if (P0[LVBI] >= 1)
> > > > >> >>   i = 99;
> > > > >> >>   else
> > > > >> >>   Mult = Mult * 10;
> > > > >> >>   }
> > > > >> >>   // ***********************************************
> > > > >> >>
> > > > >> >>   P1   = Ref(P0, 1) * Mult;
> > > > >> >>   UpDn = 100 * P1[LVBI];
> > > > >> >>
> > > > >> >>   for (i = 0; i < 200; i++)
> > > > >> >>   {
> > > > >> >>
> > > > >> >>   // An example for finding price associated with the next bars
> > > > >> >>   BBandTop
> > > > >> >>   //
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   // Put whatever indicator you want to goal seek here based on P1
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   Calc = P1;
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   // Put whatever you want for the goal here ...
> > > > >> >>   //
> > > > >> >>   // The reason for putting it in the loop is because sometimes
> > > > >> >>   the goal is price
> > > > >> >>   // oriented and will need to be recalculated on each
> > > > >> >>   iteration.
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   Goal = LastValue(BBandBot(P1, 14, 2));
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>
> > > > >> >>
> > > > >> >>
> > > > >> >>   // An example for finding price associated with the next bars
> > > > >> >>   RSI value of 65
> > > > >> >>   //
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   // Put whatever indicator you want to goal seek here based on P1
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   // Calc = RSIa(P1, 14);
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   // Put whatever you want for the goal here ...
> > > > >> >>   //
> > > > >> >>   // The reason for putting it in the loop is because sometimes
> > > > >> >>   the goal is price
> > > > >> >>   // oriented and will need to be recalculated on each
> > > > >> >>   iteration.
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>   // Goal = 65;
> > > > >> >>   //
> > > > >> >>   **************************************************************
> > > > >> >>   ***************
> > > > >> >>
> > > > >> >>   if (Calc[LVBI] < Goal)
> > > > >> >>   P1[LVBI] = P1[LVBI] + UpDn;
> > > > >> >>   else
> > > > >> >>   P1[LVBI] = P1[LVBI] - UpDn;
> > > > >> >>   UpDn = UpDn / 2;
> > > > >> >>   if (UpDn <= Acc)
> > > > >> >>   {
> > > > >> >>   j = i;
> > > > >> >>   i = 99999;
> > > > >> >>   }
> > > > >> >>   }
> > > > >> >>
> > > > >> >>   Accuracy = 100 * (abs(Goal - Calc) / Goal);
> > > > >> >>
> > > > >> >>   Filter = BarIndex() == LVBI;
> > > > >> >>
> > > > >> >>   AddColumn(Mult,
> > > > >> >>   "Multiplier",   1.0);
> > > > >> >>   AddColumn(Calc[LVBI - 1] / Mult, "Curr Ind Val", 1.9);
> > > > >> >>   AddColumn(Goal / Mult, "Goal Ind Val", 1.9);
> > > > >> >>   AddColumn(Calc[LVBI] / Mult, "Calc Ind Val", 1.9);
> > > > >> >>   AddColumn(j,
> > > > >> >>   "Iterations",   1.0);
> > > > >> >>   AddColumn(Accuracy,   "Accuray (%)",  1.9);
> > > > >> >>   AddColumn(Ref(P1, -1) / Mult, "Todays Price", 1.9);
> > > > >> >>   AddColumn(P1 / Mult, "Goal
> > > > >> >>   Price",   1.9);
> > > > >> >>
> > > > >> >>     ----- Original Message ----- 
> > > > >> >>     From: Ara Kaloustian
> > > > >> >>     To: amibroker@xxxxxxxxxxxxxxx
> > > > >> >>     Sent: Monday, April 10, 2006 1:08 PM
> > > > >> >>     Subject: Re: [amibroker] Projecting prices
> > > > >> >>
> > > > >> >>
> > > > >> >>     thanks Bob,
> > > > >> >>
> > > > >> >>     I had temporarily come to the same conclusion but realized that 
> > > > >> >> for
> > > > >> >> my particular application I already have the high and low prices ... 
> > > > >> >> just
> > > > >> >> need to calculate the close.
> > > > >> >>
> > > > >> >>     My application is to use historical data for backtest and figure 
> > > > >> >> out
> > > > >> >> a way to make it equivalent to using real time data by calculating the
> > > > >> >> exact price required to produce a signal, obviously within  the 
> > > > >> >> exixting
> > > > >> >> price range.
> > > > >> >>
> > > > >> >>     It's a clumsy solution since I will not be able to use the AB
> > > > >> >> backtester, but useful (I think). It would be great if AB backtester
> > > > >> >> could be used ...
> > > > >> >>
> > > > >> >>     So technically "projecting" prices in the subject line is a bit
> > > > >> >> misleading for this case...
> > > > >> >>
> > > > >> >>
> > > > >> >>     Ara
> > > > >> >>       ----- Original Message ----- 
> > > > >> >>       From: Bob Jagow
> > > > >> >>       To: amibroker@xxxxxxxxxxxxxxx
> > > > >> >>       Sent: Sunday, April 09, 2006 11:07 PM
> > > > >> >>       Subject: RE: [amibroker] Projecting prices
> > > > >> >>
> > > > >> >>
> > > > >> >>       An algebraic solution is possible only  for indicators dependent 
> > > > >> >> on
> > > > >> >> a single price array.
> > > > >> >>       That rules out CCI and Stochastics.
> > > > >> >>
> > > > >> >>       Bob
> > > > >> >>         -----Original Message-----
> > > > >> >>         From: amibroker@xxxxxxxxxxxxxxx
> > > > >> >> [mailto:amibroker@xxxxxxxxxxxxxxx]On Behalf Of Ara Kaloustian
> > > > >> >>         Sent: Sunday, April 09, 2006 9:43 PM
> > > > >> >>         To: AB-Main
> > > > >> >>         Subject: [amibroker] Projecting prices
> > > > >> >>
> > > > >> >>
> > > > >> >>         I am trying to figure out the required price to create a
> > > > >> >> particular value of an indicator.
> > > > >> >>
> > > > >> >>         Example: My CCI is at 50. I would get a signal if CCI reached 
> > > > >> >> 55.
> > > > >> >> What is the require value of price that would make CCI to rise to 55?
> > > > >> >>
> > > > >> >>
> > > > >> >>         This kind of calculation can be used to anticipate a signal 
> > > > >> >> and
> > > > >> >> allow us to place a conditional order for next day.
> > > > >> >>
> > > > >> >>         I am looking for the formulae to accomplish this for CCI,
> > > > >> >> Stochastics and MACD.
> > > > >> >>
> > > > >> >>         The formulae should be bit of algebra, but rather time 
> > > > >> >> consuming
> > > > >> >> to develop.
> > > > >> >>
> > > > >> >>         Wonder if anyone has already worked on this issue before.
> > > > >> >>
> > > > >> >>         Appreciate any help
> > > > >> >>
> > > > >> >>         ara
> > > > >> >>
> > > > >> >>
> > > > >> >>     Please note that this group is for discussion between users only.
> > > > >> >>
> > > > >> >>     To get support from AmiBroker please send an e-mail directly to
> > > > >> >>     SUPPORT {at} amibroker.com
> > > > >> >>
> > > > >> >>     For other support material please check also:
> > > > >> >>     http://www.amibroker.com/support.html
> > > > >> >>
> > > > >> >>
> > > > >> >>
> > > > >> >>
> > > > >> >>
> > > > >> >> ----------------------------------------------------------------------------
> > > > >> >>     YAHOO! GROUPS LINKS
> > > > >> >>
> > > > >> >>       a..  Visit your group "amibroker" on the web.
> > > > >> >>
> > > > >> >>       b..  To unsubscribe from this group, send an email to:
> > > > >> >>        amibroker-unsubscribe@xxxxxxxxxxxxxxx
> > > > >> >>
> > > > >> >>       c..  Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> > > > >> >> Service.
> > > > >> >>
> > > > >> >>
> > > > >> >> ----------------------------------------------------------------------------
> > > > >> >>
> > > > >> >
> > > > >> >
> > > > >> >
> > > > >> >
> > > > >> > ------------------------------------
> > > > >> >
> > > > >> > **** 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:
    amibroker-digest@xxxxxxxxxxxxxxx 
    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/