Search Results for

    Show / Hide Table of Contents

    The FibonacciRetracementAnnotationCreationModifier

    The FibonacciRetracementAnnotationCreationModifier is a chart modifier that allows for interactive creation of FibonacciRetracementAnnotation instances using either a 2-tap or a single-drag workflow.

    Overview

    When this modifier is enabled, users can place the 2 required anchor points - the start and the end of the price move being retraced - in one of two ways:

    • Tap to place: Each tap confirms the position of the next anchor point. A "rubber-band" dashed line provides a preview of the segment between the last confirmed point and the current touch position.
    • Single drag: If the finger moves more than 10 pixels before the first touch-up, the gesture is classified as a drag - both anchor points are placed from the start and end of that drag, and the annotation is finalized on touch-up.

    Once both points are placed, the annotation is finalized, the rubber-band preview is removed, and the modifier automatically resets to create the next one.

    Configuring the Created Annotations

    The modifier exposes the three label properties of the FibonacciRetracementAnnotation. They are applied to every annotation the modifier creates, and assigning any of them also updates the annotation currently being created:

    Property Description
    labelPlacement Whether each level's label sits beside the left anchor point (SIDE) or centered between the two anchor points (CENTER). Defaults to SIDE.
    labelFormat Whether the label text shows the raw ratio (RATIO) or a percentage (PERCENT). Pass null to auto-select based on labelPlacement. Defaults to null.
    labelVerticalPosition Whether each label sits ABOVE, ON_LINE or BELOW its level line. Defaults to ON_LINE.
    Note

    The Fibonacci levels and their colors are not exposed on the modifier. To customize those for every created annotation, override createAnnotation as shown in the Customizing the Modifier section below.

    Properties

    The following properties can also be used to configure the FibonacciRetracementAnnotationCreationModifier:

    Property Description
    xAxisId Sets the ID of the X-Axis that the created annotations should be measured against.
    yAxisId Sets the ID of the Y-Axis that the created annotations should be measured against.
    rubberBandStroke Sets the pen style for the preview line shown during creation. Must not be null.

    The following read-only properties allow to inspect the creation progress, e.g. from a custom subclass:

    Property Description
    currentAnnotation The annotation currently being created, or null if no creation is in progress.
    currentPointIndex The index of the next anchor point to be placed - 0 for the start, 1 for the end.
    rubberBandAnnotation The rubber-band preview annotation, or null if it is not currently shown.

    Event Listeners

    You can receive a notification when an annotation is fully created by setting an OnAnnotationCreatedListener:

    • setAnnotationCreationListener(OnAnnotationCreatedListener listener): Passes the newly created annotation instance to the listener.

    Using FibonacciRetracementAnnotationCreationModifier

    The following code demonstrates how to add and configure a FibonacciRetracementAnnotationCreationModifier:

    • Java
    • Kotlin
    // Create a FibonacciRetracementAnnotationCreationModifier
    final FibonacciRetracementAnnotationCreationModifier fibonacciCreationModifier = new FibonacciRetracementAnnotationCreationModifier();
    
    // Optional: Configure how the labels of every created annotation are placed and formatted
    fibonacciCreationModifier.setLabelPlacement(FibonacciRetracementAnnotation.LabelPlacement.CENTER);
    fibonacciCreationModifier.setLabelFormat(FibonacciRetracementAnnotation.LabelFormat.RATIO);
    fibonacciCreationModifier.setLabelVerticalPosition(FibonacciRetracementAnnotation.LabelVerticalPosition.ABOVE);
    
    // Optional: Customize the rubber-band preview line shown while placing the points
    fibonacciCreationModifier.setRubberBandStroke(new SolidPenStyle(Color.WHITE, true, 1.5f, new float[]{5, 5}));
    
    // Optional: Set a listener to be notified when an annotation is created
    fibonacciCreationModifier.setAnnotationCreationListener(newAnnotation -> {
        // Configure the newly created annotation if needed
        newAnnotation.setIsEditable(true);
    });
    
    // Add the modifier to the surface
    surface.getChartModifiers().add(fibonacciCreationModifier);
    
    // Create a FibonacciRetracementAnnotationCreationModifier
    val fibonacciCreationModifier = FibonacciRetracementAnnotationCreationModifier().apply {
        // Optional: Configure how the labels of every created annotation are placed and formatted
        labelPlacement = FibonacciRetracementAnnotation.LabelPlacement.CENTER
        labelFormat = FibonacciRetracementAnnotation.LabelFormat.RATIO
        labelVerticalPosition = FibonacciRetracementAnnotation.LabelVerticalPosition.ABOVE
    
        // Optional: Customize the rubber-band preview line shown while placing the points
        rubberBandStroke = SolidPenStyle(Color.WHITE, true, 1.5f, floatArrayOf(5f, 5f))
    
        // Optional: Set a listener to be notified when an annotation is created
        setAnnotationCreationListener { newAnnotation ->
            // Configure the newly created annotation if needed
            newAnnotation.setIsEditable(true)
        }
    }
    
    // Add the modifier to the surface
    surface.chartModifiers.add(fibonacciCreationModifier)
    

    Customizing the Modifier

    The FibonacciRetracementAnnotationCreationModifier is designed for extensibility. You can customize its behavior by extending it and overriding its protected methods:

    Method Description
    createAnnotation(Context) Replace the annotation type, or apply custom levels, colors and styling to every created annotation.
    createRubberBandAnnotation(Context) Replace the rubber-band preview annotation type.
    configureRubberBandAnnotation(IAnnotation) Configure the rubber-band annotation after creation.
    updateRubberBandEndPoint(PointF) Change how the rubber-band tracks the finger.
    removeRubberBandAnnotation() Clean up the rubber-band annotation.
    onAnnotationCreated(IAnnotation) React to annotation completion.

    The base implementation of createAnnotation already applies the modifier's three label properties, so call super.createAnnotation(context) first and then apply your own customizations on top:

    • Java
    • Kotlin
    // Define a custom FibonacciRetracementAnnotationCreationModifier
    private static class CustomFibonacciRetracementAnnotationCreationModifier extends FibonacciRetracementAnnotationCreationModifier {
        @Override
        protected FibonacciRetracementAnnotation createAnnotation(Context context) {
            final FibonacciRetracementAnnotation annotation = super.createAnnotation(context);
    
            // Apply a custom set of Fibonacci levels to every annotation created by this modifier.
            // Note the label properties of the modifier have already been applied by super
            annotation.setLevels(Arrays.asList(0d, 0.382, 0.618, 1d));
            annotation.setFillOpacity(0.2f);
    
            return annotation;
        }
    
        @Override
        protected void configureRubberBandAnnotation(IAnnotation annotation) {
            super.configureRubberBandAnnotation(annotation);
    
            // Customize the rubber-band styling
            if (annotation instanceof LineAnnotation) {
                ((LineAnnotation) annotation).setStroke(new SolidPenStyle(Color.YELLOW, true, 2f, new float[]{10, 5}));
            }
        }
    
        @Override
        protected void onAnnotationCreated(IAnnotation newAnnotation) {
            super.onAnnotationCreated(newAnnotation);
    
            // Custom logic after annotation is fully created
            newAnnotation.setIsEditable(true);
        }
    }
    
    void useCustomFibonacciRetracementAnnotationCreationModifier(@NonNull SciChartSurface surface) {
        // Use the custom modifier
        final CustomFibonacciRetracementAnnotationCreationModifier customModifier = new CustomFibonacciRetracementAnnotationCreationModifier();
    
        surface.getChartModifiers().add(customModifier);
    }
    
    // Define a custom FibonacciRetracementAnnotationCreationModifier
    private class CustomFibonacciRetracementAnnotationCreationModifier : FibonacciRetracementAnnotationCreationModifier() {
        override fun createAnnotation(context: Context): FibonacciRetracementAnnotation {
            val annotation = super.createAnnotation(context)
    
            // Apply a custom set of Fibonacci levels to every annotation created by this modifier.
            // Note the label properties of the modifier have already been applied by super
            annotation.levels = listOf(0.0, 0.382, 0.618, 1.0)
            annotation.fillOpacity = 0.2f
    
            return annotation
        }
    
        override fun configureRubberBandAnnotation(annotation: IAnnotation) {
            super.configureRubberBandAnnotation(annotation)
    
            // Customize the rubber-band styling
            if (annotation is LineAnnotation) {
                annotation.stroke = SolidPenStyle(Color.YELLOW, true, 2f, floatArrayOf(10f, 5f))
            }
        }
    
        override fun onAnnotationCreated(newAnnotation: IAnnotation) {
            super.onAnnotationCreated(newAnnotation)
    
            // Custom logic after annotation is fully created
            newAnnotation.setIsEditable(true)
        }
    }
    
    fun useCustomFibonacciRetracementAnnotationCreationModifier(surface: SciChartSurface) {
        // Use the custom modifier
        val customModifier = CustomFibonacciRetracementAnnotationCreationModifier()
    
        surface.chartModifiers.add(customModifier)
    }
    
    Note

    To learn more about other Annotation Types, available out of the box in SciChart, please find the comprehensive list in the Annotation APIs article.

    Back to top © 2011-2025 SciChart. All rights reserved. | sitemap.xml