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

NT8 newbie - changing plot color per bar

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

    NT8 newbie - changing plot color per bar

    I have successfully changed a few indicators to plot green / red based on direction. I am trying to modify the 'included' MoneyFlowOscillator indicator and can't get it to change color. I have used the same technique I used in my other indicator changes, but nothing seems to work. Any assistance would be appreciated.


    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    /// <summary>
    /// The Money Flow Oscillator measures the amount of money flow volume over a specific period. A move into positive territory indicates buying pressure while a move into negative territory indicates selling pressure.
    /// </summary>
    public class MoneyFlowOscillator : Indicator
    {
    private Series<double> mfv;
    private double dvs, mltp;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionMoneyFlowOscillator;
    Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meMoneyFlowOscillator;
    IsOverlay = false;
    DrawOnPricePanel = false;
    IsSuspendedWhileInactive = true;
    Period = 20;

    AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorMo neyFlowLine);
    AddLine(Brushes.DarkGray, 0, NinjaTrader.Custom.Resource.NinjaScriptIndicatorZe roLine);
    }
    else if (State == State.DataLoaded)
    {
    mfv = new Series<double>(this);
    }
    }

    protected override void OnBarUpdate()
    {
    if(CurrentBar > 0)
    {
    dvs = (High[0] - Low[1]) + (High[1] - Low[0]) == 0 ? 0.00001 : (High[0] - Low[1]) + (High[1] - Low[0]);
    mltp = Math.Round(High[0] < Low[1] ? -1: Low[0] > High[1] ? 1 : ((High[0] - Low[1]) - (High[1] - Low[0])) / dvs, 2);
    mfv[0] = mltp * (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]);

    if (CurrentBar >= Period)
    {
    double sumVolume = SUM(Volume, Period)[0];
    if (Instrument.MasterInstrument.InstrumentType == Cbi.InstrumentType.CryptoCurrency)
    sumVolume = Core.Globals.ToCryptocurrencyVolume((long)sumVolum e);
    Values[0][0] = Math.Round(SUM(mfv, Period)[0] / sumVolume, 3);
    }

    // Below are my 2 trys to get the color to change.
    /*
    if( mfv[0] > 0.0 )
    PlotBrushes[0][0] = Brushes.Green;
    if( mfv[0] < 0.0 )
    PlotBrushes[0][0] = Brushes.Red;
    if( mfv[0] = 0.0 )
    PlotBrushes[0][0] = Brushes.Yellow;
    */
    if( Values[0][0] > 0.0 )
    PlotBrushes[0][0] = Brushes.Green;
    if( Values[0][0] < 0.0 )
    PlotBrushes[0][0] = Brushes.Red;
    if( Values[0][0] = 0.0 )
    PlotBrushes[0][0] = Brushes.Yellow;


    }
    else
    mfv[0] = 0;
    }

    #2
    Hello joromero,

    Thanks for your post.

    Using the Values[0][0] should be what you want to base the condition evaluation on.

    This line: if( Values[0][0] = 0.0 ) has a typo and should be if( Values[0][0] == 0.0 ).

    Also, I would place the brush coding below the line mfv[0] = 0;

    So:

    Code:
                else
                    mfv[0] = 0;
    
                if( Values[0][0] > 0.0 )
                    PlotBrushes[0][0] = Brushes.Green;
                if( Values[0][0] < 0.0 )
                    PlotBrushes[0][0] = Brushes.Red;
                if( Values[0][0] == 0.0 )
                    PlotBrushes[0][0] = Brushes.Yellow;
            }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,

      Thanks for the quick reply. I did make the one change you caught. Thanks. But, it still does not change the plot color? Any other thoughts?

      Comment


        #4
        Hello joromero,

        Thanks for your reply.

        Did you move the code as I showed in the code block?

        Works here:

        Click image for larger version

Name:	Joromero-1.PNG
Views:	304
Size:	108.6 KB
ID:	1062825
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Paul, Again, thanks for your time. I did do as you suggested. I have also removed the indicator, pressed ok, and then once again selected 'Indicator' from the menu to add it back. I also tried to 'reload' ninja script. It looks like you created a copy of the indicator to make the changes. I did it to the original. Once I did a Save As, then compiled and loaded my named copy, it worked here as well. Not sure why, since when I made the changed to the original, it compiled with no issues.

          Any way, it is working now, so who knows ! ! !

          Again, thanks for your time

          John in NC

          Comment


            #6
            Hello John,

            Thanks for your reply.

            Glad you have it working.

            When working with scripts that draw or plot, it is indeed a good idea to remove the indicator from the chart and then reapply after you have changed your script and recompiled. This ensures that you are working with the just changed instance. This is a common mistake (and I make it myself as well).



            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Felix Reichert, 04-26-2024, 02:12 PM
            6 responses
            41 views
            0 likes
            Last Post Felix Reichert  
            Started by MrForgetful, Today, 01:28 AM
            3 responses
            21 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by cmtjoancolmenero, 04-29-2024, 03:40 PM
            16 responses
            50 views
            0 likes
            Last Post cmtjoancolmenero  
            Started by ETFVoyageur, Yesterday, 06:05 PM
            6 responses
            39 views
            0 likes
            Last Post ETFVoyageur  
            Started by rbeckmann05, Today, 02:35 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Working...
            X