Daily MA7 on smaller timeframeView all attachments
04/08/2019 at 3:45 PM #95729
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??04/08/2019 at 4:09 PM #95734
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?04/08/2019 at 4:19 PM #9573504/08/2019 at 4:21 PM #95736
“So you want a seven period average of the closing price at 1735?”
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 calculation04/08/2019 at 4:29 PM #95741
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!?04/08/2019 at 4:43 PM #95747
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 one04/08/2019 at 4:49 PM #95748
So now I have a bit modified your code, I need to check if this is correct123456789101112131415161718192021222324252627282930if time = 173500 and (currenttime<090000 or currenttime>173500) thena = bb = cc = dd = ee = ff = gg= closeendifif time = 173500 and (currenttime>=090000 and currenttime< 173500) thena = bb = cc = dd = ee = ff = closeendifif (currenttime>=090000 and currenttime< 173500) theng= closeendifif a <> 0 thenave = (a + b + c + d + e + f + g) / 7elseave = undefinedendifreturn ave04/08/2019 at 5:02 PM #9574904/08/2019 at 5:03 PM #95750
Maybe you mean something like this?12345678910111213141516if time = 173500 thena = bb = cc = dd = ee = ff = closeendifif a <> 0 thenave = (a + b + c + d + e + f + close) / 7elseave = undefinedendifreturn ave
1 user thanked author for this post.04/08/2019 at 5:26 PM #9575204/08/2019 at 5:41 PM #95753
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:1return time as "time", opentime as "opentime"