oscillator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Cunningham

    oscillator

    I have written this ob/os oscillator for securities analysis. The only
    thing is that the result is always negative. Such as -96. I have looked over
    and over this code and it looks fine to me. Is there any trouble?

    #include <stdio.h>
    #include <stdlib.h>

    double os(double price,double ma)
    { double os;
    os=price-ma/ma*100;
    return os;
    }
    int main(int argc,char *argv[])
    { if (argc!=3)
    {fprintf(stderr ,"usage error\n");
    exit(EXIT_FAILU RE);
    }
    double price,ma;
    price=strtod(ar gv[1],NULL);
    ma=strtod(argv[2],NULL);
    printf("%f.2\n" ,os(price,ma));
    return 0;
    }

    Thanks.


  • Walter Roberson

    #2
    Re: oscillator

    In article <lCg2k.548$8q2. 269@trnddc02>,
    Bill Cunningham <nospam@nspam.c omwrote:
    I have written this ob/os oscillator for securities analysis. The only
    >thing is that the result is always negative. Such as -96. I have looked over
    >and over this code and it looks fine to me. Is there any trouble?
    >double os(double price,double ma)
    >{ double os;
    os=price-ma/ma*100;
    return os;
    >}
    When ma is a double, ma/ma is always going to be 1 (unless ma is 0
    or infinity or NaN), so your os routine is always going to return
    price - 100 .

    *Possibly* you meant something like, os = (price - ma) / ma * 100; ??

    --
    "Any sufficiently advanced bug is indistinguishab le from a feature."
    -- Rich Kulawiec

    Comment

    • Bill Cunningham

      #3
      Re: oscillator


      "Walter Roberson" <roberson@ibd.n rc-cnrc.gc.cawrote in message
      news:g2c507$937 $1@canopus.cc.u manitoba.ca...
      When ma is a double, ma/ma is always going to be 1 (unless ma is 0
      or infinity or NaN), so your os routine is always going to return
      price - 100 .
      >
      *Possibly* you meant something like, os = (price - ma) / ma * 100; ??
      >
      Ah I see. Thanks much Walter. That must be the problem. Not quite used
      to all C's parenthesis yet :)

      Bill


      Comment

      • Keith Thompson

        #4
        Re: oscillator

        "Bill Cunningham" <nospam@nspam.c omwrites:
        I have written this ob/os oscillator for securities analysis. The only
        thing is that the result is always negative. Such as -96. I have looked over
        and over this code and it looks fine to me. Is there any trouble?
        >
        #include <stdio.h>
        #include <stdlib.h>
        >
        double os(double price,double ma)
        { double os;
        os=price-ma/ma*100;
        return os;
        }
        int main(int argc,char *argv[])
        { if (argc!=3)
        {fprintf(stderr ,"usage error\n");
        exit(EXIT_FAILU RE);
        }
        double price,ma;
        price=strtod(ar gv[1],NULL);
        ma=strtod(argv[2],NULL);
        printf("%f.2\n" ,os(price,ma));
        return 0;
        }
        I don't know what an "ob/os oscillator" is, or what it's supposed to do.

        Show us one or more examples of arguments passed to the program, the
        output it produces, and the output you expected (and *why* you
        expected that particular output).

        And please fix your code formatting. Run it through "indent" if you
        must.

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        Nokia
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        • Bill Cunningham

          #5
          Re: oscillator

          [snip]
          >>double os(double price,double ma)
          >>{ double os;
          > os=price-ma/ma*100;
          > return os;
          >>}
          >
          When ma is a double, ma/ma is always going to be 1 (unless ma is 0
          or infinity or NaN), so your os routine is always going to return
          price - 100 .
          >
          *Possibly* you meant something like, os = (price - ma) / ma * 100; ??
          >
          Also for some reason though I have printf("%f.2\n" ... in my code I get
          numbers like this

          44.000000.2

          There must be something else broken.

          Bill


          Comment

          • Bill Cunningham

            #6
            Re: oscillator


            "Keith Thompson" <kst-u@mib.orgwrote in message
            news:lny75ib9xe .fsf@nuthaus.mi b.org...
            I don't know what an "ob/os oscillator" is, or what it's supposed to do.
            overbought/oversold oscillator. price of security -ma or moving
            average/moving average *100. The formula produces buy and sell signals for
            things like stocks.
            Show us one or more examples of arguments passed to the program, the
            output it produces, and the output you expected (and *why* you
            expected that particular output).
            >
            And please fix your code formatting. Run it through "indent" if you
            must.
            Oh yes forgot to run it through.


            Comment

            • Keith Thompson

              #7
              Re: oscillator

              "Bill Cunningham" <nospam@nspam.c omwrites:
              [snip]
              >
              >>>double os(double price,double ma)
              >>>{ double os;
              >> os=price-ma/ma*100;
              >> return os;
              >>>}
              >>
              >When ma is a double, ma/ma is always going to be 1 (unless ma is 0
              >or infinity or NaN), so your os routine is always going to return
              >price - 100 .
              >>
              >*Possibly* you meant something like, os = (price - ma) / ma * 100; ??
              >>
              Also for some reason though I have printf("%f.2\n" ... in my code I get
              numbers like this
              >
              44.000000.2
              >
              There must be something else broken.
              "%f" specifies the format used to print the argument. The ".2"
              following it is just plain text that's printed normally. So
              you're printing a lvaue in "%f" format:
              44.000000
              immediately followed by
              .2

              Try "%.2f".

              And you get numbers like that *with what inputs*? See my other
              message.

              --
              Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
              Nokia
              "We must do something. This is something. Therefore, we must do this."
              -- Antony Jay and Jonathan Lynn, "Yes Minister"

              Comment

              • Bill Cunningham

                #8
                Re: oscillator


                "Keith Thompson" <kst-u@mib.orgwrote in message
                news:lny75ib9xe .fsf@nuthaus.mi b.org...

                [snip]
                Show us one or more examples of arguments passed to the program, the
                output it produces, and the output you expected (and *why* you
                expected that particular output).
                >
                os 4 5 result -20
                os 5 4 result 25
                os 25 35 result -28.57

                It seems to be working pretty well now. The results seem to be correct.

                Bill


                Comment

                • Richard

                  #9
                  Re: oscillator

                  "Bill Cunningham" <nospam@nspam.c omwrites:
                  "Walter Roberson" <roberson@ibd.n rc-cnrc.gc.cawrote in message
                  news:g2c507$937 $1@canopus.cc.u manitoba.ca...
                  >
                  >When ma is a double, ma/ma is always going to be 1 (unless ma is 0
                  >or infinity or NaN), so your os routine is always going to return
                  >price - 100 .
                  >>
                  >*Possibly* you meant something like, os = (price - ma) / ma * 100; ??
                  >>
                  Ah I see. Thanks much Walter. That must be the problem. Not quite used
                  to all C's parenthesis yet :)
                  >
                  Bill
                  Might I suggest you not posting until you understand what is potentially
                  the easiest thing in C to understand. Or alternatively stop
                  trolling. Read other peoples code and learn to indent and use your
                  braces clearly and consistently.

                  While I have a lot of time for people who really want to learn your
                  continual posts show you rarely, if ever, listen to what is told to you
                  and the ridiculously poor quality of your code suggests that you must be
                  trolling.

                  Comment

                  • Bill Cunningham

                    #10
                    Re: oscillator


                    "Richard" <rgrdev@gmail.c omwrote in message
                    news:g2c9l9$9jh $2@registered.m otzarella.org.. .
                    Might I suggest you not posting until you understand what is potentially
                    the easiest thing in C to understand. Or alternatively stop
                    trolling. Read other peoples code and learn to indent and use your
                    braces clearly and consistently.
                    >
                    While I have a lot of time for people who really want to learn your
                    continual posts show you rarely, if ever, listen to what is told to you
                    and the ridiculously poor quality of your code suggests that you must be
                    trolling.
                    I am honestly not quite sure how to answer this post. I understand there
                    are always going to be people who believe you have some sinister motive
                    behind everything and nothing can really be said to change that. But I will
                    give it a shot. I usually use indent to post my code and have been doing
                    that for awhile to make things easier to read and I forgot this time. If you
                    had been following my posts (which is up to you) you would know that. That
                    makes me have some doubts to your motives Richard. In my understanding clc
                    is a place to go for help now true; I might have been able to pick up a
                    reference and correct that %.2f thing but I doubt the parenthesis I would
                    have caught on my own.

                    As to level of understanding, I don't profess to be a C expert or I
                    wouldn't need clc. As for the term "Troll" this is my understanding of it.

                    From wikipedia there was an instance where a man pretended to be a woman
                    and so on and there was a big problem. On clc I doubt seriously that it is
                    possible to "troll". No one truely knows nor will ever expect to meet anyone
                    else here. That's common sense. And all we discuss is C. And nothing else.
                    How much damage can be possibly done.

                    Bill


                    Comment

                    • Bill Cunningham

                      #11
                      Re: oscillator


                      "Keith Thompson" <kst-u@mib.orgwrote in message
                      news:lntzg6b8ev .fsf@nuthaus.mi b.org...
                      And you get numbers like that *with what inputs*? See my other
                      message.
                      >
                      Answered on other message.

                      Bill


                      Comment

                      • Richard

                        #12
                        Re: oscillator

                        "Bill Cunningham" <nospam@nspam.c omwrites:
                        "Richard" <rgrdev@gmail.c omwrote in message
                        news:g2c9l9$9jh $2@registered.m otzarella.org.. .
                        >
                        >Might I suggest you not posting until you understand what is potentially
                        >the easiest thing in C to understand. Or alternatively stop
                        >trolling. Read other peoples code and learn to indent and use your
                        >braces clearly and consistently.
                        >>
                        >While I have a lot of time for people who really want to learn your
                        >continual posts show you rarely, if ever, listen to what is told to you
                        >and the ridiculously poor quality of your code suggests that you must be
                        >trolling.
                        >
                        I am honestly not quite sure how to answer this post. I understand there
                        are always going to be people who believe you have some sinister motive
                        behind everything and nothing can really be said to change that. But I
                        will
                        You are seemingly intelligent and well spoken and polite. I refuse to
                        believe that you do not understand C scoping rules with regard to
                        braces. It is the easiest thing in existence. I also do not believe you
                        do not have the common sense to correctly *MANUALLY* indent your code so
                        it is laid out nicely and is easy on the eye. Do not rely on indent. Do
                        it yourself.
                        give it a shot. I usually use indent to post my code and have been doing
                        that for awhile to make things easier to read and I forgot this
                        time. If you
                        Why? Do it yourself.
                        had been following my posts (which is up to you) you would know that. That
                        makes me have some doubts to your motives Richard. In my understanding clc
                        is a place to go for help now true; I might have been able to pick up
                        a
                        It is not the place to continually make the same mistakes regardless of
                        advice. You will then just become cannon fodder for the pedants in this
                        group of which there are many. I suspect most have you killfiled already
                        as many people consider you to be a troll and just here to waste peoples
                        time.
                        reference and correct that %.2f thing but I doubt the parenthesis I would
                        have caught on my own.
                        Why? It is the easiest thing in the world. Indent your code. Do not have
                        multiple statements on one line like Falconer does. Be
                        consistent. Personally I prefer the original K&R style e.g (code not
                        compiled or meant to do anything other than show layout)

                        ,----
                        | int i;
                        | for(i=0;i<10;i+ +){
                        | doSomething(i);
                        | doSomethingElse (i);
                        | }
                        `----

                        I like it because the boundaries are easy to see. Heathfield advocates
                        the opening brace on the next line e.g

                        ,----
                        | int i;
                        | for(i=0;i<10;i+ +)
                        | {
                        | doSomething(i);
                        | doSomethingElse (i);
                        | }
                        `----

                        Personally I do not like that but it is clear and easy to spot missing
                        braces. I would have no problem with anyone working on any projects of
                        mine using such and can understand why he, and others, prefer it.
                        >
                        As to level of understanding, I don't profess to be a C expert or I
                        wouldn't need clc. As for the term "Troll" this is my understanding of
                        it.
                        You do not have to be a C expert to understand braces. Practice. Do not
                        post your code until you have checked your parenthesis/braces. Really
                        Bill, you will not learn anything by constantly posting the same errors
                        and then glibly stating that "you are not quite familiar with or fully
                        understanding braces". How can you not be?
                        >
                        From wikipedia there was an instance where a man pretended to be a woman
                        and so on and there was a big problem. On clc I doubt seriously that it is
                        possible to "troll". No one truely knows nor will ever expect to meet anyone
                        else here. That's common sense. And all we discuss is C. And nothing else.
                        How much damage can be possibly done.
                        The only damage is that people who can guide you and help you will
                        killfile you as they feel their advice is falling on deaf ears.
                        >
                        Bill

                        Comment

                        • Richard Tobin

                          #13
                          Re: oscillator

                          In article <GPg2k.549$8q2. 535@trnddc02>,
                          Bill Cunningham <nospam@nspam.c omwrote:
                          >*Possibly* you meant something like, os = (price - ma) / ma * 100; ??
                          Ah I see. Thanks much Walter. That must be the problem. Not quite used
                          >to all C's parenthesis yet :)
                          They're not C's parentheses. It's just the normal notation used
                          in mathematics. You should have learned it at primary school!

                          -- Richard
                          --
                          In the selection of the two characters immediately succeeding the numeral 9,
                          consideration shall be given to their replacement by the graphics 10 and 11 to
                          facilitate the adoption of the code in the sterling monetary area. (X3.4-1963)

                          Comment

                          • Bill Cunningham

                            #14
                            Re: oscillator


                            "Richard" <rgrdev@gmail.c omwrote in message
                            news:g2cc10$kpt $1@registered.m otzarella.org.. .
                            [snip]
                            do not have the common sense to correctly *MANUALLY* indent your code so
                            it is laid out nicely and is easy on the eye. Do not rely on indent. Do
                            it yourself.
                            I agree with you on style. But too many people complained. So I learn
                            from indent that indents for me. Then people complained about that. Nothing
                            can be done right for some.

                            [snip]
                            The only damage is that people who can guide you and help you will
                            killfile you as they feel their advice is falling on deaf ears.
                            >
                            That's fine. As long as there are a few that are willing to help me I
                            will learn their tricks of the trade so to speak. I can't do it everyone's
                            way. There a several people who are willing to teach their style. I don't
                            need 100s disagreeing with each other and confusing me still. That's just a
                            mess.

                            Bill


                            Comment

                            • Bill Cunningham

                              #15
                              Re: oscillator


                              "Richard Tobin" <richard@cogsci .ed.ac.ukwrote in message
                              news:g2cd60$sj3 $1@pc-news.cogsci.ed. ac.uk...
                              They're not C's parentheses. It's just the normal notation used
                              in mathematics. You should have learned it at primary school!
                              >
                              I'll take the scolding. Actually I think Jr High School for me.

                              Bill


                              Comment

                              Working...