How to count numberof instances in last 20 trading days

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #153750 quote
    Alfy
    Participant
    Average

    Hi guys, i have a code for distribution days below and i would like the code to calculate how many times in the last 20 trading days the condition is fulfilled. Can anyone help please?

    thanks in advance

    a=close
    b=close[1]
    c=volume
    d=volume[1]
    e=((a-b)/b)*100
    j= high - low
    IF e<-0.1 and C>D OR E<0.1 AND A<0.25*J AND C>D THEN
    g=1
    else
    g=0
    ENDIF
    RETURN G COLOURED (255,0,0)
    #153753 quote
    fifi743
    Participant
    Master
    ONCE count=0
    a=close
    b=close[1]
    c=volume
    d=volume[1]
    e=((a-b)/b)*100
    j= high - low
    IF e<-0.1 and C>D OR E<0.1 AND A<0.25*J AND C>D THEN
    g=1
    count=count+1
    else
    g=0
    ENDIF
    RETURN G COLOURED (255,0,0),count

    counts each time G=1

    Alfy thanked this post
    #153792 quote
    Vonasi
    Moderator
    Master

    Alfy – Please follow the forum rules in any future posts and use the ‘Insert PRT Code’ button whenever you put code in your posts. I edited your post to tidy it up! 🙂

    Alfy thanked this post
    #153794 quote
    Alfy
    Participant
    Average

    First of all, thanks so much for your help. What I was trying to do was count how many times cumulatively G=1 in the last rolling 20 day period. Eyeballing it, currently we have had 3 occasions in the last 20 trading days when G=1 however your code shows only 1 occasion.

    Best regards

    #153801 quote
    Nicolas
    Keymaster
    Master

    You can make a summation of G for a rolling period with SUMMATION:

    a=close
    b=close[1]
    c=volume
    d=volume[1]
    e=((a-b)/b)*100
    j= high - low
    IF e<-0.1 and C>D OR E<0.1 AND A<0.25*J AND C>D THEN
    g=1
    else
    g=0
    ENDIF
    RETURN G COLOURED (255,0,0),summation[20](g)
    GraHal and Alfy thanked this post
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

How to count numberof instances in last 20 trading days


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Alfy @alfy Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/14/2020
Status: Active
Attachments: No files
Logo Logo
Loading...