Hi,
I want to customize the style of stick such that
1. Green and hollow stick if it is rising and open higher than close
2. Green and fill stick if it is rising and open lower than close
3. Red and hollow stick if it is falling and open higher than close
4. Red and fill stick if it is falling and open lower than close
How could i achieve that with only one candle series?
- tommy ng asked 6 years ago
- last edited 6 years ago
- You must login to post comments
Hi Tommy,
I believe you can do achieve this by using our PaletteProvider API.
I’m not sure what do you mean by ‘rising stick’ but you can use next code as base for your palette provider:
private static class CandleStickPaletteProvider extends PaletteProviderBase<FastCandlestickRenderableSeries> implements IStrokePaletteProvider, IFillPaletteProvider {
private final IntegerValues fillColors = new IntegerValues();
private final IntegerValues strokeColors = new IntegerValues();
public CandleStickPaletteProvider() {
super(FastCandlestickRenderableSeries.class);
}
@Override
public IntegerValues getFillColors() {
return fillColors;
}
@Override
public IntegerValues getStrokeColors() {
return strokeColors;
}
@Override
public void update() {
final OhlcRenderableSeriesBase renderableSeries = this.renderableSeries;
final OhlcRenderPassData currentRenderPassData = (OhlcRenderPassData) renderableSeries.getCurrentRenderPassData();
final int size = currentRenderPassData.pointsCount();
fillColors.setSize(size);
strokeColors.setSize(size);
final int[] fillColorsArray = fillColors.getItemsArray();
final int[] strokeColorsArray = strokeColors.getItemsArray();
final double[] openValues = currentRenderPassData.openValues.getItemsArray();
final double[] closeValues = currentRenderPassData.closeValues.getItemsArray();
final double[] highValues = currentRenderPassData.highValues.getItemsArray();
final double[] lowValues = currentRenderPassData.lowValues.getItemsArray();
for (int i = 0; i < size; i++) {
final double closeValue = closeValues[i];
final double openValue = openValues[i];
final boolean up = closeValue >= openValue;
final boolean isRising = closeValue >= openValue;
strokeColorsArray[i] = up ? Color.GREEN : Color.RED;
fillColorsArray[i] = isRising ? strokeColorsArray[i] : Color.TRANSPARENT;
}
}
}
Is this suitable for your needs?
Best regards,
Yura
- Yura Khariton answered 6 years ago
-
Thanks!!! It works
- You must login to post comments
Please login first to submit.