• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New Indicator

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

    New Indicator

    Hi,

    I'm trying to make a simple indicator but it is not appearing on my chart.

    Have inserted this logic where it says " //Add your custom indicator logic here."

    if ((High[2]-Low[2]) > (Open[2] * .01) && High[0] < High[1]);

    Thank you for your help

    #2
    Hello Martyb,

    Thanks for your post and welcome to the NinjaTrader forums.

    To output a plot you would need to have used AddPlot() in state.SetDefaults to create the plot data series needed. Does your code have this?

    In the OnBarUpdate() where you have the code: if ((High[2]-Low[2]) > (Open[2] * .01) && High[0] < High[1]); which will actually do nothing as the structure of an if statement should be followed by an action statement, for example

    if (some conditions)
    {
    Perform some action;
    }


    Note that you have ended the if statement with a ";" which means that nothing will occur as a result of the if statement being either true or false. Here is a link to the NT7 help guide section on basic syntax that would be a good reference (we did not include this basic reference in the NT8 help guide): https://ninjatrader.com/support/help...g_concepts.htm

    What is the action you want to happen when the condition is true? If you want something to be plotted, what specifically would you have plotted and would it only plot when the condition is true?

    Please feel free to post a screenshot of a chart that shows what you are trying to accomplish.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick response.
      I learn better by seeing.
      Can you just post the whole code so that a see a signal on my chart.
      Thank you.

      Comment


        #4
        Hello Martyb,

        Thanks for your reply.

        I've attached an example for your understanding. The example shows a chart with an indicator applied and the right panel shows the code window of that indicator.

        The indicator example was generated with the Ninjascript wizard where I specified I wanted an input (called MyOffset) and a single plot (called MyExamplePlot), the wizard then created the structure you see.

        In OnBarUpdate() I added the line: MyExamplePlot[0] = Close[0] + (MyOffset * TickSize); which takes the current bar Close value and adds it to another value made up of a number I can enter in to the indicator before it runs to offset the plot from the close value, that number is multiplied times the instruments property called "TickSize" which is the minimum movement of that instruments. In the chart example, I have offset the plot by 40 ticks above the close of each bar.

        Click image for larger version

Name:	martyb-1.PNG
Views:	1
Size:	128.7 KB
ID:	1060633

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Why can't you use the example I gave. Just want a signal when this occurs:

          if ((High[2]-Low[2]) > (Open[2] * .01) && High[0] < High[1]);

          Please if you can give me the code for this I will be on my way.
          Thank you

          Comment


            #6
            Hello Martyb,

            Thanks for your reply.

            In the Support Department, we cannot create modify or debug code for our clients. While we understand that it may be easier for you to copy and paste working code from us, this is not an expectation that we like to set. Our goal for providing NinjaScript support is to provide educational information to help you accomplish your goals. Providing code that can be copy and pasted puts us in a position where we would have to provide such services for all of our clients. As we are a small team, this is not something we can deliver on.

            What are you trying to accomplish with this indicator?
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              It would take less time and questions if you can give me the code since it is such a simple indicator.
              I will then be able to modify it.
              I find Ninjascript pretty complicated compared to other programs.
              Please just to get me started, provide code.
              Thank you

              Comment


                #8
                Hello Martyb,

                This is Jim, responding on behalf of Paul. I'm the Scripting Support Lead here at NinjaTrader.

                Paul is right here about our policy. We do not create code that is to be copy and pasted. Doing so puts in a position where we have to provide such services for all of our clients and this is something our team cannot deliver on due to the size of our team.

                We also do not provide programming education in the Support Department, so if you are having issues with the programming concepts, we really would not be helping by providing code to be copy and pasted.

                We are happy to help, but we will not be able to provide code that is to be copied verbatim. If you are looking for such services, I may suggest hiring a NinjaScript Consultant from our EcoSystem.

                If you are having issues with writing syntax, I may suggest using the Strategy Builder to generate the syntax for you. You can create your condition in the Strategy Builder and have it perform an action to draw on the chart. Once you click the View Code button, you will see resulting syntax. This tool can help to generate code for you if it is too complex to write by hand, and is probably the best way to get more familiar with NinjaScript code. I have included some resources for the Strategy Builder below.

                Strategy Builder 301 - https://www.youtube.com/watch?v=_KQF2Sv27oE
                Conditions exmaples - https://ninjatrader.com/support/help...on_builder.htm
                Actions examples (See Drawing on a chart) - https://ninjatrader.com/support/help...us/actions.htm

                To proceed with this inquiry, please share a screenshot of what you have setup with the Strategy Builder and the action you have entered to draw on the chart, as well as a screenshot of the chart with the strategy enabled. As long as this is working, you will be able to view the code generated and implement it in your indicator.

                We look forward to assisting.
                JimNinjaTrader Customer Service

                Comment


                  #9
                  Hi,
                  Have tried the following but still not working.

                  Comment


                    #10
                    Hello Martyb,

                    NinjaScript programming requires some C# background as a prerequisite so you can write proper syntax and avoid compiler errors. I encourage you to Google the compiler errors to get a better understanding on what they mean. There are often great external educational resources that explain what the compiler errors mean. C# is a hard typed language so you cannot assign a bool to a double like you are in your code. For example, logical checks will return a boolean value and they cannot be assigned to a double.

                    We have some light programming educational materials in the NinjaTrader 7 help guide, but more robust C# education can be found externally to NinjaTrader.

                    Basic Programming Concepts - https://ninjatrader.com/support/help...g_concepts.htm

                    Additionally, you are referencing BarsAgo indexes of previous bars without checking if you have processed enough bars first. After you get past your compiler errors, you will receive errors in the log tab of your Control Center stating that you are accessing an index with a value that is invalid because it is out of range. Please see the tip below for adding a CurrentBar check to ensure that you have processed enough bars before referencing a historical value.

                    Making sure you have enough bars in the data series you are processing - https://ninjatrader.com/support/help...nough_bars.htm

                    I still encourage you to set this up in the Strategy Builder as that will generate the C# syntax for you. You would not be able to create a continuous plot, but you could create a condition following your logic (High[2]-Low[2]) > (Open[2] * .01) && High[0] < High[1]) and then draw a dot or some other visual indication or signal. You could then use the strategy, or implement what the strategy is doing in your indicator.

                    If you are still having issues, please setup a condition in the Strategy Builder that makes your logical check and then draws an object in the action block of that condition.

                    Drawing on a chart - https://ninjatrader.com/support/help...ToDrawOnAChart

                    I'm confident if you set this up in the Builder you will have something working that can be used as-is or provide further direction on how the code would be set up.

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

                    Comment


                      #11
                      Originally posted by Martyb View Post
                      Hi,
                      Have tried the following but still not working.
                      Try:
                      MPlot[0] = (High[2]-Low[2]) > (Open[2] * .01) && High[0] < High[1]) ? 1.0 : 0.0;

                      This will plot 1.0 when your condition is true and 0.0 otherwise.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by rickyblah12, Today, 01:01 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post rickyblah12  
                      Started by dadarara, Today, 12:18 PM
                      0 responses
                      8 views
                      0 likes
                      Last Post dadarara  
                      Started by joemiller, Today, 07:33 AM
                      2 responses
                      12 views
                      0 likes
                      Last Post joemiller  
                      Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
                      7 responses
                      38 views
                      0 likes
                      Last Post DaveS
                      by DaveS
                       
                      Started by claxxical, Yesterday, 10:00 PM
                      0 responses
                      13 views
                      0 likes
                      Last Post claxxical  
                      Working...
                      X