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

Change an Indicator Color in a Strategy

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

    #16
    Rmi

    no i got it from standard indicators RMI = Relative Momentum Indicator
    but here are the guts of the code

    protected override void Initialize()
    {
    Add(new Plot(Color.Lime, "RMI"));

    Add(new Line(System.Drawing.Color.Green, 30, "Lower"));
    Add(new Line(System.Drawing.Color.Black, 50, "Center"));
    Add(new Line(System.Drawing.Color.Red, 70, "Upper"));

    avgUp = new DataSeries(this);
    avgDown = new DataSeries(this);


    PriceTypeSupported = true;
    }

    /// <summary>
    /// Calculates the indicator value(s) at the current index.
    /// </summary>
    protected override void OnBarUpdate()
    {
    double amountUp = 0;
    double amountDown = 0;
    double rmi = 0;

    if (CurrentBar ==0)
    {
    avgUp.Set(0);
    avgDown.Set(0);

    return;

    }

    if (CurrentBar < (Period + Shift))
    {
    return;
    }
    else if (CurrentBar == (Period + Shift))
    {
    double sumUp = 0;
    double sumDown = 0;

    for (int barsAgo = 0; barsAgo < Period; barsAgo++)
    {
    amountUp = Input[barsAgo] - Input[barsAgo + Shift];
    if (amountUp >= 0)
    {
    amountDown = 0;
    }
    else
    {
    amountDown = -amountUp;
    amountUp = 0;
    }
    sumUp = sumUp + amountUp;
    sumDown = sumDown + amountDown;
    }
    avgUp.Set( sumUp / Period);
    avgDown.Set( sumDown / Period);
    }
    else
    {
    amountUp = Input[0] - Input[Shift];
    if (amountUp >= 0)
    {
    amountDown = 0;
    }
    else
    {
    amountDown = -amountUp;
    amountUp = 0;
    }
    avgUp.Set((avgUp[1] * (Period - 1) + amountUp) / Period);
    avgDown.Set((avgDown[1] * (Period - 1) + amountDown) / Period);
    }

    if ((avgUp[0] + avgDown[0]) != 0)
    {
    rmi = 100 * avgUp[0] / (avgUp[0] + avgDown[0]);
    }
    else rmi = 0;


    Value.Set(rmi);
    }

    #region Properties

    Comment


      #17
      Hello RicRules,

      Thank you for providing some of the RMI code. You would likely add the following code:
      Code:
      [COLOR="DarkGreen"]//....
      else rmi = 0;[/COLOR]
      
      [B]if(rmi > 50) { PlotColors[0][0] = Color.Red; }
      else { PlotColors[0][0] = Color.Green; }
      [/B]
      [COLOR="DarkGreen"]Value.Set(rmi);
      //...[/COLOR]
      in the OnBarUpdate() method.

      Please let me know if you have any questions or if I may be of further assistance.
      Michael M.NinjaTrader Quality Assurance

      Comment


        #18
        here is what i came up with that compiles (by itself with everything else commented out)
        {
        if(RMI(14,4)[0] > 50) { PlotColors[0][0] = Color.Red; }
        else { PlotColors[0][0] = Color.Green; }
        }
        ty

        Comment


          #19
          Hello RicRules,

          Could you please clarify if you are providing a solution to your inquiry or if you are asking for further assistance?

          Thank you in advance.
          Michael M.NinjaTrader Quality Assurance

          Comment


            #20
            no cause nt to not open

            Comment


              #21
              Hello RicRules,

              Please delete the code that causes NinjaTrader to not open and try the code I have provided for your RMI indicator instead.

              The steps are as follows:
              1. Navigate to Tools -> Edit NinjaScript -> Indicator
              2. Select the RMI indicator
              3. Scroll down to the following code:
              Code:
              if ((avgUp[0] + avgDown[0]) != 0)
              {
              rmi = 100 * avgUp[0] / (avgUp[0] + avgDown[0]);
              }
              else rmi = 0;
              
              
              Value.Set(rmi);
              4. Change it to look like the following:
              Code:
              if ((avgUp[0] + avgDown[0]) != 0)
              {
              rmi = 100 * avgUp[0] / (avgUp[0] + avgDown[0]);
              }
              else rmi = 0;
              if(rmi > 50) { PlotColors[0][0] = Color.Red; }
              else { PlotColors[0][0] = Color.Green; }
              Value.Set(rmi);
              5. Press F5 on your keyboard to recompile.
              6. Add the RMI indicator to a chart.

              Please let me know if you have any further questions.
              Michael M.NinjaTrader Quality Assurance

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Stanfillirenfro, Today, 07:23 AM
              4 responses
              17 views
              0 likes
              Last Post Stanfillirenfro  
              Started by DayTradingDEMON, Today, 09:28 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by cmtjoancolmenero, Yesterday, 03:58 PM
              8 responses
              31 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by helpwanted, Today, 03:06 AM
              2 responses
              22 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by navyguy06, Today, 09:28 AM
              0 responses
              6 views
              0 likes
              Last Post navyguy06  
              Working...
              X