count bars since event

Forums ProRealTime English forum ProBuilder support count bars since event

Viewing 8 posts - 1 through 8 (of 8 total)
  • #239293

    Hello, does anyone knows how to count the number of candles/bars since an event took place before the actual one. i’m trying to code and order based on 2 Ma crossing ”X ” bars/candles before the actual one /during the day .  is barindex and additional conditions usefull for that kind of code . Thanks for your help.

    #239299

    Use BarsSince (https://www.prorealcode.com/documentation/barssince/):

    Please select the correct language. I moved this topic from the French forum.

    3 users thanked author for this post.
    #239310

    Hi Roberto, I was comparing  barsSince with a basic count and got some differing results.

    The count values presented regarding the true conditions are the same.

    However, the lines plotted are different.

    It appears that barsSince counts from the last count value of the last true condition, then jumps to the correct new count value level on next true condition.

    This means the  prior value [1],[2] etc wouldn’t be representing the correct prior values of the count.

    Is this the intended operation or is there something more to it.

     

    If using a basic count , the prior values are relevant between counts for prior values.

     

     

     

    1 user thanked author for this post.
    #239320

    This code works like a charm:

     

    2 users thanked author for this post.
    #239418

    Bonjour merci pour les réponses, déjà intégrées dans le code. j’ai codé l’algo de manière à démarrer à 9h et terminer à 19h50 avec une clôture de trades ouvert automatique à 19h48 pour éviter de passer la nuit avec une position ouverte (margin broker) et voir le marché décaler dès l’ouverture.

    Le problème est (je n’ai pas trouvé la solution) que si le trend initial qui à ouvert le trade j-1 (que je ferme à 19h48 automatiquement) ne se termine pas obligatoirement à la clôture de marché et peut continuer jusqu’a deux heures du matin. Mon code est basé sur le croisement de 2 SMA (par exemple) mais si le croisement des SMA n’intervient pas à la clôture du marché mais le lendemain dans la nuit, ou juste après la réouverture du marché, je rate une partie des trades possibles dans la mesure ou l’algo attend un nouveau croisement.

    J’ai un bout de code qui utilise les condition Timeopen + not(onmarket) et SMA1 crosses over SMA2 ou SMA1 crosses under SMA2 mais cela ne fonctionne pas à la réouverture du marché avant qu’un croisement (de sma) ne se produise . Si vous avez une solution, je suis preneur..cordialement

    Hello, thank you for the answers, already integrated into the code. I coded the algo to start at 9am and end at 7:50pm with an automatic closing of open trades at 7:48pm to avoid spending the night with an open position (margin broker) and seeing the market shift as soon as it opens.

    The problem is (I haven’t found the solution) that if the initial trend that opened the trade j-1 (which I close at 7:48pm automatically) does not necessarily end at the market close and can continue until two in the morning. My code is based on the crossing of 2 SMAs (for example) but if the crossing of the SMAs does not occur at the market close but the next day during the night, or just after the market reopens, I miss some of the possible trades since the algo is waiting for a new crossing.

    I have a piece of code that uses the conditions Timeopen + not(onmarket) and SMA1 crosses over SMA2 or SMA1 crosses under SMA2 but it doesn’t work when the market reopens before a (sma) crossover occurs.
    If you have a solution, I’m interested..regards

    #239430

    You have chosen the English forum, please stick to it. Thanks 🙂

     

    #239432

    no problemo. Thanks and best regards

    #239466

    You need a variable to be used as a flag, so that when trading is off it still scans and sets its value to 1 whenever a crossover is detected. When trading resumes, you will check this flag and, if set, you can enter a trade without having to wait for the next crossover:

     

Viewing 8 posts - 1 through 8 (of 8 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login