Announcement

Collapse
No announcement yet.

Writing a Counter EFS and Displaying the results

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

  • Writing a Counter EFS and Displaying the results

    Hello, I have made several attempts and spend hours over the last couple of weeks looking for a similiar EFS with no luck.

    This is what I am attempting to accomplish;

    I have over 10 slightly different conditions that I have written EFS's for.
    Can anyone assist me with the following;
    I am trying to determine from my 10 conditions how many of them are going UP verses going DOWN.
    I have created the following variables;

    var GreenUP = 0;
    var RedDN = 0;
    var GreenTotal = GreenUP;
    var RedTotal = RedDN;

    I believe the logic should work like so;

    if condition1 is green{
    GreenUP++;
    }
    if condition2 is green{
    GreenUP++
    }

    this would be continued up to the 10 total conditions

    if condition1 is red{
    RedDN++
    }
    if condition2 is red{
    RedDN++
    }

    this would be continued up to the 10 total conditions

    At the end, I need a method of displaying the totals
    I can use " SetBarBgColour(color.green);" to show the color I desire, is there a way to have the total number of up conditions using GreenTotal.

    In my scenario, where is the best place to put my variable, in function preMain, or function main ?

    Is it correct to use e.g. RedDN++ to add to the total ?

    What are the best ways to display the results on the chart, 1 for total reds and 1 for total greens ?

    If anyone can point me in the right direction, it would be greatly appreciated.
    Thanks in advance for any assistance.

  • #2
    EFS to add totals and display results

    I had originally accidentally posted this thread in the wrong forum.

    Hello, I have made several attempts and spend hours over the last couple of weeks looking for a similiar EFS with no luck.

    This is what I am attempting to accomplish;

    I have over 10 slightly different conditions that I have written EFS's for.
    Can anyone assist me with the following;
    I am trying to determine from my 10 conditions how many of them are going UP verses going DOWN.
    I have created the following variables;

    var GreenUP = 0;
    var RedDN = 0;
    var GreenTotal = GreenUP;
    var RedTotal = RedDN;

    I believe the logic should work like so;

    if condition1 is green{
    GreenUP++;
    }
    if condition2 is green{
    GreenUP++
    }

    this would be continued up to the 10 total conditions

    if condition1 is red{
    RedDN++
    }
    if condition2 is red{
    RedDN++
    }

    this would be continued up to the 10 total conditions

    At the end, I need a method of displaying the totals
    I can use " SetBarBgColour(color.green);" to show the color I desire, is there a way to have the total number of up conditions using GreenTotal.

    In my scenario, where is the best place to put my variable, in function preMain, or function main ?

    Is it correct to use e.g. RedDN++ to add to the total ?

    What are the best ways to display the results on the chart, 1 for total reds and 1 for total greens ?

    If anyone can point me in the right direction, it would be greatly appreciated.
    Thanks in advance for any assistance.

    Comment


    • #3
      Hi,

      Just a few observations:

      -Based on your post "GreenTotal" and "RedTotal" don't seem useful since "GreenUP" and "RedDN" already contain the totals.
      -Consider using Boolean variables instead of "if condition# is green"
      -One of several ways to display the totals could use the return with "PLOTTYPE_HISTOGRAM" where GreenTotal is a positive value and RedTotal is a negative value. And possibly using "setStudyMax()" to 10 and "setStudyMin()" to -10.
      -Ref: "...best place to put my variable...": if you mean where to declare it, then declare variables as global (outside of any function) for those that must retain their values through every iteration of main. If the a new value is generated on every iteration of main then local variables are usually better.
      -Ref: "RedDN++" yes that increments the variable. There is a difference between that and "++RedDN": see http://www.w3schools.com/js/js_operators.asp and do a google search for "javascript operator" for more information.
      -There are several ways to display the information. Some are : return a histogram or two line plots, use the draw functions to plot the values somewhere on the chart like above and below the appropriate bar, color code the bars based on the value, etc.

      Wayne
      Last edited by waynecd; 05-13-2013, 05:54 PM.

      Comment

      Working...
      X