Announcement

Collapse
No announcement yet.

help with ma offset

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

  • help with ma offset

    Hi

    Im having trouble with 9 ema with a 1 offset,

    I belive there are three ways of obtaning a ema without using a function.

    if I use these two methods, the output numbers are identical to each other

    var vEMA9_2 = new MAStudy(9, 1, "Close", MAStudy.EXPONENTIAL);
    vEMA9_2.getValue(MAStudy.MA) ;
    and
    offsetSeries(eval("ema")(9,eval(close)(sym(vSymbol ))),1);


    if i use this function the number is totally different from the above two,if I use this function realtime, it displays a number and then changes when i reload the efs

    ema(9,close(),1)

    Ive attached a script that ive written to help debug the problem
    the problem is when using

    The attached efs will write the values into a text file and output to debug, ive been using tick replays, so the data is always the same.

    Which value is correct ?, I would like to use the value produced from ema(9,close(),1) when the efs2 is reloaded as opposed to the realtime value that it spits out.

    MASTUDY EMA(9,etc) offsetSeries
    values produced realtime
    5 1539 767.5974565 767.8143721 767.5974565
    values produced after reload
    5 1539 767.5974565 767.7543721 767.5974565


    the mastudy and offset series data remains the same after a reload but as you see the ema does not, the data

    This may be a bug in esignal ??
    Last edited by biswar; 04-06-2006, 04:44 AM.

  • #2
    attching efs

    efs attached
    Attached Files

    Comment


    • #3
      biswar
      This is not a bug. In your first two examples the parameter you are using to displace the average is an offset so positive numbers offset a plot forward (and negative numbers offset it backwards).
      In the third example ie ema(9,close(),1) the last parameter is the bar index which means you are addressing one bar in the future and in effet displacing the plot backwards by 1 bar (ie the same as you would get if using a negative offset). If you want this to be the same as in the first two examples you need to use a negative bar index value
      Alex

      Comment


      • #4
        Thanks for clearing that up Alexis

        I would like to use the value outputted by
        ema(9,close(),1)

        However it only is accurate when reloaded, and it outputs a different number realtime.

        Is this normal ?

        Thanks

        Bob

        Comment


        • #5
          Bob
          That is normal. The formula engine only updates a plot that is displaced backwards when this is returned as an offsetSeries(). In your case you would use a negative offset eg -1 (see example below)
          Alex

          PHP Code:
          var myVar null

          function main(){

              if(
          myVar==nullmyVar ema(9,close());
              
              return 
          offsetSeries(myVar,-1);

          Comment


          • #6
            Bob
            If for whatever reason you do not want to use the offsetSeries() function then you need to update the plot yourself using the setBar() function. If you run a search for negative offset you will find several threads on the subject.
            Also you need to consider that plots with negative offsets are "forward looking" and can provide unrealistic results when used improperly.
            Alex

            Comment


            • #7
              Thanks Alexis

              What i would like to do is show the crossover of

              ema(9,close(),1)
              ema(9,close())

              the crossover of these looks great, but i cannot script it to plot exactly the same realtime and when its reloaded.

              this should only compute on the close, so it should generate a plot on the close of the bar.

              Can you please advise on how to use this properly.

              Comment


              • #8
                Bob
                You still intialize the study as I showed you in my prior reply after which you declare a local variable which you use to retrieve the offset series (rather than returning it directly).
                Once you have done that you can create your conditions since you now have both the non-offset and offset series. Note that the conditions need to look back at the prior bar since you are applying a negative offset (ie there is no value for the offset series on the current bar)
                Alex

                PHP Code:
                ...
                if(
                myVar==nullmyVar ema(9,close());
                var 
                myOffsetVar offsetSeries(myVar,-1);
                if(
                myVar.getValue(-1) > myOffsetVar.getValue(-1)){
                //execute commands
                }else {
                ... 

                Comment

                Working...
                X