Daily MA7 on smaller timeframe

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #95729 quote
    stefou102
    Participant
    Veteran

    Hello I’m looking to code a daily  moving average(7)  on my intraday chart. I know there has been already topics on that in the past, but the particularity here is that I would like to take the closing price of a particular time, ie 17h35 for the Dax for example, corresponding to the cash close.  Any idea how to navigate with the past dates, and avoid the problem with the weekend, the new month etc??

    #95734 quote
    Vonasi
    Moderator
    Master

    So you want a seven period average of the closing price at 1735?

    You could just store the last seven values at close of 1735 candle. Each time there is a new one drop one of the old ones and record the new one.

    Another alternative is to code a dummy MTF strategy and then use GRAPHONPRICE to draw it on your intraday chart.

    I’m not sure what weekend or change of month issues you see happening?

    #95735 quote
    Vonasi
    Moderator
    Master

    Here is the first idea:

    if time = 173500 then
    a = b
    b = c
    c = d
    d = e
    e = f
    f = g
    g = close
    endif
    
    if a <> 0 then
    ave = (a + b + c + d + e + f + g) / 7
    else 
    ave = undefined
    endif
    
    return ave
    
    #95736 quote
    stefou102
    Participant
    Veteran

    “So you want a seven period average of the closing price at 1735?”

    Yes

    seems simple but I have some difficulties in my head to work with dates.

    If you compare Date in YYYYMMDD, then rolling month complicates a bit the calculation

    #95741 quote
    Vonasi
    Moderator
    Master

    seems simple but I have some difficulties in my head to work with dates. If you compare Date in YYYYMMDD, then rolling month complicates a bit the calculation

    I don’t understand. What do dates and months have to do with it? There is only one 1735 everyday unless you have a time machine!?

    #95747 quote
    stefou102
    Participant
    Veteran

    Sorry I made my comment before seeing your code idea. I didn’t know that it was that easy and dates weren’t needed.

    Idea is good, even though what is missing is to make it more dynamic by taking the value of today into consideration. So the 6 last closes at 17h35, and the seventh value is the most current one

    #95748 quote
    stefou102
    Participant
    Veteran

    So now I have a bit modified your code, I need to check if this is correct

     

    
    
    if time = 173500 and (currenttime<090000 or currenttime>173500) then
    a = b
    b = c
    c = d
    d = e
    e = f
    f = g
    g= close
    endif
     
    if time = 173500 and (currenttime>=090000 and currenttime< 173500) then
    a = b
    b = c
    c = d
    d = e
    e = f
    f = close
    endif
    
    if (currenttime>=090000 and currenttime< 173500) then
    g= close
    endif
    
    if a <> 0 then
    ave = (a + b + c + d + e + f + g) / 7
    else
    ave = undefined
    endif
     
    return ave
    
    #95749 quote
    Vonasi
    Moderator
    Master

    Your conditions in lines 1 and 7 can never be met.

    #95750 quote
    Vonasi
    Moderator
    Master

    Maybe you mean something like this?

    if time = 173500 then
    a = b
    b = c
    c = d
    d = e
    e = f
    f = close
    endif
    
    if a <> 0 then
    ave = (a + b + c + d + e + f + close) / 7
    else 
    ave = undefined
    endif
    
    return ave
    
    stefou102 thanked this post
    #95752 quote
    stefou102
    Participant
    Veteran

    Indeed;)

    the price at 17h35 is the close price of the 17h30 candle on a 5min chart actually, so 17300 it should be for those who wish to use this little code snippet for scalping.

    #95753 quote
    Vonasi
    Moderator
    Master

    Yes OPENTIME is the time a candle opens and TIME is the time it closes. So if you want the exact price at 1735 then you can use OPEN and OPENTIME or use CLOSE and TIME. Both should return the same value unless there is a gap in price between CLOSE and OPEN.

    In a strategy TIME is used more often as decisions are made at the candle close and trades opened at the next candle open. In indicators generally OPENTIME is of more use as on the fly analysis of a candle is carried out from the moment it opens.

    I still find that sometimes I have to just put the following indicator on a chart to clarify things in my head when coding stuff:

    return time as "time", opentime as "opentime"
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.

Daily MA7 on smaller timeframe


ProBuilder support

New Reply
Author
author-avatar
stefou102 @stefou102 Participant
Summary

This topic contains 10 replies,
has 2 voices, and was last updated by Vonasi
6 years, 9 months ago.

Topic Details
Forum: ProBuilder support
Language: English
Started: 04/08/2019
Status: Active
Attachments: No files
Logo Logo
Loading...