Moving Average Daily

Moving Average Daily
At this stage ProRealtime doesn't have multi timeframe capabilities. However one easy possibility is to use the moving average of the daily timeframe with the options of DOpen, DHigh, DLow, DClose and that's what this indicator enables you to do. You can select the number of periods ie. Days: number of periods/days (please note there's a limit depending on the timeframe you use this on and there's a difference between PRT and IG data periods) open/high/low/close, etc... If you are going to use this in a live trading account you will need to set: DEFPARAM Preloadbars = Here is the table of how much Preloadbars you will need depending how many periods you want to look back.  The column max days shows the maximum of what you can set Preload to.

As an example of you are using a 10 minute timeframe the maximum DEFPARAM Preloadbars = 5000 // maximum is 5000 and this is equal to the moving average of 35 days.

DEFPARAM Preloadbars =
60 24 5000
Minutes bars per hour bars per day max days
1 60 1440 3
5 12 288 17
10 6 144 35
15 4 96 52
30 2 48 104
60 1 24 208

You should find this indicator useful if you are trading mean reversion system and want to make an entry a timeframe less than the daily while using the daily moving average as the mean.

REMINDER: if you want the indicator to appear in the Price section of the chart, you must add it by clicking on the spanner icon on the little Price tab in the Price window.

// Please note if you're using IG there's a smaller number of days you can use and the smaller the timeframe the small number of days you can use
periods = p // days

LMA=0 // Loop MA
FOR i = 0 TO periods-1 DO  // Need -1 so the Result is the number of periods we actually want
 LMA = DClose(i) + LMA // Don't think this is possible CustomClose[(i)]

LMAactual = (LMA / (periods))

RETURN LMAactual AS "Daily MA"
Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

New! PRC is also now on YouTube, subscribe to our channel for exclusive content and tutorials

  1. Nicolas • 70 days ago #

    Thanks a lot, a lot of people will find it useful!

    About customclose of the daily OHLC, you could have compute them this way: (totalprice for instance)

    LMA = ((DOpen(i)+DHigh(i)+DLow(i)+DClose(i))/4) + LMA


  2. David • 39 days ago #

    Unfortunately the PRT is unreliable. 

    I made a simple 7 day moving average crosses over 30 day moving average but
    Pro Realtime opens position even though there’s no cross over.

    I tried to provide a screenshot but I keeping getting a HTTP error.

    • Nicolas • 39 days ago #

      Did you change trading hours or weekends data of the tested instruments? Calculate the daily moving average like the author do it in this code means a lot of preloaded bars, did you adapt this parameter correctly? 

    • David • 38 days ago #

      Nicolas, I wrote the code and I have DEFPARAM Preloadbars = 3000 on m60 so that’s plenty of preloadbars.

      As far as I know I didn’t change the weekend data of FX. But the drawn moving average lines do not cross many times but the position open and they should not open. So no one else is having this issue?

      I am running the Demo of 10.3 via IG so maybe that’s having an issue?


    • Nicolas • 38 days ago #

      How do you call this indicator in you trading strategy code? Did you make a CALL? Have you tried to GRAPH the returned variables of the indicators while backtesting?

    • David • 37 days ago #

      I’m using the call function. I checked again and it seems okay now on Demo and Live testing. Luckily I took a screen shot otherwise I wouldn’t believe that there was an entry issue as per my initial comment. 

  3. David • 3 days ago #

    Nicolas I’ve looked at it again and there’s a problem. 

    As an example here’s a simple cross over system and you can see the entry and exit is not at the cross over. It’s even worse if you use <> for the daily moving averages for the BUY. I made 2 instances of the indicator and Call the indicators Moving Average Daily with DHigh and DLow. I’m still having HTTP error when trying to upload a screen shot. Here’s a screenshot 

    I look forward to hearing what results you have Nicolas. 


    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    // Conditions to enter long positions
    indicator1 = CALL "Moving Average Daily HIGH"[14]
    indicator2 = CALL "Moving Average Daily LOW"[50]
    c1 = (indicator1 CROSSES OVER indicator2)
    IF c1 THEN
    // Conditions to exit long positions
    indicator3 = CALL "Moving Average Daily HIGH"[14]
    indicator4 = CALL "Moving Average Daily LOW"[50]
    c2 = (indicator3 CROSSES UNDER indicator4)
    IF c2 THEN




    • Nicolas • 3 days ago #

      You’ll need to preload bars to get the good calculations of you indicators. I did not test it myself though. 

  4. David • 3 days ago #

    Nicolas I tried
    DEFPARAM Preloadbars = 5000

    And still the same drawn output of entries/exits not at the drawn Cross Over  around 2 days earlier than the drawn Cross Over /Cross Under. 

