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

Trade Entry Variable

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

    Trade Entry Variable

    I have an indicator which measures order flow and plots a triangle on the chart when orderflow exceeds a threshold, (either for buying or selling). I would like to create a variable which also exposes when the triangle is drawn on the chart (call it TradeDir) and it takes on a value of 1 for positive OF, -1 for negative OF, and 0 otherwise. when I create a plot to expose it, it screws up my chart and compresses everything. If I create a simple integer variable, can that take on a value of -1? If so, how do I expose it and make it available for the trading strategy I want to write, using that exposed variable to trigger a trade entrry?
    Any examples of this kind of thing in code that I could see?
    Thanks
    DaveN

    #2
    Hello Daven,

    Thank you for writing in.

    I have attached a sample strategy and indicator to demonstrate this.

    In the indicator, depending on whether there is gap up, down, or no gap, a int data series is set to 1,0,-1. Within the strategy, I reference this series to paint a bar yellow or pink depending on the value of series, GapUpPositve1GapDownNeg1Plot, in the indicator GapUpOrDownBoolAndPlotIndicatorExpose. I also draw arrows up or down within the strategy in the presence of a gap, depending on two series which are not plots, gapUp and gapDown. The attachment demonstrates how to expose values that are plots as well as not plots.

    Within the indicator, I also set the series GapUpPositve1GapDownNeg1Plot to a plot, and have this added in a new panel via the indicator. Then when adding the indicator to the strategy with AddChartIndicator , we avoid the issue with the plot and instrument bars conflicting for chart real estate.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      I'm reviewing they two scripts you sent, one for an indicator, and one for the strategy which uses the indicator. I can't simply re-use and re-name your code because my indicator already plots something in a secondary panel, so using a plot that will be much smaller than the basic information already being plotted will easily be obscured by the primary plots. Is it possible to expose a single variable which takes on a value of -1, 0, or +1, without converting it to a plot? It would be the same I think as having two binary variables, one which would be true for long entries, otherwise, false, and one which would be true for short entries, otherwise false, and have it exposed so a strategy could access it. I think either one could be made to work if it's value is exposed as something other than a plot.
      Thanks
      DaveN

      Comment


        #4
        Hello Daven,

        Yes, it is possible to expose a variable which take the value of -1, 0, +1 without converting it to a plot.
        In the example I provided the following line from the strategy would be referencing that int data series,

        Code:
        GapUpOrDownBoolAndPlotIndicatorExpose().GapUpPositve1GapDownNeg1Plot[0]
        While it does set a plot, you could remove that specific plot from the indicator and the strategy still could reference it, because the series is exposed. You could also remove the reference to AddChartIndicator from the strategy to not have the plot applied.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hello Alan. I know it's been a while since you last wrote on this thread. I have a related issue.

          I have a strategy that runs on UniRenko bars as the primary data series and needs to reference plots from an indicator that runs on a secondary data series based on 12 Range bars, to determine automatic entry conditions.

          The issue is that when I add the secondary data series from the strategy nothing is accessible and the indicator won´t plot on the chart if set to reference the secondary data series If I set it to reference the primary data series it plots fine and the plots are accessible. But, as mentioned, I need the conditions from the secondary data series, not the primary.

          I'm sending an example strategy and the indicator that shows the issue. From the "properties" section you may switch the secondary data series on / off-. You'll notice that the indicator plots fine and may access variables from the indicator only from the primary data series

          Do you know how to solve this issue?

          Thank you.

          BobPerez
          Attached Files
          Last edited by bobperez; 11-24-2022, 06:58 PM.

          Comment


            #6
            Hi Bob, thanks for posting. The documentation page on AddChartIndicator has a note about this:

            •An indicator being added via AddChartIndicator() cannot use any additional data series hosted by the calling strategy, but can only use the strategy's primary data series. If you wish to use a different data series for the indicator's input, you can add the series in the indicator itself and explicitly reference it in the indicator code

            E.g. Add the second series to the indicator code, calculate the indicator based on the secondary series, then you can use AddChartIndicator. The indicator also does not add any plots, so calculating the secondary series from this indicator will be nessecary.

            Kind regards.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Thank you, Chris. Do you happen to have an example of your explanation?

              In particular, you mention "The indicator also does not add any plots, so calculating the secondary series from this indicator will be necessary" Do you mean any indicator or the one I added with the example strategy?

              My primary series is Unirenko T2,O1,R8. The secondary series needed for entry order is Range(12).

              BobPerez
              Last edited by bobperez; 11-25-2022, 10:54 AM.

              Comment


                #8
                Hi Bob, thanks for the follow up. I misspoke, the indicator you posted does add plots but in order to use the secondary data series, you need to add the secondary series to the indicator itself and calculate the indicator logic based on that secondary series. We have an existing example of this here:



                Kind regards,
                -ChrisL​
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chris, I was able to resolve the issue with your support.

                  1. I created a copy of my indicator as myIndicatorSecondSeries
                  2. In myIndicatorSecondSeries I added the secondary series Range 12
                  3. All the calculations are made referencing the second series. E.G. Closes[1][0] > CLoses[1][1]
                  4. My strategy instantiates myIndicatorSecondSeries
                  5. I'm plotting this indicator with AddChartIndicator()
                  6. The strategy has access to the variables I need from myIndicatorSecondSeries

                  All good!
                  Thanks,

                  BobPerez
                  ​​

                  Comment


                    #10
                    Hi Bob, Im happy to help out. Please let me know if you have anything else I can help with.
                    Chris L.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by mmenigma, Today, 02:22 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post mmenigma  
                    Started by frankthearm, Today, 09:08 AM
                    9 responses
                    34 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by NRITV, Today, 01:15 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post NRITV
                    by NRITV
                     
                    Started by maybeimnotrader, Yesterday, 05:46 PM
                    5 responses
                    26 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by quantismo, Yesterday, 05:13 PM
                    2 responses
                    20 views
                    0 likes
                    Last Post quantismo  
                    Working...
                    X