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

Re: [amibroker] USE OF [ ]



PureBytes Links

Trading Reference Links

Anthony - 
I believe you are using Barcount when you should be using Barindex() to step through an array.  
However I believe you can do it without indexing down an array, by using the Ref function, 
 BuyState = MyMA > Ref(MyMA,-R)  

The way to run this is - select a single issue, set the number of bars to 500 or so, and
do an EXPLORE.  From the columns of data that spills out you should be able to see what's happening when you apply the rules you've got coded.   It's a way to debug with using DebugView.  

Note the item about Barcount and Barindex() attached also.

Hope this helps
JOE    

Amount = Param( "dollz", 10000, 50, 1000000, 50 );

defMAL = Param("MAL",10, 2, 200, 10 );

defR = Param( "Recul", 30, 2, 30, 2 );

MAL = Optimize( "MAL", defMAL, 2, 100, 5 );

R = Optimize( "Recul", defR, 1, 20, 2 );

PositionSize = Amount;

MyMA = MA( Close, MAL );

BuyState = MyMA > Ref(MyMA,-R);

Sellstate = MyMA < Ref(MyMA,-R);

Buy = ExRem(BuyState,SellState); 

Sell= ExRem(SellState,BuyState);

Short = MyMA < Ref(MyMA,-R);

Cover = MyMA > Ref(MyMA,-R);

Filter =1; 

AddColumn(BarCount,"Barcount"); 

AddColumn(BarIndex(),"Barindex"); 

AddColumn(BarCount - R,"BC-R"); 

AddColumn(BarIndex()-R,"BI-R"); 

AddColumn(BuyState,"Buy State"); 

AddColumn(SellState,"Sell state"); 

AddColumn(Buy,"Buy Single"); 

AddColumn(Sell,"Sell Single"); 





Barcount vs BarIndex()
There is a fundamental difference between BarCount and BarIndex(). BarCount is a numeric variable that holds just one number (the count of elements in array). On the other hand BarIndex() is a function that returns ARRAY representing consecutive index of each bar. 

EXAMPLE 

Incorrect code:

for (i = 0; i < BarIndex();i++ ) // WRONG 
{ 
  // your formula 
}

It's not allowed to use ARRAY inside for loop, and Barindex() returns ARRAY. That is why it's necessary to change the formula.

Correct code:

for (i =0 ; i < BarCount ;i++ )  // CORRECT 
{ 
  //your formula 
}

  ----- Original Message ----- 
  From: Schippers Anthony 
  To: amibroker@xxxxxxxxxxxxxxx 
  Sent: Tuesday, October 17, 2006 12:54 PM
  Subject: [amibroker] USE OF [ ]


  Hello,

  I am a french trader and user of amibroker( former TS user ) ,and I always have the same problems with array identifiers. 

  On TS, you simply use a variables between the brackets, but on ami, it seems like you have to put [barcount - var]...

  Anyone can help me and tell where the error is in this code. It's a simple mov avg system referring to the past value of the mov avg:

  Amount = Param( "dollz", 10000, 50, 1000000, 50 );
  defMAL = Param("MAL", 10, 2, 200, 10 );
  defR = Param( "Recul", 30, 2, 30, 2 );

  MAL = Optimize( "MAL", defMAL, 2, 100, 5 );
  R = Optimize( "Recul", defR, 1, 20, 2 );

  PositionSize = Amount;

  MyMA = MA( Close, MAL );

  Buy = MyMA > MyMA[BarCount - R];
  Sell = MyMA < MyMA[BarCount - R];

  Short = MyMA < MyMA[BarCount - R];
  Cover = MyMA > MyMA[BarCount - R];


  Thanks for your help.



------------------------------------------------------------------------------
  Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son interface révolutionnaire.  
Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.13.27/517 - Release Date: 11/3/2006