The problem started a month ago,
Some of the older sheets, where I get a list of stocks, and calculate moving averages, bollinger band values etc, in form of a table through googlesheets script. It used to do 4-10 stocks per minute when I created the sheet. But now, it is at 0.3 Stock/min.
What I have done till now based on other questions on stackoverflow.
- Removed all the formulas where range was infinite, A:A to A1:A100.
- Added SpreadsheetApp.flush(); without any help
- Put sleep timer on time based infinite loop. (Do While loop with an end time - start time < 3 minutes)
- Deleted blank rows and blank columns.
- Part of the code where I think the problem is.
if ( s1.getRange("t1").getValue() == 1)
{
var stime = min+sec/60;
do
{
SpreadsheetApp.flush();
if(s1.getRange("d7").getValue()>0){s1.getRange('e1').copyTo(s1.getRange('d14'),{contentsOnly: true})}
s1.getRange("t1").setValue(0);
var pasterow= s1.getRange("d7").getValue();
if(pasterow<=s1.getRange('t2').getValue()&&s1.getRange("G9").getValue()>0) //Conditions required for pasting values in table
{
var t = 'l'+pasterow; var p = 'm'+pasterow;var q = 'n'+pasterow;var r = 'o'+pasterow;
var s = 'p'+pasterow;var x = 'q'+pasterow;var u = 'L'+pasterow;var v = 's'+pasterow;var w = 'i'+pasterow;
s1.getRange('d6').copyTo(s1.getRange(t),{contentsOnly: true});
s1.getRange('d5').copyTo(s1.getRange(p),{contentsOnly: true});
s1.getRange('d8').copyTo(s1.getRange(q),{contentsOnly: true});
s1.getRange('d9').copyTo(s1.getRange(r),{contentsOnly: true});
s1.getRange('d10').copyTo(s1.getRange(s),{contentsOnly: true});
s1.getRange('d11').copyTo(s1.getRange(x),{contentsOnly: true});
s1.getRange('d16').copyTo(s1.getRange(v),{contentsOnly: true});
s1.getRange("d18").copyTo(s1.getRange(w),{contentsOnly: true});
}
Utilities.sleep(10000);
var date = new Date(); var day = date.getDay();var hrs = date.getHours();var min = date.getMinutes(); var sec = date.getSeconds()+1;
var etime =min+sec/60;if(stime>=55&&etime<10){etime = etime+60;};
s1.getRange("G9").setValue(etime)
} while (etime-stime<1.95 && pasterow<s1.getRange('t2').getValue()+1 && s1.getRange('ad2').getValue()==0);
}