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

Value and trade signal output from indicator

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

    Value and trade signal output from indicator

    Hi,

    I have modified the SMA indicator to plot different colours based on the value of the slope. I would like to use this logic to enter trades but as SMA() only returns the SMA value I would have to replicate the coded logic in the strategy as I have already done in the indicator. What would I need to do to get SMA() to return the entry trigger which it is using to colour code it's plot?

    Thanks,
    darmbk.

    #2
    Originally posted by darmbk View Post
    Hi,

    I have modified the SMA indicator to plot different colours based on the value of the slope. I would like to use this logic to enter trades but as SMA() only returns the SMA value I would have to replicate the coded logic in the strategy as I have already done in the indicator. What would I need to do to get SMA() to return the entry trigger which it is using to colour code it's plot?

    Thanks,
    darmbk.
    In general you would need to create another dataseries with the input being when the slope condition exits. As an idea, when the condition to go long exists, set the data series to +1 when the condition to go short exists set to -1, when neither condition exists, set to 0. Creating the public dataseries will make it available outside the indicator for use in a strategy as well as the Market Analyzer.

    Comment


      #3
      Hi darmbk,

      You would need to make a public value that can be called from another script.

      It would be best to use Browsable false so that the public variable does not show as a parameter.

      Attached is an example. In the example my public variable is called RelationToClose. If the sma is greater than the close RelationToClose will be 1, if sma is less than close, RelationToClose will be -1, if equal RelationToClose will be 0.


      Your other option is to add a plot to this indicator and set the plot value and then call this. This method would allow you to use the script in the Market Analyzer as well.
      Attached Files
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you both for your responses.

        Hi Chelsea,
        I like the sound of the plot data series option. I have my indicator set-up with a Plot1 shown here as specified in the SMA() properties:

        Code:
        [Browsable(false)]
        [XmlIgnore()]
        public DataSeries Plot1
        {
        	get { return Values[0]; }
        }
        This is called in SMA() like this in OnBarUpdate(), capturing another time frames SMA value:

        Code:
        Plot1.Set(SMA(BarsArray[1], MAPeriod)[0]);
        What I think you are suggesting is then to have a Plot2 DataSeries and in that I should capture the +1, 0, -1 values that Tasker suggests.

        Can I refer to Plot2 in my strategy and/or should it be declared at the strategy level? Could you show me an example based on the code you attached already as I'm unsure where to define a Plot2 and how to refer to it when inside an indicator? If I have other filters I will need a Plot3, Plot4 etc I guess too.

        Many thanks,
        darmbk.

        Comment


          #5
          Hi darmbk,

          I'd made a new sample for you that uses a public data series in the indicator and then calls this value in a sample strategy.

          The MACD indicator is also a great example of how to do this.
          Attached Files
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Hi Chelsea,

            Many thanks for the example, that's excellent. Are we using a dataseries object rather than a single element here because of the possibility that multi-threading could overwrite the value stored in a single element at the wrong time? Or otherwise, why are we using a dataseries object?

            Thanks,
            darmbk.

            Comment


              #7
              Hi Chelsea,

              I have run into a problem. When I add:

              Code:
              Values[1].Set(1);
              I am unable to plot the indicator and I get the following error:

              Code:
              Error on calling 'OnBarUpdate' method for indicator 'qHigherFrame_MA_V1_3' on bar 104: Index was outside the bounds of the array.
              Here are my dataseries under properties:

              Code:
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries Plot1
              {
              	get { return Values[0]; }
              }
              
              [Browsable(false)]
              [XmlIgnore()]
              public DataSeries TrendDirection
              {
              	get { return Values[1]; }
              }
              Any idea what I might be doing wrong?

              Thanks,
              darmbk.

              Comment


                #8
                Hi darmbk,

                May I see the complete code?

                The public data series will not affect this but the plot will.

                To export your script do the following:
                1. Click File -> Utilities -> Export NinjaScript
                2. Enter a unique name for the file in the value for 'File name:'
                3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
                4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


                By default your exported file will be in the following location:
                • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


                Below is a link to the help guide on Exporting NinjaScripts.
                http://www.ninjatrader.com/support/h...nt7/export.htm
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi darmbk,

                  I have received the indicator file from your private message and am taking a look now.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello darmbk,

                    Thanks for your note.

                    I am seeing that you have commented out the Values[1].Set() calls.

                    These wouldn't work because you have not added a custom data series and you have not added a second plot.

                    At this point Values[1] does not exist.

                    You will need to add a data series or add a plot (which is a simple way of adding a dataseries as plots are actually data series).

                    Below is a link to the help guide on Add() for indicators (for adding a plot).
                    http://www.ninjatrader.com/support/h...es/nt7/add.htm
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,

                      Ah I see. In my file you will see the dataseries defined under Properties but as you say, not used to Add a plot. I didn't realise I could set a plot to Transparent.

                      Thanks for this solution.
                      darmbk.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by funk10101, Today, 12:02 AM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by GLFX005, Today, 03:23 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by nandhumca, Yesterday, 03:41 PM
                      1 response
                      13 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by The_Sec, Yesterday, 03:37 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by vecnopus, Today, 06:15 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post vecnopus  
                      Working...
                      X