Could any one please help me to change this code so that user can enter a value for the variable Days .
Please see lines 33 to 52 in the code below.
I have tried to use my rather limited knowledge of java scripts and attempted to use the following:
daysInput = shell.InputBox("Please enter the number of days to clean zero-volume quotes:", "Input for Days");
and the a short logic to validate the entered value.
It looks however the broker object does not support (I could be totally wrong here) user input using shell.inputbox.
And to be plain simple, I do not know what I need to do to accept a user input for a number of days, once the script starts running.
I do appreciate and would be very grateful for any guidance on this,
Thank you kindly.
// Windows script to clean zero-volume quotes from AmiBroker data
// This script runs from outside of AmiBroker
function RemoveZeroVolumeQuotes(stockName, days) {
var AB = new ActiveXObject("Broker.Application");
var stock = AB.Stocks(stockName);
var quotations = stock.Quotations;
var totalQuotes = quotations.Count;
// Approximate number of quotes per day (1-minute intervals)
var maxQuotesPerDay = 384;
// Adjust maxQuotesPerDay if there are fewer than expected quotes
if (totalQuotes < days * maxQuotesPerDay) {
maxQuotesPerDay = Math.floor(totalQuotes / days);
}
var removedCount = 0;
// Loop through the last 'days' of quotes and remove those with zero volume
for (var i = totalQuotes - 1; i >= totalQuotes - days * maxQuotesPerDay; i--) {
var quote = quotations.Item(i);
if (quote.Volume === 0) {
removedCount++;
quotations.Remove(i);
}
}
AB.RefreshAll();
return removedCount;
}
// Create a WScript.Shell object
var shell = new ActiveXObject("WScript.Shell");
// Show an input box to prompt the user for the number of days
var daysInput = shell.InputBox("Please enter the number of days to clean zero-volume quotes:", "Input for Days");
// Check if the user pressed "Cancel"
if (daysInput === null) {
WScript.Echo("User cancelled the input.");
WScript.Quit();
}
// Try to parse the input as an integer
var days = parseInt(daysInput, 10);
// Check if the entered value is a valid number
if (isNaN(days) || days <= 0) {
WScript.Echo("Please enter a valid number of days.");
WScript.Quit();
}
var totalRemovedQuotes = 0;
var stocks = [
"360-ASX-S-AUD",
"A2M-ASX-S-AUD",
"AGL-ASX-S-AUD",
"ALD-ASX-S-AUD"
];
// Remove zero-volume quotes from each stock and accumulate the removed count
for (var i = 0; i < stocks.length; i++) {
totalRemovedQuotes += RemoveZeroVolumeQuotes(stocks[i], days);
}
WScript.Echo("Cleanup Completed\n" + totalRemovedQuotes + " quotes with zero volume have been removed.");