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

Strategy Analyzer back test with stop loss and profit target orders

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

    #16
    Hello RedDuke,

    Thank you for your reply.

    Your attached sample is exactly the same as your previous example and I still cannot replicate what you're experiencing. Attached is an example of my output from running the strategy (note that my primary series is a five second series so I can see results more quickly, which is why there are more "1 hour" prints than minute prints):

    Code:
    Enabling NinjaScript strategy 'SampleStr/174663544' : On starting a real-time strategy - StartBehavior=ImmediatelySubmit EntryHandling=All entries EntriesPerDirection=2 StopTargetHandling=By strategy position ErrorHandling=Ignore all errors ExitOnSessionClose=False SetOrderQuantityBy=Strategy ConnectionLossHandling=Keep running DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=True Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
    Series 1 hour - Strategy 7/24/2019 7:58:35 AM
    Series 1 hour - Strategy 7/24/2019 7:58:40 AM
    Series 1 hour - Strategy 7/24/2019 7:58:45 AM
    Series 1 hour - Strategy 7/24/2019 7:58:50 AM
    Series 1 hour - Strategy 7/24/2019 7:58:55 AM
    Series 1 hour - Strategy 7/24/2019 7:59:00 AM
    Series 1 minute - Strategy 7/24/2019 7:59:00 AM
    Series 1 hour - Strategy 7/24/2019 7:59:05 AM
    Series 1 hour - Strategy 7/24/2019 7:59:10 AM
    Series 1 hour - Strategy 7/24/2019 7:59:15 AM
    Series 1 hour - Strategy 7/24/2019 7:59:20 AM
    Series 1 hour - Strategy 7/24/2019 7:59:25 AM
    Series 1 hour - Strategy 7/24/2019 7:59:30 AM
    Series 1 hour - Strategy 7/24/2019 7:59:35 AM
    Series 1 hour - Strategy 7/24/2019 7:59:40 AM
    Series 1 hour - Strategy 7/24/2019 7:59:45 AM
    Series 1 hour - Strategy 7/24/2019 7:59:50 AM
    Series 1 hour - Strategy 7/24/2019 7:59:55 AM
    Series 1 hour - Strategy 7/24/2019 8:00:00 AM
    Series 1 minute - Strategy 7/24/2019 8:00:00 AM
    Series 1 hour - Strategy 7/24/2019 8:00:05 AM
    Series 1 hour - Strategy 7/24/2019 8:00:10 AM
    Series 1 hour - Strategy 7/24/2019 8:00:15 AM
    Series 1 hour - Strategy 7/24/2019 8:00:20 AM
    Series 1 hour - Strategy 7/24/2019 8:00:25 AM
    Series 1 hour - Strategy 7/24/2019 8:00:30 AM
    Series 1 hour - Strategy 7/24/2019 8:00:35 AM
    Series 1 hour - Strategy 7/24/2019 8:00:40 AM
    Series 1 hour - Strategy 7/24/2019 8:00:45 AM
    Series 1 hour - Strategy 7/24/2019 8:00:50 AM
    Series 1 hour - Strategy 7/24/2019 8:00:55 AM
    Series 1 hour - Strategy 7/24/2019 8:01:00 AM
    Series 1 minute - Strategy 7/24/2019 8:01:00 AM
    Series 1 hour - Strategy 7/24/2019 8:01:05 AM
    Series 1 hour - Strategy 7/24/2019 8:01:10 AM
    Series 1 hour - Strategy 7/24/2019 8:01:15 AM
    Series 1 hour - Strategy 7/24/2019 8:01:20 AM
    Series 1 hour - Strategy 7/24/2019 8:01:25 AM
    Series 1 hour - Strategy 7/24/2019 8:01:30 AM
    Series 1 hour - Strategy 7/24/2019 8:01:35 AM
    I have not gotten any prints from the indicator unless I add the indicator separately from the strategy, which is expected behavior.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #17
      Hi Kate,

      I was able to almost figure it out, the issue was that I was not calling Update() method (in indicator) when calling indicator, which in turn calls OnBarUpdate Attached zip file that the new code. Here is what output looks like now;

      Strategy 1 hour bar time 4/30/2019 7:00:00 PM
      Indicator 1 hour bar time 4/30/2019 7:00:00 PM (this was correctly printed in OnBarUpdate in indicator)
      Strategy 1 minute bar time 4/30/2019 7:00:00 PM
      Strategy 1 minute bar time 4/30/2019 7:01:00 PM

      My issue now is that I need to invoke OnBarUpdate in indicator when processing 1 min data series in Strategy.

      Currently OnBarUpdate, in indicator, only gets triggered when strategy processes the same data series (1 hour). I need to be able to keep triggering OnBarUpdate in indicator, for every 1 min in the strategy. Is it possible?

      Thanks,
      redduke
      Attached Files

      Comment


        #18
        Hello RedDuke,

        Thank you for your reply.

        Try also adding a secondary 1 minute data series to the indicator as well, then try calling the update. Does that give the results you'd expect?

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #19
          I tried it, and it did not work. What I need to to keep triggering OnBarUpdate in indicator on main 1 hour bar, while strategy processing 1 min data series. Basically a trigger for every 1 min Bar in Strategy.

          Thanks

          Comment


            #20
            Hello RedDuke,

            Thank you for your reply.

            While the prints aren't in the order you'd expect, the indicator is being triggered each minute as well as each hour.

            I slightly modified the OnBarUpdate() of the example strategy:

            Code:
                    protected override void OnBarUpdate()
                    {
                        //Add your custom strategy logic here.
                        if(BarsInProgress == 0){
                            TestSequence.ForceOnBarUpdate();
                            Print("Strategy 1 hour bar time "+Times[0][0]);
                        }
                        else if(BarsInProgress == 1){
            
                            TestSequence.ForceOnBarUpdate();
                            Print("Strategy 1 minute bar time "+Times[1][0]);
            }

            Here's prints from my latest test: (note that I'm running this on a primary series of 3 minutes rather than an hour for quicker testing)
            Code:
            [INDENT]Strategy 1 hour bar time 7/25/2019 10:45:00 AM
            Strategy 1 minute bar time 7/25/2019 10:45:00 AM
            Strategy 1 minute bar time 7/25/2019 10:46:00 AM
            Strategy 1 minute bar time 7/25/2019 10:47:00 AM
            Indicator 1 hour bar time 7/25/2019 10:48:00 AM
            Indicator 1 minute bar time7/25/2019 10:46:00 AM
            Indicator 1 minute bar time7/25/2019 10:47:00 AM
            Indicator 1 minute bar time7/25/2019 10:48:00 AM
            Strategy 1 hour bar time 7/25/2019 10:48:00 AM
            Strategy 1 minute bar time 7/25/2019 10:48:00 AM
            Strategy 1 minute bar time 7/25/2019 10:49:00 AM
            Strategy 1 minute bar time 7/25/2019 10:50:00 AM
            Indicator 1 hour bar time 7/25/2019 10:51:00 AM
            Indicator 1 minute bar time7/25/2019 10:49:00 AM
            Indicator 1 minute bar time7/25/2019 10:50:00 AM
            Indicator 1 minute bar time7/25/2019 10:51:00 AM[/INDENT]
            I've checked with my colleagues and they advise this pattern is to be expected when calling an indicator from a hosting script. BarsInProgress order unrolls by time, so BIP 0 prints should be beform the BIP 1 prints. It also appears that when using the indicator's Update() method, a hosted indicator's prints will appear in the log before the prints from the strategy. Both are firing each minute, it's simply the print order.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by FrazMann, Today, 11:21 AM
            2 responses
            6 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by rjbtrade1, 11-30-2023, 04:38 PM
            2 responses
            80 views
            0 likes
            Last Post DavidHP
            by DavidHP
             
            Started by Spiderbird, Today, 12:15 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Started by lorem, Yesterday, 09:18 AM
            5 responses
            18 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            12 responses
            42 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X