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

Re: [amibroker] First Value When



PureBytes Links

Trading Reference Links

Ken, 

if you can define your range (first bar in range), then you can find the first buy bar by using valuewhen() and looking into the future (n= -1).

Offset = BarIndex() - FirstBarInRange;
Ref(ValueWhen(Buy==1,BarIndex(),-1),-Offset);

This will start looking for a Buy signal after your firstbarin range.

Alternately, you can certainly use a loop.

m=Firstbarinrange-1;
count = 0;
// Use count to limit number of loops in case of getting in an infinite loop.
do
{
m++;
count++;
} (while Buy==0 and  count < 100);

BuyBar = m;

but if you are planning on using the backtester in this application, you may have some issues if you use loops.

Array processing that AB uses has been a blessing due to its speed and a headache due to issues like this - at least for me.

Ara
  ----- Original Message ----- 
  From: Ken Close 
  To: amibroker@xxxxxxxxxxxxxxx 
  Sent: Sunday, February 04, 2007 10:43 AM
  Subject: RE: [amibroker] First Value When


  Ara:  thanks for the suggestion, which caused me to go off and study StaticVars, which I have not used before.

  Now, having studied it, I am left with my original problem.  How do I set the Static Variable to the Price (or Shares) when there was the first Buy signal?  Part of what is causing me problems is that I have a test range that is less than the total number of bars of data for the ticker.  I want the first buy within the test range, yet status(barinrange) is not helping me isolate the buys.  I have been trying all of this with full arrays, and perhaps need to go into a loop and check each bar.  I also have not used the custom backtester.  It seems this problem can be solved using plain ol' arrays.

  Grrrr.  Any further suggestions?



------------------------------------------------------------------------------
  From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf Of Ara Kaloustian
  Sent: Sunday, February 04, 2007 12:53 PM
  To: amibroker@xxxxxxxxxxxxxxx
  Subject: Re: [amibroker] First Value When


  Ken,

  why not save the number of shares (when initially bought), into a static variable?

  Ara
    ----- Original Message ----- 
    From: Ken Close 
    To: amibroker@xxxxxxxxxxxxxxx 
    Sent: Sunday, February 04, 2007 8:07 AM
    Subject: [amibroker] First Value When


    I want to determine the stock price (to become the Buyprice) at the very first Buy signal in a series of buy signals over a range.

    When I have written 

    ValueWhen(Buy, Close);

    I get changing buy prices at each Buy signal.

    I have tried counting the number of Buy signals in the Range, and using

    ValueWhen(Buy, Close, NumbBuys);  but that does not seem to get it.

    What I am doing is using the BuyPrice to determine the number of shares purchased at that very first buy signal, then wanting to maintain that same number of shares throughout the range.

    Any suggestions to solve my problem?

    Thanks,

    Ken
   
Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.17.24/668 - Release Date: 2/4/2007 1:30 AM