Monthly (close-open), monthly timeframe

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #182929 quote
    briacbriac
    Participant
    Junior

    Hi , i am trying to do and indicator that returns me the summatory of the value (close-open) for the last 10 month but for each month separately, i mean: the last 10 januaries, the last 10 februaries, …..

    that is what i did,But it doesn´t work, i don´t know why

    Retorno = close[0]-open[0]
    
    for i=0 to 10 do
    Retorno = (close[i+12]-open[i+12]) + Retorno
    next
    
    Return Retorno
    

    Thank you very much

    #182934 quote
    JC_BywanJC_Bywan
    Moderator
    Master

    Hi, it’s because in the loop, with i+12 instead of i*12 you’re adding all the consecutive months before the one 12 ago instead of “jumping” every 12 months + with 0 to 10 you’re adding that 11 times instead of 9 times to first one to make a total of 10 + you’re counting current candle’s retorno several times inside the loop.

    Let’s try with this one to display on a monthly timeframe each month the sum of same-name 10 months as current month + previous same-name 9 one’s

    x=close[0]-open[0]
    y=0
    Retorno=0
    
    if barindex>120 then// wanting at least 10 times 12 months in history
    
     for i=1 to 9 do
      y = x[i*12] + y // y intermediate calculation of the 9 times before (close-open)
     next
    
     Retorno= y+x// adding y to current close-open
    
    endif
    
    return Retorno as "Retorno",0
    #182953 quote
    briacbriac
    Participant
    Junior

    Now is perfect, thank you very much, my idea was the following

    x=(close[0]*100/open[0])-100 // (close-open)%
    y=0
    Retorno=0
     
    if barindex>120 then
     
    for i=1 to 9 do
    y = x[i*12] + y // y intermediate calculation of the 9 times before (close-open)
    next
     
    Retorno= y+x// adding y to current close-open
     
    endif
    
    RetornoMedio = Retorno/10 //average
     
    return RetornoMedio ,0
    

    An indicator that returns the average of (close-open)% of the last 10 months (for each month) to do seasonality studies for stocks.

    Thanks again

    JC_Bywan thanked this post
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Monthly (close-open), monthly timeframe


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
briac @briac Participant
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/07/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...