How to get selected date or Lastvalue Date in OLE

Hi all.
Below is the javascript code which is working fine to export the image. I need to add selected date in the code but unable to do it. It is needed because I want to take image of same symbol multiple time.

AB = new ActiveXObject("Broker.Application");
Name = AB.ActiveDocument.Name;
exportPath = "C:\\Amibroker Scripting\\Export Image\\"+Name+".PNG";
AW = AB.ActiveWindow;
AW.ExportImage( exportPath); 

Kindly help....

Hi
Just before yahoogroups close, we can see an example

i have save the following in a file named as
Auto_Export_to_png_deskTop.js >>


/////////////// start code ////////////////////////

// Auto Export to PNG
// this  javascript which when double clicked will export symbol in 
current active window to a .png file
// In the tools menu entry definition:
// Command: wscript.exe
// Arguments: //E:javascript Auto_Export_to_png_deskTop.js
// Initial Directory: E:\Stock\AmiBroker\Scripts\

saveimage = "C:\\Documents and Settings\\Administrator\\Desktop\\";

var oAB = WScript.CreateObject("Broker.Application");
Ticker = oAB.ActiveDocument.Name;

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

DateObj=new Date();
Ye=DateObj.getYear();
M=(DateObj.getMonth()+1);
D=DateObj.getDate();
H=DateObj.getHours();
mi=DateObj.getMinutes();

Win = AB.ActiveWindow;

output=saveimage + Ticker + "-"+D+M+Ye+"_"+H+"-"+mi+ ".png";
Win.ExportImage( output, 800, 600 );

var Shell;
Shell = new ActiveXObject("WScript.Shell");
Shell.Popup("Foto is ready",2); // 2 second to close the popup window

/////////////// end code ////////////////////////
2 Likes

Now if you need selected day or last bar date then you can use AFL version

For the lastbar we can use

ldt= DateTimeToStr( LastValue( DateTime() ),3 );  // rerurn LastValue DateTime

And for selected bar is ready AFL example below. Need go to parameters CLR+ R and press to export chart image

 _SECTION_BEGIN( "FOTO" );
 // path to Export foto
 // foto="C:\\temp\\"+Name()+SelectedValue(DateNum())+".png";  	// rerurn time YYMMDD
 foto="C:\\temp\\"+Name()+"_"+DateTimeToStr(SelectedValue( DateTime()),3 )+".png";  // rerurn time YYYY-MM-DD HH:MM:SS)
 
if( ParamTrigger( "Image export", "Click" ) )
{
    Say( "Foto" );
    AB = CreateObject( "Broker.Application" ); // AVOID THIS with multithread
    AW = AB.ActiveWindow;
    AW.ExportImage( foto, 1280, 960 );
}
_SECTION_END();

Νow i hope we have covered all possible as far as the filename it will be

3 Likes

Thanks. AFL version is fine also. Above code for java script is more suitable because I can create a Image saver button using that.

Thanks again.....
Here is my code which was developed by your help

AB = new ActiveXObject("Broker.Application");
Name = AB.ActiveDocument.Name;

AW = AB.ActiveWindow;
var today = new Date();
var date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
var time = today.getHours() + "." + today.getMinutes() + "." + today.getSeconds();

exportPath = "C:\\Amibroker Scripting\\Export Image\\"+Name+"_"+date+"_"+time+".PNG";
AW.ExportImage( exportPath); 

var Shell;
Shell = new ActiveXObject("WScript.Shell");
Shell.Popup("Picture Saved In "+exportPath,2); // 2 second to close the popup window
1 Like

Thanks.
Here is the button I created using above code.

image

2 Likes