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

[amibroker] Re: Need help on Jscript



PureBytes Links

Trading Reference Links

Grover,

Sounds like you've got the concept. I didn't test my example. But  
rather just banged out a quick code snippet.

It looks like I forgot to include a + "-" + between 
rightNow.getMinutes() and rightNow.getSeconds(), which wouldn't cause 
the error, but needs fixing anyway.

The error is that JScript is case sensitive. So, "fileName" is not 
the same as "filename" (note the uppercase N vs. lowercase n). You 
needed to pass fileName to your ExportImage function call, not 
filename.

The following code has been tested and works. Modify the file path as 
you see fit. Be sure to use \\ (double backslash) for path separation:

AB = new ActiveXObject("Broker.Application");
Win = AB.ActiveWindow;

// e.g. Image_2008-8-6_14-22-33.png
rightNow = new Date();
fileName = "c:\\temp\\Image_" +
rightNow.getFullYear() + "-" + 
(rightNow.getMonth() + 1) + "-" +
rightNow.getDate() + "_" + 
rightNow.getHours() + "-" +
rightNow.getMinutes() + "-" +
rightNow.getSeconds() +
".png";

Win.ExportImage( fileName, 1280, 960 );

For the second case (milliseconds by the way, not seconds as I 
hurriedly posted earlier), you did not get an error because you used 
lowercase n for both the variable initialization and usage. However, 
you forgot the parenthesis after getTime(). The following has been 
tested and works:

AB = new ActiveXObject("Broker.Application");
Win = AB.ActiveWindow;

// e.g. Image_1218084630858.png
rightNow = new Date();
fileName = "c:\\temp\\Image_" + rightNow.getTime() + ".png";

Win.ExportImage( fileName, 1280, 960 );

Mike

--- In amibroker@xxxxxxxxxxxxxxx, "Grover Yowell" <gyowell1@xxx> 
wrote:
>
> Mike,
> 
>  
> 
> Thanks for the reply and the idea on how to do it.  I think I am 
intimidated
> by not being familiar with Jscript.  I will be doing some study on 
Jscript
> in my spare time.
> 
>  
> 
> Ok, I tried your code and got a run time error , but modified it to 
its
> simplest elements and have the simple version working.  Thanks!
> 
>  
> 
> Here is what I had in exportimage1.js which I cut and pasted from 
your post.
> This version gave me a run time error and complained about filename.
> 
>  
> 
> AB = new ActiveXObject("Broker.Application");
> 
>  
> 
> Win = AB.ActiveWindow;
> 
> // e.g. Image_2008-8-6_14-22-33.png
> 
> rightNow = new Date();
> 
> fileName = "Image1_" + rightNow.getFullYear() + "-" + 
> 
> (rightNow.getMonth() + 1) + "-" + rightNow.getDate() + "_" + 
> 
> rightNow.getHours() + "-" + rightNow.getMinutes() + 
> 
> rightNow.getSeconds() + ".png";
> 
>  
> 
> Win.ExportImage( filename, 1280, 960 );
> 
>  
> 
> Next I tried your alternative, which was exportimage3.js;
> 
> AB = new ActiveXObject("Broker.Application");
> 
>  
> 
> Win = AB.ActiveWindow;
> 
> // e.g. Image_2008-8-6_14-22-33.png
> 
> rightNow = new Date();
> 
> //fileName = "Image_" + rightNow.getFullYear() + "-" + 
> 
> //(rightNow.getMonth() + 1) + "-" + rightNow.getDate() //+ //"_" + 
> 
> //rightNow.getHours() + "-" + rightNow.getMinutes() + 
> 
> //rightNow.getSeconds() + ".png";
> 
> filename = "Image3_" + rightNow.getTime + ".png";
> 
> Win.ExportImage( filename, 1280, 960 );
> 
>  
> 
> This version, curiously did not give a run time error, but didn't 
export the
> image either. Darn!
> 
>  
> 
> That is when I decided to simplify the problem to its barest terms 
and use
> the following as export image2:
> 
>  
> 
> AB = new ActiveXObject("Broker.Application");
> 
>  
> 
> Win = AB.ActiveWindow;
> 
>  
> 
> num = 5;
> 
> filename = "Image2_" + num + ".png";
> 
> Win.ExportImage( filename, 1280, 960 );
> 
>  
> 
> This version worked. Success!  I figured that if the simple version 
worked,
> that it would be easy to index num or better to use some of your 
code after
> we find the error.
> 
>  
> 
> Again, thanks for all your help.
> 
>  
> 
> Grover
> 
>  
> 
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] 
On Behalf
> Of Mike
> Sent: Wednesday, August 06, 2008 5:55 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] Re: Need help on Jscript
> 
>  
> 
> You can just tack on the current date/time to the file name. Try 
> something along these lines before exporting your image:
> 
> // e.g. Image_2008-8-6_14-22-33.png
> rightNow = new Date();
> fileName = "Image_" + rightNow.getFullYear() + "-" + 
> (rightNow.getMonth() + 1) + "-" + rightNow.getDate() + "_" + 
> rightNow.getHours() + "-" + rightNow.getMinutes() + 
> rightNow.getSeconds() + ".png";
> 
> If you really want to get fancy, use "Buy_" or "Sell_" instead 
> of "Image_" :)
> 
> Alternatively, you can just use seconds since the epoch:
> 
> // e.g. Image_438057023343... some crazy long number ...
> rightNow = new Date();
> fileName = "Image_" + rightNow.getTime(); + ".png";
> 
> Mike
> 
> --- In amibroker@xxxxxxxxxxxxxxx <mailto:amibroker%
40yahoogroups.com> ,
> "gyowell2000" <gyowell1@> wrote:
> >
> > Hello,
> > 
> > I want to save an image to file after the Buy or Short for each 
> > trade. The export image method to do this is in Jscript, and must 
> > be called from outside of AB. But I have a problem since I need 
to 
> > use the BUY(or Short) from AB to trigger the image export. So 
what 
> > I have come up with is to use the Alertif function inside AB to 
> > trigger the external action, e.g.,
> > 
> > AlertIf( Buy, "EXEC C:\\ExportImage.js" , "At "+Now() , 1 );
> > 
> > Then on the root directory of the C: drive, a I have a Jscript 
> file, 
> > ExportImage.js which is:
> > 
> > AB = new ActiveXObject("Broker.Application");
> > 
> > Win = AB.ActiveWindow;
> > 
> > Win.ExportImage( "test3.png", 1280, 960 );
> > 
> > So far so good. Works like a champ EXCEPT that it keeps writing 
> > each new image to the same file name, test3.png.
> > 
> > So here is the question: How do I increment the number after test 
> > or attach a time stamp to it sso that I get individual files for 
> > each image? I have tried several approaches but nothing works so 
> > far. Also can see from the Jscript documentation in the User's 
> > Guide and on the web, that it will be a chore to learn Jscript 
> > basics. I want to do that over time , but not right now.
> > 
> > Can anyone help?
> > 
> > Thanks in advance,
> > 
> > Grover
> >
>



------------------------------------

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 NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
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:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto: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/