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

Need help to change this custom indicator

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

    Need help to change this custom indicator

    Hello, after 3 days of tries and without success, decide to ask here.
    I found indicator that is making the color of the candles depends of the side of the moving average, but this is build for T3 (triangular MA maybe?) so, I need to shows also SMA and WMA. But when I try to change the code to SMA for example, there is in the code something that I cannot understand (TCount) that if its put on 1 or 0 the candle colors missing, so I could not even delete it....
    Also, if it possible the moving average to be in one color.

    Thank you
    Attached Files

    #2
    Hello,

    Thank you for the post.

    It does seem this was built to be specific to the T3, and the reason you cannot use 1 or 0 is that the logic does not allow for that.

    In the top of OnBarUpdate there is this condition:

    Code:
    if (TCount == 1)
    {
    	CalculateGD(Inputs[0], Values[0]);
    	return;
    }
    This is checking if the entered TCount is 1, if so it calls the method CalculateGD and then prevents further logic from happening.

    Using 0 would not work because the Minimum that is defined is 1:

    Code:
    public int TCount
    {
         get { return tCount; }
         set { tCount = [B]Math.Max(1, value)[/B]; }
    }
    These would be items you would need to modify if you wanted this indicator to support the values of 0 or 1. However this would change the overall logic and could impact the calculation that are defined. For example, the following line uses the TCount minus 1:
    Code:
    for (int i = 0; i < TCount - 1; i++)
    If you allowed a 0 value, this would also need modified as this logic would not work: 0 minus 1 is -1 which is not ever greater than 0 so this code would not run.

    Regarding the colors, you would need to remove the logic that controls the colors for the plots, you can locate this in the lower portion of the script.

    Code:
    if (Rising(Values[0]))
    	PlotColors[0][0] = upColor;
    else 
    	PlotColors[0][0] = downColor;
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello,

      Thank you for the post.

      It does seem this was built to be specific to the T3, and the reason you cannot use 1 or 0 is that the logic does not allow for that.

      In the top of OnBarUpdate there is this condition:

      Code:
      if (TCount == 1)
      {
      	CalculateGD(Inputs[0], Values[0]);
      	return;
      }
      This is checking if the entered TCount is 1, if so it calls the method CalculateGD and then prevents further logic from happening.

      Using 0 would not work because the Minimum that is defined is 1:

      Code:
      public int TCount
      {
           get { return tCount; }
           set { tCount = [B]Math.Max(1, value)[/B]; }
      }
      These would be items you would need to modify if you wanted this indicator to support the values of 0 or 1. However this would change the overall logic and could impact the calculation that are defined. For example, the following line uses the TCount minus 1:
      Code:
      for (int i = 0; i < TCount - 1; i++)
      If you allowed a 0 value, this would also need modified as this logic would not work: 0 minus 1 is -1 which is not ever greater than 0 so this code would not run.

      Regarding the colors, you would need to remove the logic that controls the colors for the plots, you can locate this in the lower portion of the script.

      Code:
      if (Rising(Values[0]))
      	PlotColors[0][0] = upColor;
      else 
      	PlotColors[0][0] = downColor;
      I look forward to being of further assistance.

      Thank you very much Jesse,
      Now I understand the problem.

      Idea occurred to me, is it possible to catch only the script from this indicator where its written the code of the candles, and move it to original script of WMA indicator? As I saw, we can also change the integrat. indicators in the Ninjatrader.

      And if it possible, may you show me, exactly wich script to copy and where to paste it in the script of the standart moving average?

      Thank you again.

      Comment


        #4
        Hello,

        Thank you for the reply.

        I wanted to confirm, are you asking how to duplicate the stock indicators such as the WMA and then copy some portion of this indicators code into the copy of the WMA?

        If so, yes that is possible but you would need to know what portion of the logic you want to bring over. This would not necessarily be something I could tell you exactly what to copy.

        The indicator you have provided was intended to work in a specific way in regard to the properties and variables used in the script. You would need to know what specific properties and variables are important to the logic you would be making in the new script and bring only those parts over. I would likely suggest to duplicate the WMA and then modify it instead of copying and pasting directly. This would assist you in learning NinjaScript and allow you to ensure the values you are using are what you are expecting.

        To make a duplicate of an existing file, you can select that file in the Tools -> Edit NinjaScript -> Indicator menu and open it. Next right click and choose Save as. This will allow you to give the duplicate a new name and will open it.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello,

          Thank you for the reply.

          I wanted to confirm, are you asking how to duplicate the stock indicators such as the WMA and then copy some portion of this indicators code into the copy of the WMA?

          Yes, that's the idea.
          The main thing is to make candles colored in 2 colors when close above or bellow the moving average (SMA,WMA,EMA). What I like in this indicator is that the color of the candles shows as full painted body, and just outline (this is for oposite direction candle).

          Its hard to code that, but any advice from where to start?

          Thanks
          Attached Files

          Comment


            #6
            Hello,

            Thank you for the reply.

            In general these concepts are not difficult, it may be more difficult trying to interpret the existing indicator and then try to re develop that logic.

            The indicator you provided controls the bar colors using the following syntax, this would basically be the same syntax you could use in a different indicator but would require some modification.

            Code:
            if (Rising(Values[0]))
            {
            	CandleOutlineColor = upColor;
            	BarColor = upColor;
            }
            else
            {
            	CandleOutlineColor = downColor;
            	BarColor  = downColor;
            }
            if(Open[0] < Close[0]) 
                BarColor  = Color.Transparent;

            This is in essence checking if there was a Rising value or not with the main Plot, depending on Rising or Falling, the candles are colored. Both the Candle body and Outline are colored, and then the Body is removed if the Open is less than the Close.

            You could implement similar logic in a new indicator, this specific syntax could be directly copy and pasted, the only changes that would be needed wouble be the upColor, downColor and Values[0]. the upColor and downColor would need to be changed to a Color value, and Values[0] would be replaced with the indicator you want to check.

            A simple example of checking a WMA from this syntax:

            Code:
            if (Rising(WMA(12)))
            {
            	CandleOutlineColor = Color.Green;
            	BarColor = Color.Green;
            }
            else
            {
            	CandleOutlineColor = Color.Red;
            	BarColor  = Color.Red;
            }
            if(Open[0] < Close[0]) 
            	BarColor  = Color.Transparent;
            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello,



              A simple example of checking a WMA from this syntax:

              Code:
              if (Rising(WMA(12)))
              {
              	CandleOutlineColor = Color.Green;
              	BarColor = Color.Green;
              }
              else
              {
              	CandleOutlineColor = Color.Red;
              	BarColor  = Color.Red;
              }
              if(Open[0] < Close[0]) 
              	BarColor  = Color.Transparent;
              I look forward to being of further assistance.

              Jesse, I`v done the job succs. Thank you for your support.

              Now, I want to try making the candles to color when 2 moving average cross each other, I found some thread in the forum with similar question, and there where a code, but didn`t work for me. Can you help me with that?

              Thanks.

              Comment


                #8
                Hello,

                What specifically are you trying that is not currently working? Cross conditions can be done using only price data or also the built in methods like CrossAbove/CrossBelow. Depending on what you are doing I could provide different cases, if you can show me what you are currently trying that would help me provide a more accurate answer.





                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello,

                  What specifically are you trying that is not currently working? Cross conditions can be done using only price data or also the built in methods like CrossAbove/CrossBelow. Depending on what you are doing I could provide different cases, if you can show me what you are currently trying that would help me provide a more accurate answer.





                  I look forward to being of further assistance.
                  Hi Jesse,

                  This is the syntax that I found in the forum:

                  if (CrossAbove(SMA(6), SMA(12), 1))
                  {
                  BarColor = Color.Green;
                  }


                  So I tried to replace this with the syntax that you write me as example:

                  if (Rising(Values[0]))
                  {
                  CandleOutlineColor = upColor;
                  BarColor = upColor;

                  But nothing shows...

                  Thanks.

                  Comment


                    #10
                    Hello nikodine,

                    The code you have posted is not complete.

                    What is the exact code that you are testing in your script that is not behaving as expected?

                    To export a NinjaTrader 8 NinjaScript do the following:

                    - Click Tools -> Export -> NinjaScript...
                    - Click the 'add' link -> check the box(es) for the script(s) you want to include
                    - Click the 'Export' button
                    - Enter a unique name for the file in the value for 'File name:'
                    - Choose a save location -> click Save
                    - Click OK to clear the export location message

                    By default your exported file will be in the following location:

                    - (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>

                    Below is a link to the help guide on Exporting NinjaScripts.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by arvidvanstaey, Today, 02:19 PM
                    4 responses
                    11 views
                    0 likes
                    Last Post arvidvanstaey  
                    Started by samish18, 04-17-2024, 08:57 AM
                    16 responses
                    61 views
                    0 likes
                    Last Post samish18  
                    Started by jordanq2, Today, 03:10 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post jordanq2  
                    Started by traderqz, Today, 12:06 AM
                    10 responses
                    18 views
                    0 likes
                    Last Post traderqz  
                    Started by algospoke, 04-17-2024, 06:40 PM
                    5 responses
                    48 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X