use of suite.trade.analysis.MovingAverage.MovingRange in project suite by stupidsing.
the class BackAllocatorGeneral method donchian.
private BackAllocator donchian(int window) {
float threshold = .05f;
return BackAllocator_.byPrices(prices -> {
MovingRange[] movingRanges = ma.movingRange(prices, window);
return Quant.fold(0, movingRanges.length, (i, hold) -> {
MovingRange range = movingRanges[i];
double min = range.min;
double max = range.max;
double price = prices[i];
// channel wide?
boolean b = price * threshold < (max - min);
return b ? Quant.hold(hold, price, min, range.median, max) : hold;
});
});
}
Aggregations