Need some help with a simple code!!

Discussion in 'Strategy Development' started by veggen, Oct 6, 2008.

  1. veggen



    Can somebody help me writing a code for a color changing moving average?

    Green if up, and red if down, that is what I am working on.

    I have little experience with code writing, or come to think of it - no experience.

    I know where to write the code, that is all!

    I am using OpenEcry, and it will understand Easy Language, .Net and C#

    Please someone, I am desperate :)

    Regards, veggen
  2. Don't need to know much about coding to do this in OEC. I did this using their "show case" feature. All you need to know is this:

    Green: SMA(Input,20)>SMA(Input, 20)[1];

    You can do this through their menus and its fairly easy. You can also have the bars change color is you'd like.

  3. veggen


    Do I insert this code in "condition"?

    I assume this is for a SMA 20 period. If I wanted a LSMA with a 20 period, do I plot: "LSMA((Input,20)>SMA(Input, 20)[1]" ?

    what should I plot in the "input" field?

    Your help is much appriciated!!
    Thank you

  4. veggen


    hmm.. I can not figure this out.

    I tried placing your code in the "Condition" area, but this only makes the candlesticks turn red when going upwards!
    What am I doing wrong?

  5. Takes a little getting used. When i started out I didnt have a clue and people helped me, so here I am returning the favor.

    Follow these steps:

    1) Create a chart with nothing but the data on it

    2) Insert whatever type of moving average you want ( in the example I just used a simple 20 average)

    3) Go to Insert-Custom Indicators - Show Cases

    4) In Condition, put in the equation. I suggest you hit the "...", and just use the drag and drop feature.
    Here is an example that would turn the sma green:

    --once again I would just use the "..." so that you dont mis-type anything.

    5) Input: Close:"whatever market"

    6) Where to show: Use the "...", and select the moving average you are using.

    All the other stuff is just formatting, i hope you could figure that out:p . To turn the color red, just go make a show case and change flip the condition around.

    Hope this helps.
  6. veggen


    Finally!! Thank you so much :)

    Now there is only one problem. Whith "chart style" as "point", it is excelent, but I would prefer it to be a normal "line". This is were problems appear:

    When the line is not "in use" so to say, it moves in a straight line to the next point where it is moving from.

    How can I fix this?

    Again, thank you so much for all the help. Your "play-by-play" there was excellent, and must have taken you some time to arrange!

    Regards, veggen
  7. veggen


    This one is better.

  8. Hmm..not really sure, as mine is not doing that. I set mine up to use the LSMA, there was some extra code when using it, i just took that out and used: LSMA(Input,20)

    Here's what settings look like:

    And what the chart looks like:
    <IMG src="" width=800>

    Now, I am not sure how to just color the line ( I am sure there is a way to do it). However the moving average line will change color if you use the "Coloring" instead of "Show Case". You can choose to either color the whole candle body or just outline it. Use the same logic as for the Show Case, but just use Coloring.
  9. veggen


    I tried the "coloring" feature, but that made the candlesticks change color as well!

    But the dotted lines are good enough for me :)

    Thank you so much, owe you one!

    Regards veggen
  10. Not a problem. If you got the code exactly as you want it, you can place it the library to easily use on other charts.

    #10     Oct 7, 2008