Announcement

Collapse
No announcement yet.

using getInterval() with SMA question

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

  • using getInterval() with SMA question

    Hi,

    When plotting a sma by hard-coding the time interval, I have no issues with what is returned. Works great.

    When I try to plot the same sma using getInterval(), I get contracted, wierd compressed data points.

    My objective is to grab the interval and use it to plot the sma, so that when the user changes the display interval of a chart, the sma will update and redraw automatically based on the new time parameters.

    Any help would be appreciated.

    [BTW - is there a simple way to attach a .png file so I could show you what I mean? ]

    Ryan.

    PHP Code:
    var cStudyTitle "TickMA";


        var 
    gInt getInterval();

    //    var vTickSMA = sma(13, sym("$Tick,15"));          // *** this works fine ***
    //    var vTickInst  = sma(1, sym("$Tick,15"));

        
    var vTickSMA sma(13sym("$Tick,gInt"));          // *** this does not  ***
        
    var vTickInst  sma(1sym("$Tick,gInt"));

        var 
    bInt false;
        
        var 
    fpArray = new Array();
        
        
    function 
    preMain() {

        
    debugClear();

        
    setComputeOnClose(true)
        
    setPriceStudy(false);
        
    setStudyTitle(cStudyTitle);
        
    setShowCursorLabel(true);
        
    setShowTitleParameters(false);


        
    setCursorLabelName("Tick"0);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(30);
        
    setPlotType(PLOTTYPE_LINE0);

        
    setCursorLabelName("TickInst"1);
        
    setDefaultBarStyle(PS_DOT1);
        
    setDefaultBarFgColor(Color.green1);
        
    setDefaultBarThickness(21);
        
    setPlotType(PLOTTYPE_LINE1);

    }

    function 
    main() {
       
        if(!
    bInt) {

        
    //       debugClear();
          
    bInt true;
            
        }
     
        var 
    Tick vTickSMA.getValue(0);
        if (
    Tick == null) return;
        
        var 
    TickInst vTickInst.getValue(0);
        if (
    TickInst == null) return;



    return new Array (
    TickTickInst);



  • #2
    Re: using getInterval() with SMA question

    Ryan
    The error is in these two lines of code
    var vTickSMA = sma(13, sym("$Tick,gInt"));
    var vTickInst = sma(1, sym("$Tick,gInt"));

    that should instead be
    var vTickSMA = sma(13, sym("$Tick,"+gInt));
    var vTickInst = sma(1, sym("$Tick,"+gInt));

    That said you do not need to pass the interval if this is the same as that of the chart IOW you could write those two lines as follows
    var vTickSMA = sma(13, sym("$Tick"));
    var vTickInst = sma(1, sym("$Tick"));

    Alex


    Originally posted by rdehavelyn
    Hi,

    When plotting a sma by hard-coding the time interval, I have no issues with what is returned. Works great.

    When I try to plot the same sma using getInterval(), I get contracted, wierd compressed data points.

    My objective is to grab the interval and use it to plot the sma, so that when the user changes the display interval of a chart, the sma will update and redraw automatically based on the new time parameters.

    Any help would be appreciated.

    [BTW - is there a simple way to attach a .png file so I could show you what I mean? ]

    Ryan.

    PHP Code:
    var cStudyTitle "TickMA";


        var 
    gInt getInterval();

    //    var vTickSMA = sma(13, sym("$Tick,15"));          // *** this works fine ***
    //    var vTickInst  = sma(1, sym("$Tick,15"));

        
    var vTickSMA sma(13sym("$Tick,gInt"));          // *** this does not  ***
        
    var vTickInst  sma(1sym("$Tick,gInt"));

        var 
    bInt false;
        
        var 
    fpArray = new Array();
        
        
    function 
    preMain() {

        
    debugClear();

        
    setComputeOnClose(true)
        
    setPriceStudy(false);
        
    setStudyTitle(cStudyTitle);
        
    setShowCursorLabel(true);
        
    setShowTitleParameters(false);


        
    setCursorLabelName("Tick"0);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(30);
        
    setPlotType(PLOTTYPE_LINE0);

        
    setCursorLabelName("TickInst"1);
        
    setDefaultBarStyle(PS_DOT1);
        
    setDefaultBarFgColor(Color.green1);
        
    setDefaultBarThickness(21);
        
    setPlotType(PLOTTYPE_LINE1);

    }

    function 
    main() {
       
        if(!
    bInt) {

        
    //       debugClear();
          
    bInt true;
            
        }
     
        var 
    Tick vTickSMA.getValue(0);
        if (
    Tick == null) return;
        
        var 
    TickInst vTickInst.getValue(0);
        if (
    TickInst == null) return;



    return new Array (
    TickTickInst);


    Comment


    • #3
      Alexis... that did it. Thanks very much for you help.

      We all appreciate your invaluable tutelage and the time / energy you direct towards helping members of this forum.

      Thank-you!

      Regards,
      Ryan.

      Comment


      • #4
        Ryan
        You are most welcome and thank you for the appreciation
        Alex


        Originally posted by rdehavelyn
        Alexis... that did it. Thanks very much for you help.

        We all appreciate your invaluable tutelage and the time / energy you direct towards helping members of this forum.

        Thank-you!

        Regards,
        Ryan.

        Comment

        Working...
        X