I'm aware the documentation says not to use OLE from within Amibroker.
I'm also aware of threads that say it's ok as long as you know what you're doing.
I'm likely one of those that do not know what I'm doing. Please help.
I've got this function, it's working up until line 108. ie I'm able to get the COM object, iterate through documents ( funny enough getting active doc or window doesn't do anything ), find windows, zoom windows to a predefined date range programmatically.
What I would absolutely love to do is to programmatically take a screenshot of the window once it's zoomed.
At the moment, logging stops at "Before image export" then the program fails silently.
I'm able to do this with JScript from outside amibroker as per reference manual but do not yet know/want to fiddle with setting it up to programmatically take screenshots of 400 trades over multiple windows ( different t/f ).
The questions are:
- Is there a way to take a screenshot programmatically from within amibroker itself?
- If not, what is the easiest way to setup a loop to do this for a csv of trades from outside of amibroker?
Thank you for reading!
You could do that only for chart that is NOT the one that currently executes the formula that contains ExportImage. Otherwise you are creating infinite loop/lockup (your formula executes->Export image causes another execution->your formula executes->Export image causes another execution that again causes Export image -> ad infinitum).
Ok, so I found this: How to get the marketid /name using Com Object?
And I think my problem is that ALL my charts are floating... doh!
Once I moved them to being normal, ActiveDocument, Document.Name, ExportImage started working on those windows.
Now I'm trying to work out how to keep my floating windows, whilst taking multiple timeframe screenshots of these in non-floating/normal windows, but that's a much easier problem to solve!
This is great!
You can also use third party software like nircmd.
procedure ScreenCapture( Type, AppendFileNameStr )
// Saves screenshot to file, using third party software nircmd.exe which must be downloaded from https://www.nirsoft.net/utils/nircmd.html
// nircmd.exe must be installed in the path indicated in ShellExecute(), below.
// Type 0 = primary monitor. 1 = full screen. 2 = current window.
// Filename must not contain spaces.
FileName = StrReplace( DateTimeFormat( "%Y%m%d_%H%M%S", Now(5) ) + "-" + AppendFileNameStr, " ", "-" );
FilePath = GetFormulaPathParent() + "AmiBroker\\Exports\\" + FileName + ".png";
CommandStr = WriteIf( Type == 0, "savescreenshot ", WriteIf( Type == 1, "savescreenshotfull ", WriteIf( Type == 2, "savescreenshotwin ", "" ) ) );
Result = ShellExecute( "C:\\Program Files\\nircmd-x64\\nircmd.exe", CommandStr + FilePath, "", 0 );
Trace( "ScreenCapture:" + Result );
This is brilliant!
After some tinkering, I realised that nircmd doesn't do exactly what I needed, they have the ability to crop and to do all monitors but not both sadly ( ie you can't do
screenshotfull <filename> 1920 0 1920 1080 to get the second monitor from the left )
However, ImageMagick does so I swapped it out with the cmd below. What I learned was
Very rough POC but what I needed was the ability to specify the 3rd monitor which will become a parameter in the forumula. Thank you @PeterD ! Very happy with the results.
procedure trade_window_screenCapture( fileName )
local fileName, filePath, screenshotCmd, result, arguments, convert;
convert = "c:\\Program Files\\ImageMagick-7.1.0-Q16-HDRI\\convert.exe";
arguments = "screenshot: c:\\temp\\" + fileName;
log_warn(StrFormat("ScreenCapture - %s", arguments));
result = ShellExecute( convert, arguments, "");
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.