Announcement

Collapse
No announcement yet.

EMA and SMA formula error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • EMA and SMA formula error

    Just tried my hand to write an indicator / formula. Unfortunately it is not showing on a forex chart. Any suggestions towards solution would be highly appreciated.

    Indicator: Moving Average 200E - Moving Average 200S

    var study = new MAStudy(1, 0, "Close", MAStudy.EXPONENTIAL);
    var study = new MAStudy(1, 0, "Close", MAStudy.SIMPLE);


    function preMain()

    {
    setPriceStudy(true);
    setStudyTitle("EMA-SMA200");
    setCursorLabelName("SEMA-SMA200",0);
    setDefaultBarFgColor(Color.red,0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);

    }

    function main() {

    return(ema(200) - sma(200));
    }

    Many thanks in advance,
    Magda

  • #2
    Re: EMA and SMA formula error

    Magda
    First of all you do not need the first two lines of code in your script ie
    var study = new MAStudy(1, 0, "Close", MAStudy.EXPONENTIAL);
    var study = new MAStudy(1, 0, "Close", MAStudy.SIMPLE);

    since you are not using those functions. This is because you are calling the EFS2 functions for those studies directly in the return statement ie
    return(ema(200) - sma(200));
    Secondly make sure that you have at least 200 bars of data loaded in the chart else you will not see a plot. Those studies require a minimum of 200 bars before they begin plotting. As far as I can see at my end the study is working.
    Lastly you may want to set that formula as a non-priice study rather than a price study. To do that either remove the statement
    setPriceStudy(true);
    or change it to
    setPriceStudy(false);
    Hope this helps
    Alex



    Originally posted by Magda
    Just tried my hand to write an indicator / formula. Unfortunately it is not showing on a forex chart. Any suggestions towards solution would be highly appreciated.

    Indicator: Moving Average 200E - Moving Average 200S

    var study = new MAStudy(1, 0, "Close", MAStudy.EXPONENTIAL);
    var study = new MAStudy(1, 0, "Close", MAStudy.SIMPLE);


    function preMain()

    {
    setPriceStudy(true);
    setStudyTitle("EMA-SMA200");
    setCursorLabelName("SEMA-SMA200",0);
    setDefaultBarFgColor(Color.red,0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);

    }

    function main() {

    return(ema(200) - sma(200));
    }

    Many thanks in advance,
    Magda

    Comment


    • #3
      Re: Re: EMA and SMA formula error

      Hi Alex,

      Thanks for your kind response. I affected the changes you suggested and it works fine now.

      Thanks a lot for your kindness I have more hope now that I will be able to write other formulas.

      Best regards,
      Magda

      Originally posted by Alexis C. Montenegro
      Magda
      First of all you do not need the first two lines of code in your script ie
      var study = new MAStudy(1, 0, "Close", MAStudy.EXPONENTIAL);
      var study = new MAStudy(1, 0, "Close", MAStudy.SIMPLE);

      since you are not using those functions. This is because you are calling the EFS2 functions for those studies directly in the return statement ie
      return(ema(200) - sma(200));
      Secondly make sure that you have at least 200 bars of data loaded in the chart else you will not see a plot. Those studies require a minimum of 200 bars before they begin plotting. As far as I can see at my end the study is working.
      Lastly you may want to set that formula as a non-priice study rather than a price study. To do that either remove the statement
      setPriceStudy(true);
      or change it to
      setPriceStudy(false);
      Hope this helps
      Alex

      Comment


      • #4
        Magda
        You are most welcome and thank you for letting me know it is working fine now
        Alex

        Comment

        Working...
        X