Announcement

Collapse
No announcement yet.

Ratio plot with 1 and -1 as "zero line"

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

  • Ratio plot with 1 and -1 as "zero line"

    Hello,

    I am trying to plot a ratio of say A and B, where I want both '1' and '-1' to be the reference or "zero line" of the y-axis (with no y-axis difference between 1 and -1). Scaling above that line would continue up as 2,3,4 etc and below that line would continue down as -2, -3, -4, etc. There would be no '0' value in the y-axis


    Then if A>B (i.e. A=1.5 and B=1.2 so A/B = 1.25) a value of 1.25 would plot and display in the y axis - no problem there. But if B>A (i.e. A=1.2 and B=1.5) I want to plot -B/A= -1.25 where the +1.25 and -1.25 values are the same distance of only (+.25 and -.25) from the reference line.

    I can get the positive side of this to work with the setHistogramBase(1.0) command, but then the -ve values will not plot.

    Is there a way to set both 1 and -1 as the "zero line" in a chart?

    Thanks
    shaeffer

  • #2
    The only way I can think that you can get this to work is to subtract (or add) 1.0 to the final value calculated, then plot the final value.

    Something like this (a pre-processor) may help.


    PHP Code:

    var preAB A/B;
    var 
    preBA B/A;

    if (
    preAB >= 1.0) {
      
    preAB preAB-1;
    } else {
      
    preAB 0;
    }

    if (
    preBA <= -1.0) {
      
    preBA preBA 1;
    } else {
      
    preBA 0;

    The intent is to manipulate the final result of your study so that it accomplishes your goal.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thanks for the reply, Brad,

      Using the +1 and -1 adjustments as you suggested gets me the continuous linear y-axis scale with no plotted values between +1 and -1. I ended up using a whole mess of drawTextAbsolute commands to then to create a y-axis scale to match (where -1 and +1 are the same Y value). Hopefully all those commands have negligible CPU load.

      Thanks again
      shaeffer

      Comment


      • #4
        well then, next you need to consider the "reset conditions" that will reset your control system to ZERO.

        What would make that happen?
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Originally posted by Doji3333
          well then, next you need to consider the "reset conditions" that will reset your control system to ZERO.

          What would make that happen?
          Hi Brad,
          I'm sorry, I don't understand your question. The code I had actually used, for which I wanted a 'matching Y-axis' was:
          PHP Code:
          if (>= B){ 
                
          vRatio = (A/B)-1;
          }else{
                
          vRatio 1-(B/A);

          The purpose of adding the '-1' and '1-' above was so no values between 1 or -1 would appear on the chart, so for example, the difference between 1.25 and 1.75 would look the same on the chart as the difference between 1.25 and -1.25.

          But because I added the '-1' and '1-', the values appearing in the y-axis would be out by +1 or -1. Since it seems there is no way to 'cut out' the -1 to +1 piece of the y-axis, I created such a y-axis with all the drawTextAbsolute commands.

          So, I'm not sure if the above answers your question, 'cause I don't understand the question. But there should never be any zero value appearing in my chart.

          Regards
          shaeffer

          Comment


          • #6
            ok. Well let me try to help.

            Maybe you could subtract 1 or add 1 from/to the value if the value is greater than 1 or less than one. This would give you a return of 0 (if between one and neg one) or greater/less than zero if greater or less than one.

            It take the same logic (basically).

            PHP Code:

            if ((returnvalue 1) || (returnvalue > -1)) {
              
            returnvalue 0;
            } else if (
            returnvalue >= 1) {
              
            returnvalue -=1;
            } else if (
            returnvalue <= -1) {
              
            returnvalue +=1;

            Brad Matheny
            eSignal Solution Provider since 2000

            Comment


            • #7
              Hi Brad,

              I'm going to try out your code this weekend, but meanwhile, on this particular chart (histogram), the most -ve bar always hits (or is maybe exceeding?) the bottom of my chart window. However, the +ve histo bars maintain the little gap from the top of the chart window, as with all other charts.

              Any idea why those -ve histo bars are not maintaining the little gap at the bottom of the chart window?

              I've got autoscaling on. Changing the top/bottom margin offsets in Properties does not seem to make a difference.

              Regards
              shaeffer

              Comment


              • #8
                nope, without seeing your code and seeing exactly what you are experiencing, I can't offer a solution. All I can tell you is if you are trying to display two values in the histogram, then you should be using..

                return new Array (item1, item2);

                This should create both items in your histogram and autoscale it properly.

                B
                Brad Matheny
                eSignal Solution Provider since 2000

                Comment

                Working...
                X