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

Help me understand this.

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

    Help me understand this.

    I've got half a day in this and it's obviously time to try the experts. There are just so many of them here.

    I have a chart which holds a strategy and an indicator. The Indicator exposes buy/sell signals to the Strategy, as well as the "CurrentStop" price.

    This is in the Indicator Variables section:

    privatedouble stopTicks = 8;


    This is in the Properties section;

    [Description("Risk per trade (ticks)")]
    [Category(
    "Trade Parameters")]
    publicdouble StopTicks
    {
    get { return stopTicks; }
    set { stopTicks = value; }
    }


    I modified the script so that it only does ONE thing. It prints the value of StopTicks whenever it gets a trade signal. There are 4 trade signals.

    Here is the output window when I load the scripts.



    **NT** Disabling NinjaScript strategy 'ScalpManager/967ec46f107d4ad8b0a556bb17beb25f'
    **NT** Enabling NinjaScript strategy 'ScalpManager/967ec46f107d4ad8b0a556bb17beb25f' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
    8
    8
    8
    8
    8
    8
    8
    8
    21
    21
    21
    21


    Remember, the code does nothing but print the value of StopTicks, and there are only 4 trades.


    The problem:


    StopTicks is "user adjusted" to 21 before it is run, but the script always uses the default setting of 8.


    Also, there should only be 4 21's printed there, nothing else. Why does it look as if the bars are processed 3 times? That can be the only reason for all those 8's and 21's.


    The Indicator script exposes the buy/sell signals to the Strategy very well, but the stop is always wrong, being set to 8 ticks instead of 21. You can see by the last four printouts that the script can "see" the setting of 21. Why does it use 8.


    Am I allowed to do what I am doing? Is there a work around to do what I need? Are you going to make me publish the entire script?

    Thx in advance.


    TD






    #2
    TD,

    Are you printing those values from the strategy only?

    From which section in the code do you print them to check?

    Commenting with the script would be easier for us, but if you don't want to publish it, that's ok, too.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      NTB,
      Thx for the reply, you guys are great!

      It is printing from within the indicator, where buy/sell signals occur. The indicator draws the trade signals on the chart, and it draws a Stop level on the chart (as a horizontal line). The Stop level, as it is drawn, is correct. The trades however, all exit before it reaches the stop level and is what started me working on this. I can tell that they are exiting on the default value of 8 ticks.

      I made the printout to help you see what I am seeing. I was hoping you could see immediately what was going on by the printout. I can't understand why it looks like that at all, except for the last four lines ( the 21's) which I am expecting. It looks as if the bars are processed 3 times, and the first two times, it is using the 8 ticks default, and then on the final run, it is using the 21. But why does it trade with the 8?

      Comment


        #4
        NTB,

        By the way, it does this in replay or in real time if it helps.
        TD

        Comment


          #5
          Hello TikDaddy,

          The public property stopTicks is related only to the indicator, so setting the indicator value won't adjust the strategy equivalent.

          It may help to add CurrentBar as well as the context of the print method to the output, so you can evaluate if it's processing multiple times per bar and from only within the indicator context.

          Print (this.ToString() + CurrentBar + ": " + stopTicks);
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            NTR

            The stop price is computed in the indicator, and then it is exposed to the strategy in the "Exposed External Variables" section (as CurrentStop). The Strategy is picking it up, but it picks up the wrong value as computed with 8 ticks instead of the "user defined" setting of 21.

            The CurrentBar suggestion is a good one. I will do it and get ya back.

            Thx for helping.

            Comment


              #7
              NTR,

              I don't think I answered your question fully. The print statement is located in the indicator.

              TD

              Comment


                #8
                NT Gang,

                Below is the printout with your new print statement installed. Its is most enlightening.

                **NT** Disabling NinjaScript strategy 'ScalpManager/36671f2eb4444fc998383165117c1afe'
                **NT** Enabling NinjaScript strategy 'ScalpManager/36671f2eb4444fc998383165117c1afe' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True MaxRestarts=4 in 5 minutes
                Scalper(6E 09-10 (343 Volume))1163: 8

                Scalper(6E 09-10 (343 Volume))1239: 8

                Scalper(6E 09-10 (343 Volume))1404: 8
                Scalper(6E 09-10 (343 Volume))1474: 8
                Scalper(6E 09-10 (343 Volume))1536: 8

                Scalper(6E 09-10 (343 Volume))1552: 8
                Scalper(6E 09-10 (343 Volume))1937: 8
                Scalper(6E 09-10 (343 Volume))2041: 8

                Scalper(6E 09-10 (343 Volume))2054: 8

                Scalper(6E 09-10 (343 Volume))2063: 8

                Scalper(6E 09-10 (343 Volume))2073: 8

                Scalper(6E 09-10 (343 Volume))2148: 8

                Scalper(6E 09-10 (343 Volume))1163: 21

                Scalper(6E 09-10 (343 Volume))1239: 21
                Scalper(6E 09-10 (343 Volume))1404: 21
                Scalper(6E 09-10 (343 Volume))1474: 21
                Scalper(6E 09-10 (343 Volume))1937: 21


                It looks as if it is processing the bars 2 times. The print statement is inside the code section that generates trade signals, so therefore there is a line in the printout for each trade that is generated. When the script is running with the 8 tick stop, it generates more trades because it gets stopped out so many times. That explains the extra "8's" in the printout. I made sure to have no other charts running just in case they would interfere with each other and so this printout reflects what is really happening.

                So:

                Q1:
                Why would the script run twice?

                Q2
                Can anyone explain to me what happens when a chart is loaded that has Indicators and Strategies attached to it? Is there a link to such an explanation.

                Q3
                If I compile a script and "reload" the script in one chart, do other open charts that have this same script reload it also?

                As always, Thx for the efforts.

                TD

                Comment


                  #9
                  1) Hard to say due to many potential sequences of adding indicator / setting property / enabling strategy / viewing output. What order are you doing this?

                  2) Logic is processed for both. They don't operate any differently except that strategies offer order placement methods.

                  3) It reloads ALL ninjascript, even from other charts.

                  I would look at what benefit you're getting by exposing the indicators public property to the strategy. From within the strategy you can draw, add plots, and set the stoploss value.

                  If you want to track this down some more, please share the strategy code that accesses the stopTicks variable from the indicator.
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    NTR,

                    The reason that I am doing it this way is that the Indicator is already written, and it is complex with many plots and many variables. To make it trade, all I needed to do was expose these variables.

                    "TradingLong"
                    "TradingShort"

                    It seemed brain dead simple. The Strat goes long when it sees TradingLong and it does an ExitLong() when TradingLong goes false. You gotta admit, it's simple !

                    The Strat is no problem at all. The problem is that the INDICATOR is setting "TradingLong" to false, before it reaches the desired Stop price even though it clearly "sees" the desired setting of 21 on it's second pass through the bar series. And, it draws the stop level correctly on the screen. If I hard code the stop to 21 ticks, it works as expected.

                    I was hoping you guys would recognize the symptoms and just tell me what it is that makes an Indicator appear to be processing the bars multiple times.

                    I don't want to waste any more of your time on this though. It is clear that I need to build a script to reproduce the problem and then play with it until I find out why it does what it does.

                    Thx for the help so far. When I figure it out, I'll post here for posterity. Wish me luck

                    TD

                    Comment


                      #11
                      Thank you for your comments. Unfortunately it's hard to tell exactly what's going on without seeing more code.

                      There may be reasons to have some logic in an indicator and other logic in a strategy, but having inputs related to the strategy outside of the strategy context could cause these issues. All strategy input parameters should be within the strategy.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        Did you ever get an answer to this.

                        TikDaddy
                        I was going to do something very similar. I don't want to go down this path if its problematic. Can you tell me if you figured out or were given an answer.

                        Thanks.
                        Jerry

                        Originally posted by TikDaddy View Post
                        NTR,

                        The reason that I am doing it this way is that the Indicator is already written, and it is complex with many plots and many variables. To make it trade, all I needed to do was expose these variables.

                        "TradingLong"
                        "TradingShort"

                        It seemed brain dead simple. The Strat goes long when it sees TradingLong and it does an ExitLong() when TradingLong goes false. You gotta admit, it's simple !

                        The Strat is no problem at all. The problem is that the INDICATOR is setting "TradingLong" to false, before it reaches the desired Stop price even though it clearly "sees" the desired setting of 21 on it's second pass through the bar series. And, it draws the stop level correctly on the screen. If I hard code the stop to 21 ticks, it works as expected.

                        I was hoping you guys would recognize the symptoms and just tell me what it is that makes an Indicator appear to be processing the bars multiple times.

                        I don't want to waste any more of your time on this though. It is clear that I need to build a script to reproduce the problem and then play with it until I find out why it does what it does.

                        Thx for the help so far. When I figure it out, I'll post here for posterity. Wish me luck

                        TD

                        Comment


                          #13
                          Originally posted by JerryWar View Post
                          TikDaddy
                          I was going to do something very similar. I don't want to go down this path if its problematic. Can you tell me if you figured out or were given an answer.

                          Thanks.
                          Jerry
                          There shouldn't be any problems.

                          It looks like he has a logic problem of some sort.

                          Comment


                            #14
                            Thanks Sledge

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by StockTrader88, 03-06-2021, 08:58 AM
                            45 responses
                            3,992 views
                            3 likes
                            Last Post johntraderuser2  
                            Started by TAJTrades, Today, 09:46 AM
                            0 responses
                            7 views
                            0 likes
                            Last Post TAJTrades  
                            Started by rhyminkevin, Yesterday, 04:58 PM
                            5 responses
                            62 views
                            0 likes
                            Last Post dp8282
                            by dp8282
                             
                            Started by realblubb, Today, 09:28 AM
                            0 responses
                            8 views
                            0 likes
                            Last Post realblubb  
                            Started by AaronKoRn, Yesterday, 09:49 PM
                            1 response
                            19 views
                            0 likes
                            Last Post Rikazkhan007  
                            Working...
                            X