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

[amibroker] Re: Request for Code Review


  • Date: Fri, 12 Mar 2010 19:41:36 -0000
  • From: "Mike" <sfclimbers@xxxxxxxxx>
  • Subject: [amibroker] Re: Request for Code Review

PureBytes Links

Trading Reference Links



To set individual array elements, use square brackets [].
Use a switch statement to differentiate between Buy, Sell, Short, Cover.
Note that the PositionSize array expects negative values below -2000 to indicate number of shares.

      switch (Action) {
         
case "Buy":
            
Buy[ActionBar] = true;
            
BuyPrice[ActionBar] = ActionPrice;
            
PositionSize[ActionBar] = -2000 - ActionPositionSize;
            
break;

         
case "Sell":
            ...
            
break;

         
case "Short":
            ...
            
break;

         
case "Cover":
            ...
            
break;
      } 

You can try something like the following to ensure that the fgets line has not been truncated. Essentially we're saying that if the line did not end with the newline character, yet we still haven't reached the end of the file, then the line must have been truncated. I have not tested it, but that's the way the documentation reads.

http://www.amibroker.com/guide/afl/afl_view.php?id=228

      while (!feof(fh)) {
         Row =
"";

         
do {
            Segment =
fgets(fh);
            Row += Segment;
         }
while (StrRight(Segment, 1) != "\n" && !feof(fh)); 

         ...
      }

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "longt3rm" <longt3rm@xxx> wrote:
>
> Mike,
>
> Thank you so much for the information.
>
> All,
> I'm having challenges with two points:
> 1. One file vs. Multiple Files = I'm not able to figure out how to use Buy[Index] where Index is calculated. As you see below, I am processing the file and every row in the file for each bar / column in the array. I suspect this is wrong. Would you have suggestions on how to calculate and use "Index".
>
> 5. Would you suggest a url where I can learn about fgets maximum buffer length? I'm not able to locate a function to test for the success / failure of fgets.
>
> Below is the current code which works in Formula Editor | Verify Syntax but crashes the backtest:
> ------------------------
> filename = "C:\\data\\signal_";
> fileext = ".txt";
> filename = filename + Name() + fileext;
>
> Buy = 0;
> Sell = 0;
> dt = DateTime();
> RowNum = 0;
>
> fh = fopen(filename ,"r");
>
> if(fh)
> {
> Indices = BarIndex();
> while(! feof(fh)) //Have we reached end of file?
> {
> Row = fgets(fh);
> RowNum += 1;
> if(1 + StrCount(Row,",")== 4) //Make sure we have four values per Row; Date, Action, PositionSize, Price
> {
> ActionDate = StrToDateTime(StrExtract(Row,0));
> Action = "">> ActionPositionSize = StrExtract(Row,2);
> ActionPrice = StrExtract(Row,3);
> //Next Row finds the correct bar but I cannot figure out how to use it effectively.
> ActionBar = ValueWhen(dt==ActionDate, Indices);
> Buy = IIf(Action="" AND dt==ActionDate,1,Buy );
> Sell = IIf(Action="" AND dt==ActionDate,1,Sell);
> }
> }
> fclose(fh);
> }
>


__._,_.___


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





Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___