Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

BetterVolume w/ UP/DOWN bars

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

    BetterVolume w/ UP/DOWN bars

    hey guys whats going on i am attempting to code but since i do not know how as of yet, i am hacking stuff already done. this is the bettervolume indicator married with the volume updown. i have almost got it correct there are just three *statement expected* errors near the upper middle. i have no idea what this means or how to fix it, so i am giving this to ya'll to finish or not once i can really program i figure i can debug too. i was hoping to give it finished but hey it is what it is. i am learning a ton. and i already can't wait to start on my next project. stoploss, trailingstop, no profit target it seems to be the on of the more requested features on the forum.
    while it's late and my eyes hurt. gnite ya'll


    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    #endregion

    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
    /// <summary>
    /// Better Volume indicator from emini-watch.com/free-stuff/volume-indicator/ using true range instead of range in calculations.
    /// </summary>
    [Description("Better Volume indicator from emini-watch.com/free-stuff/volume-indicator/ using true range instead of range in calculations.")]
    public class BetterVolumeUPDOWN : Indicator
    {
    #region Variables
    // Wizard generated variables
    private int lookback = 20; // Default setting for Lookback
    private bool paintbars = true; // Default setting for Paintbars
    private bool useTrueRange = true; // Default setting for UseTrueRange
    // User defined variables (add any user defined variables below)
    private int barwidth = 2;
    private DataSeries vxr, vdr;
    private double vwt;
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    int hilight=barwidth+1;
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Silver), barwidth), PlotStyle.Bar, "VBarUP"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Grey), barwidth), PlotStyle.Bar, "VBarDOWN"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Goldenrod), hilight), PlotStyle.Bar, "LowBarUP"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Yellow), hilight), PlotStyle.Bar, "LowBarDOWN"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Lime), hilight), PlotStyle.Bar, "ClimaxBarUP"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Tomato), hilight), PlotStyle.Bar, "ClimaxBarDOWN"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Green), hilight), PlotStyle.Bar, "ChurnBarUP"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Red), hilight), PlotStyle.Bar, "ChurnBarDOWN"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Magenta), hilight), PlotStyle.Bar, "ClimaxChurnBarUP"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Purple), hilight), PlotStyle.Bar, "ClimaxChurnBarDOWN"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Black), hilight), PlotStyle.Bar, "LowChurnBarUP"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.White), hilight), PlotStyle.Bar, "LowChurnBarDOWN"));
    Add(new Plot(new Pen(Color.FromKnownColor(KnownColor.Grey), 1), PlotStyle.Line, "VolEMA"));

    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = false;

    vxr = new DataSeries(this);
    vdr = new DataSeries(this);
    vwt = 2.0 / (10.0 * lookback + 1.0); // bar average period is 10*lookback
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// Need to find out the logic for up and down bars/ticks
    /// </summary>
    protected override void OnBarUpdate()
    {
    {
    if (Close[0] > Open[0])
    Values[0].Set(Volume[0]);
    else
    Values[1].Set(Volume[0]);
    }
    {
    double range, v = Volume[0];
    if ( CurrentBar < 1) {
    range = High[0] - Low[0];
    VolEMA.Set(v);
    return;
    }
    range = useTrueRange ?
    Math.Max(High[0], Close[1]) - Math.Min(Low[0], Close[1]) // use true range
    : High[0] - Low[0]; // use normal range
    VolEMA.Set(vwt * (v - VolEMA[1]) + VolEMA[1]); // faster than SMA

    int cc = 0; // climax churn detection
    int bc = 0; // bar color, default 0 (normal volume bar)

    vxr.Set(v * range);
    vdr.Set((range != 0.0) ? v / range : 0.0);

    if (v == MIN(Volume, lookback)[0]); //LowBar
    if (Close[0] > Open[0])
    Values[bc = 2].Set(Volume[0]);
    else
    Values[bc = 3].Set(Volume[0]);

    if (vxr[0] == MAX(vxr, lookback)[0]); //ClimaxBar
    if (Close[0] > Open[0])
    Values[{ bc = 4; ++cc; >}]<.Set(Volume[0])>;< **statement expected between ><**
    else
    Values[{ bc = 5; ++cc; >}]<.Set(Volume[0]); **statement expected ><**

    if (vdr[0] == MAX(vdr, lookback)[0]); //ChurnBar
    if (Close[0] > Open[0])
    Values[{ bc = 6; ++cc; >}]<.Set(Volume[0])>;< **statement expected ><**
    else
    Values[{ bc = 7; ++cc; >}]<.Set(Volume[0]); **statement expected ><**

    if (cc == 2); //ClimaxChurnBar
    if (Close[0] > Open[0])
    Values[bc = 8].Set(Volume[0]);
    else
    Values[bc = 9].Set(Volume[0]);

    if (vdr[0] == MIN(vdr, lookback)[0]); //LowChurnBar
    if (Close[0] > Open[0])
    Values[bc = 10].Set(Volume[0]);
    else
    Values[bc = 11].Set(Volume[0]);

    Values[bc].Set(v); //plot whatever we found
    if (paintbars && bc > 0) BarColor = Plots[bc].Pen.Color;
    }
    }

    #2
    jupiejupe,

    You remind me of me one year ago. Learning code is an adventure!!!

    I have to agree with the software.

    Are you sure the "<" and ">" operators are in the correct places???

    It looks really strange to me!!!!

    Values[{ bc = 7; ++cc; >}]<.Set(Volume[0]); **statement expected ><**

    Do you feel the equation is mathamatically correct?

    RJay
    RJay
    NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

    Comment


      #3
      so how is your programming now? what reference materials would you suggest? who long did it take for you to be about to write real code?

      it looks strange because i added them there to show were the editor was complaining about the script.

      i realized i should have uploaded the script in the og post. so i am doing it now.
      Attached Files

      Comment


        #4
        jupiejupe,

        First I freely admit I am a hack programmer. (no formal training)

        I get some information of microsoft's websites. The rest I learning through brut force immersion.)

        Some information is available like this...

        Ex. C# Operators found here.



        I also make up my own definitions as I go along.

        I treat "if" statements as loops of specific commands. Commands in loops are defined within curly brackets {}

        Here is the part of your code with changes using curly brackets.

        -------------------------------------------------------------------

        if (vxr[0] == MAX(vxr, lookback)[0]); //ClimaxBar
        {
        if (Close[0] > Open[0])
        {
        Values[{ bc = 4; ++cc; }].Set(Volume[0]);
        }
        else
        {
        Values[{ bc = 5; ++cc; }].Set(Volume[0]);
        }
        }

        if (vdr[0] == MAX(vdr, lookback)[0]); //ChurnBar
        {
        if (Close[0] > Open[0])
        {
        Values[{ bc = 6; ++cc; }].Set(Volume[0]);
        }
        else
        {
        Values[{ bc = 7; ++cc; }].Set(Volume[0]);
        }
        }

        -------------------------------------------------------------

        Without the curly brackets, Where do the "if" commands stop executing?

        Do you see how there loops inside loops?

        your code has them all trying to execute at once with no guidlines.

        This is an excellent learning experience for you.

        Rework your code and post your results.

        Good Luck,

        RJay
        RJay
        NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

        Comment


          #5
          i have done as you command and while that did not solve the problem, i understand what it is worth and it may have solved a runtime error, i so thank you for the lesson.

          i have also got a little tricky and solved the issue by adding the ++cc value to bc before that line.

          now the are only two(2) compile errors and neither i understand. it's still **statement expected**

          1. is what is a statement?
          2. why is expected?
          Attached Files

          Comment


            #6
            what does the following code mean:

            vwt = 2.0 / (10.0 * lookback + 1.0); // bar average period is 10*lookback


            What is vwt? Why 2 divided by (10*lookback+1)

            thanks

            Comment


              #7
              i do not know, but the parent code is from "bettervolume" and "volume up down" is you'd like to take a look. maybe you could tell me, but seeing as that part of the code i have not married to anything else, they will be the same.

              Comment


                #8
                jupiejupe,

                More curly brackets Please!!!

                Add brackets indicated in RED!!!

                ------------------------------------------------------

                if (v == MIN(Volume, lookback)[0]); //LowBar
                {
                if (Close[0] > Open[0])
                {
                Values[bc = 2].Set(Volume[0]);
                }
                else
                {
                Values[bc = 3].Set(Volume[0]);
                }
                }

                if (vxr[0] == MAX(vxr, lookback)[0]); //ClimaxBar
                {
                if (Close[0] > Open[0])
                {
                bc += cc;
                Values[bc = 4].Set(Volume[0]);

                else

                Values[bc = 5].Set(Volume[0]);
                }
                }

                if (vdr[0] == MAX(vdr, lookback)[0]); //ChurnBar
                {
                if (Close[0] > Open[0])
                {
                bc += cc;
                Values[bc = 6].Set(Volume[0]);

                else

                Values[bc = 7].Set(Volume[0]);
                }
                }
                if (cc == 2); //ClimaxChurnBar
                {
                if (Close[0] > Open[0])
                {
                Values[bc = 8].Set(Volume[0]);
                }
                else
                {
                Values[bc = 9].Set(Volume[0]);
                }
                }

                --------------------------------------------------------------

                I don't know if this will fix anything but its what I would try next.

                RJay
                RJay
                NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                Comment


                  #9
                  Originally posted by rt6176 View Post
                  jupiejupe,

                  More curly brackets Please!!!

                  Add brackets indicated in RED!!!

                  ------------------------------------------------------

                  if (v == MIN(Volume, lookback)[0]); //LowBar
                  {
                  }

                  if (vxr[0] == MAX(vxr, lookback)[0]); //ClimaxBar
                  {
                  }

                  if (vdr[0] == MAX(vdr, lookback)[0]); //ChurnBar
                  {
                  }
                  if (cc == 2); //ClimaxChurnBar
                  {
                  }

                  --------------------------------------------------------------

                  I don't know if this will fix anything but its what I would try next.

                  RJay
                  And the ";"-signs in the lines with the if-statements look veeery strange.

                  Comment


                    #10
                    that seems to have fixed that issue. those errors are gone and there's new one when i went to compile the code so i am gonna look at it before posting. thank with the help so for, i really appreciate it.

                    Comment


                      #11
                      Is the problem here?

                      -------------------------------------------------------------------

                      if (vdr[0] == MIN(vdr, lookback)[0]); //LowChurnBar
                      {
                      if (Close[0] > Open[0])
                      {
                      Values[bc = 10].Set(Volume[0]);
                      }
                      else
                      }
                      Values[bc = 11].Set(Volume[0]);
                      }

                      Values[bc].Set(v); //plot whatever we found
                      if (paintbars && bc > 0) BarColor = Plots[bc].Pen.Color;
                      }

                      -----------------------------------------------------------------
                      RJay
                      NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                      Comment


                        #12
                        okay so i go it at least working, but with only two colours, not the full range. i think i know where the logic goes pissy, in the marriage of the two codes, also because the volume ema is reacting like it has been set to 1.

                        so, everything i am doing so far is with your assistant, as i am far above my pay grade after value 0 & 1 are called, i need to tell the cpu to keep going and get the other 10 values of colour.

                        side note:
                        i could not find where the cs files are stored so i have to remain a n00b and post txt files
                        Attached Files

                        Comment


                          #13
                          Just go to File/Utilities/Export Ninja Script for that.
                          eDanny
                          NinjaTrader Ecosystem Vendor - Integrity Traders

                          Comment


                            #14
                            Originally posted by jupiejupe View Post
                            okay so i go it at least working, but with only two colours, not the full range. i think i know where the logic goes pissy, in the marriage of the two codes, also because the volume ema is reacting like it has been set to 1.

                            so, everything i am doing so far is with your assistant, as i am far above my pay grade after value 0 & 1 are called, i need to tell the cpu to keep going and get the other 10 values of colour.

                            side note:
                            i could not find where the cs files are stored so i have to remain a n00b and post txt files
                            jupiejupe,

                            Ok, Here is what I would do. Each type of bar is already defined with the plot statements. You probably don't need all this bc="x" stuff.

                            For just the code below, remove "bc =" and just leave the number.

                            -----------------------------------------------------------------

                            if (v == MIN(Volume, lookback)[0]); //LowBar
                            {
                            if (Close[0] > Open[0])
                            {
                            Values[bc = 2].Set(Volume[0]);
                            }
                            else
                            {
                            Values[bc = 3].Set(Volume[0]);
                            }
                            }

                            if (vxr[0] == MAX(vxr, lookback)[0]); //ClimaxBar
                            {
                            if (Close[0] > Open[0])
                            {
                            bc += cc;
                            Values[bc = 4].Set(Volume[0]);
                            }
                            else
                            {
                            Values[bc = 5].Set(Volume[0]);
                            }
                            }

                            if (vdr[0] == MAX(vdr, lookback)[0]); //ChurnBar
                            {
                            if (Close[0] > Open[0])
                            {
                            bc += cc;
                            Values[bc = 6].Set(Volume[0]);
                            }
                            else
                            {
                            Values[bc = 7].Set(Volume[0]);
                            }
                            }

                            if (cc == 2); //ClimaxChurnBar
                            {
                            if (Close[0] > Open[0])
                            {
                            Values[bc = 8].Set(Volume[0]);
                            }
                            else
                            {
                            Values[bc = 9].Set(Volume[0]);
                            }
                            }

                            if (vdr[0] == MIN(vdr, lookback)[0]); //LowChurnBar
                            {
                            if (Close[0] > Open[0])
                            {
                            Values[bc = 10].Set(Volume[0]);
                            }
                            else
                            {
                            Values[bc = 11].Set(Volume[0]);
                            }

                            ------------------------------------------------------------------

                            Don't stop now, your almost there,

                            RJay
                            RJay
                            NinjaTrader Ecosystem Vendor - Innovative Trading Solutions

                            Comment


                              #15
                              here the cool export of v003 with the two colour error as it is missing the others
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Waxavi, Today, 02:10 AM
                              1 response
                              16 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Kaledus, Today, 01:29 PM
                              5 responses
                              13 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by Waxavi, Today, 02:00 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by alifarahani, Today, 09:40 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by gentlebenthebear, Today, 01:30 AM
                              3 responses
                              17 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X