Register or


avatar avatar avatar avatar
Related users ' posts
Sofitech Ce code n'est valable que sur la V10.3 ? sur le 10.2 il y a une erreur de syntaxe dans le fi...
Nicolas Oui en effet, c'est un indicateur "10.3" à cause uniquement de la mise en forme des courbes ...
2 months ago
Holt EMA
Holt EMA
supertiti Voici un code de VIDYA construit par Sohocool : // MOYENNE EXPONENTIELLE ADAPTIVE VIDYA by ...
Matriciel Merci Supertiti. Je trouve que ce code est difficile à règler et n'est pas d'une grande pré...
Ernesto1 J'ai essayé avec deux différents I ,  a =  3 périodes et un 3 x 5 = 15 périodes.Ie comme si ...
3 months ago
SoloContado Hello Nicolas,   thanks a lot for your many contributions in this post. I have a prob...
Nicolas Because of no data available at the start of calculations. Add this at line 15 : if barindex...
luigi Ciao Nicolas. Approfitto di questo spazio per chiederti se puoi aiutarmi. Avrei bisogno di u...
Nicolas Si prega di utilizzare i forum per chiedere richieste di codice per favore.
Wilko Hi Nicolas!, Thanks for providing code for the FRAMA! If I have understood correctly, one s... HELP, WHY DONT I NOT GOT THE INDICATOR IN CHART. JUST UNDER?????????????
Nicolas Use the wrench on the upper left side of your price chart to add correctly indicator on PRICE.
Nicolas @Renato I have this code in my indicators list since a while and honestly I don't remember ...
Renato Di Lorenzo Agree; thanks.
rpreviteri Hi Nicolas, thanks a  loto for sharing your knowliedge, Wasn't the original momentum pinball...
gianlox I added a simple momentum indicator (MACD). I think much better results:   achat = 0v...
gianlox achat = 0 vente = 0 MACD12M = MACDline[12,26,9](close) MACD12S = ExponentialAverage[9](MA...
Somatolysis   Hi IGOSNELL, you´ll find other of my strategies here - but without the code - maybe...
IGOSNELL Thanks but unfortunately can't read German. If you can show that your strategies can work on...
Nicolas Thank you for contribution. Please consider that advertising is tolerate as long as you cont...
Dimi.A Perfect for counter-trend scalping. I like this!
finplus Bonjour, j'ai retesté hier sur la paire AUD/USD timeframe 1 heure sur mon compte réel chez I...
finplus Bonsoir, j'ai de nouveau aujourd'hui lancé la stratégie en réel sur mon compte IG sur la pai...
AleX 0 improvments, I tried a lot of modified version but no one was working. I think that only w...
leyoy Bonjour, je viens de l'installer sur 10.3 ... comment faire apparaitre les flèches sur l'ind...
Nicolas Les flèches apparaissent d'elles-mêmes selon les signaux de l'indicateur.
leyoy Elles viennent d'apparaitre après redémarrage. Merci Nicolas. Du coup, les signaux sont à pr...
Nicolas Ok Doc, beware of intraday, it's a battlefield full of random noises :) Maybe we can work to...
phili711 Bonjour Si la moyenne 100 est au dessus de la moyenne 20 le trend est baissier zlors pourqu...
Nicolas La comparaison se fait entre la valeur de la moyenne actuelle et telle qu'elle était il y a ...
jctrader Bonjour . CAC 40    1988 = 1000   today = 4900  soit 490%  en buy and hold  .... + 370% av...
Nicolas Aucune immobilisation du capital. Quel est le drawdown du buy & hold ? Je ne l'ai pas ca...
jctrader ok pour le codage mais le choix "indice" n'est pas le bon : moins de 5%/an pour le meilleur ...
DonDollar ...and I do not see any opened positions...strange...
DonDollar I found the answer by myself for the second question. But still no idea about the False and ...
Nicolas The line 12 of the code is the answer of your question. Before launching a new trade, the co...
Nicolas I do not have any error Alfredo, even while testing on 150000 bars in the past. By the way, ...
alfredo thank for the council, when i do start the strategie on Italy at 1h some mornings happen tha...
Nicolas I think it's because of price gaps and/or quote interrupt. Anyway, be aware that this strate...