pinescript, i'm gathering cumulative sums for regression calculation,combining 4 points…
- User
pinescript, i'm gathering cumulative sums for regression calculation,combining 4 points in one array bucket, which doesn't make difference for sum, the only difference is the number of points os actually 4 times greater then array size: x = 4.0 * time y = open + close + high + low // Get last sums from arrays lastSumX = cumSumX.get(cumSumX.size() - 1) lastSumY = cumSumY.get(cumSumY.size() - 1) lastSumXY = cumSumXY.get(cumSumXY.size() - 1) lastSumX2 = cumSumX2.get(cumSumX2.size() - 1) // Append new cumulative sums for this bar cumSumX.push(lastSumX + x) cumSumY.push(lastSumY + y) cumSumXY.push(lastSumXY + x * y) cumSumX2.push(lastSumX2 + x * x) now, when i calculate , as far i see it, if i want to accomodate for 4 times greater number of points then buckets in array i just need to multiply count by 4, keeping rest of formulas intact: float sumX = cumSumX.get(endingOffset + 1) - cumSumX.get(startingOffset) float sumY = cumSumY.get(endingOffset + 1) - cumSumY.get(startingOffset) float sumXY = cumSumXY.get(endingOffset + 1) - cumSumXY.get(startingOffset) float sumX2 = cumSumX2.get(endingOffset + 1) - cumSumX2.get(startingOffset) int n = 4*(endingOffset - startingOffset + 1) float denom = n * sumX2 - sumX * sumX float slope = denom != 0 ? (n * sumXY - sumX * sumY) / denom : na float intercept = denom != 0 ? (sumY - slope * sumX) / n : na float angle = math.atan(slope) / math.pi * 180 here i multiply n by 4 to adjust is that correct?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.