Problème dans la création d’un histogramme des cotations

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #195750 quote
    Denis Quéva
    Participant
    New

    Bonjour,

    Je souhaite créer un histogramme de répartition des cotations pour le Future CAC à partir d’un tableau de variables et de la fonction drawrectangle.

    Comme vous pouvez le voir sur le graphique, des rectangle sont créés sur des intervalles de cotations qui ne peuvent pas exister : les 2 traits horizontaux sont séparés de 0.5 point.

    Il ne devrait donc y avoir qu’un seul rectangle et non pas un multitude. Par ailleurs la longueur des rectangles n’est pas la même.

    Si quelqu’un a une idée sur l’origine du problème. Voici le code .

    Merci d’avance !

    Denis

     

    DEFPARAM DRAWONLASTBARONLY = true
    TIMEFRAME(default, updateonclose)
    
    // Future CAC
    // Objectif : représenter la répartition des cours (sans tenir compte des volumes) par un histogramme vertical (à droite des cours)
    // Comment : Mémoriser dans un tableau de données le nombre de fois où un cours est atteint
    // Astuce : transformer les cotations cours en nombre entier sachant que :
    //        - Intervalle de cotation 0.5 point
    //        - Nombre de décimales : 1. Donc multiplier chaque cotation par 10
    //          Exemple 6002.5 --> 60025
    //                  6001.0 --> 60010
    
    ONCE IntervalCotation = 0.5
    ONCE MultipleCotation = 10
    
    //**************************************************************************************************************************
    //On mémorise les cotations d'une bougie dans le tableau
    //**************************************************************************************************************************
    //On formate les cotations pour le tableau de données
    // round(low/IntervalCotation)*IntervalCotation : pour corriger des cotations en 0.2 (???)
    LowFormatage=round(low/IntervalCotation)*IntervalCotation*MultipleCotation
    HighFormatage=round(high/IntervalCotation)*IntervalCotation*MultipleCotation
    
    FOR iCotationFormatage = LowFormatage TO HighFormatage
    
    //Si première fois que la cotation est touchée, alors on initialise la variable Array à 1
    //Sinon on ajoute 1 au nombre de fois où la cotation a été touchée
    IF Not IsSet($NbCotations[iCotationFormatage]) THEN
    $NbCotations[iCotationFormatage] = 1
    ELSE
    $NbCotations[iCotationFormatage] = $NbCotations[iCotationFormatage] + 1
    ENDIF
    
    //Pour éviter des boucles inutiles (Pas de la boucle = 5 et non 1)
    iCotationFormatage = iCotationFormatage + (IntervalCotation*MultipleCotation)
    NEXT
    
    //**************************************************************************************************************************
    //On représente la répartition des cotations sous forme d'histogramme
    //**************************************************************************************************************************
    ONCE MinLow = LowFormatage
    ONCE MaxHigh = HighFormatage
    LowestFormatage = MIN(LowestFormatage, LowFormatage)
    HighestFormatage = MAX(HighestFormatage, HighFormatage)
    
    //IsLastBarUpdate : pour minimser les temps de calculs lors des changements d'unité de temps ou de profondeur d'historique
    IF IsLastBarUpdate THEN
    
    //On repère le maximum de fois où une cotation a été touchée. Cela servira de base 100 pour l'histogramme en %
    NbMaxCotations =  ArrayMax($NbCotations)
    
    //Création de l'histogramme de répartition en %
    //Au maximum la longueur de l'histogramme = 20
    FOR jCotationFormatage = LowestFormatage[1] TO HighestFormatage[1]
    DRAWRECTANGLE(barindex+1, jCotationFormatage/MultipleCotation-(IntervalCotation/2), barindex+1+round($NbCotations[jCotationFormatage]/NbMaxCotations*20), jCotationFormatage/MultipleCotation+(IntervalCotation/2)) Coloured(100,100,100)
    jCotationFormatage = jCotationFormatage + round(MultipleCotation*IntervalCotation)
    NEXT
    
    ENDIF
    
    RETURN
    
    PRT.jpg PRT.jpg
    #195756 quote
    Nicolas
    Keymaster
    Master

    J’ai codé quelque chose qui s’approche de cela récemment (sauf que je ne trace pas de rectangle mais une heatmap en fonction des occurrences des prix touchés): https://www.prorealcode.com/topic/historique-des-prix/#post-193758

    Je suppose que tu pourrais repartir de cette base pour afficher tes rectangles.

    Denis Quéva thanked this post
    #195844 quote
    Denis Quéva
    Participant
    New

    Merci Nicolas

    En changeant la boucle For en While ça marche parfaitement.

    #195958 quote
    Nicolas
    Keymaster
    Master

    Oui en effet car on ne peut pas changer l’incrément d’une boucle FOR/NEXT comme tu le faisais dans ton code.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Problème dans la création d’un histogramme des cotations


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Denis Quéva @deun-deun Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by Nicolas
3 years, 8 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 06/21/2022
Status: Active
Attachments: 1 files
Logo Logo
Loading...