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

[amibroker] Re: Request for Code Review


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

PureBytes Links

Trading Reference Links

Just for clarity, when calculating ActionBar, you would need to use LastValue(ValueWhen(...)) such that you end up with a scaler instead of an array.

Also, none of the code posted in any of my replies to this thread has actually been tested. So, look for the intent and make corrections as needed.

Finally, I haven't given much thought to what you're trying to do. So, there may be a better way. My comments are merely intended to help you along the path you've chosen.

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> 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
> <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@> 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 = StrExtract(Row,1);
> >    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=="Buy" AND dt==ActionDate,1,Buy );
> >    Sell = IIf(Action=="Sell" 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/

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/