• 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

Strategy Analyzer back test with stop loss and profit target orders

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

  • NinjaTrader_Kate
    replied
    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:
    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
    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.

    Leave a comment:


  • RedDuke
    replied
    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

    Leave a comment:


  • NinjaTrader_Kate
    replied
    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.

    Leave a comment:


  • RedDuke
    replied
    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

    Leave a comment:


  • NinjaTrader_Kate
    replied
    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.

    Leave a comment:


  • RedDuke
    replied
    Sorry, zip fie is here.
    Attached Files

    Leave a comment:


  • RedDuke
    replied
    Hi Kate,

    I created zip file, so it is easier for you to set it up. here are the steps to reproduce:

    1) Import zip file
    2) Open Strategy analyzer and use the same setting as in attached screen shot (analyzer.jpg)

    The output windows will first display what is in screen shot "Strategy series.jpg", and only after it runs through every bars on the chart, it will run again through every bar and you will what is in "Indicator series.jpg"


    Since strategy calls indicator on every bar, I would have expected this behaviors in output windows:
    ....
    Series 1 minute - Strategy 5/9/2019 10:58:00 PM
    Series 1 minute - Indicator 5/9/2019 10:58:00 PM
    Series 1 minute - Strategy 5/9/2019 10:59:00 PM
    Series 1 minute - Indicator 5/9/2019 10:59:00 PM
    Series 1 hour - Strategy 5/9/2019 11:00:00 PM
    Series 1 hour - Indicator 5/9/2019 11:00:00 PM
    ......

    Instead I get this:

    ......................
    ​​​​​​​Series 1 minute - Strategy 5/9/2019 10:58:00 PM
    Series 1 minute - Strategy 5/9/2019 10:59:00 PM
    Series 1 hour - Strategy 5/9/2019 11:00:00 PM
    ......................
    .
    .
    .
    .......................
    Series 1 minute - Indicator 5/9/2019 10:58:00 PM
    Series 1 minute - Indicator 5/9/2019 10:59:00 PM
    Series 1 hour - Indicator 5/9/2019 11:00:00 PM
    .......................

    Thanks,
    redduke
    Attached Files

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello RedDuke,

    Thank you for your reply.

    I'm unable to reproduce this with your sample strategy - I get no prints from the indicator at all, only the strategy. If you're uncomfortable with posting the full strategy here, might you be able to send it in an email to platformsupport[at]ninjatrader[dot]com? Please include a link to this forum post and "2215973 ATTN Kate" in the body of the email. If not, please revise your example so I can reproduce your results.

    Thanks in advance; I look forward to assisting you further.

    Leave a comment:


  • RedDuke
    replied
    Hi Kate,

    The strategy calls the indicator. If I remove 1 min time frame all works well. I get 1 output line from strategy, on each bar, followed by 1 output line from indicator:
    Strategy
    Indicator
    Strategy
    Indicator
    Strategy
    Indicator......

    However, once 1 min data series is added, strategy first outputs a line for every bar, and only that calls indicator for every bar:
    Strategy
    Strategy
    Strategy
    Indicator
    Indicator
    Indicator......

    Thanks

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello RedDuke,

    Thank you for your reply.

    How are you backtesting? When I run your example strategy, I do not get any prints at all from your example indicator, only the strategy. If, however, I attach the indicator to the chart directly, I get the behavior you're describing. This would be normal - I would expect separate objects updating separately to be initially calculated separately as well for historical data.

    Thanks in advance; I look forward to assisting you further.

    Leave a comment:


  • RedDuke
    replied
    Hello,

    I came across a different issue after I added 1 min as additional data series to get a more granular execution. I ran it on 1 hour charts. The way my code is written, I have an indicator that produces a signal and strategy that calls it. Once signal is received, order gets submitted.

    Attached files have a super easy example of the issue. Both indicator and strategy just output bar time for each data series (main 1 hour and 1 min). If you run strategy through back test, it will first run through every bar as strategy and than through every bar as indicator. I would have expected the logic to be triggered on each bar, first strategy and than indicator it calls.

    Thanks
    Attached Files

    Leave a comment:


  • RedDuke
    replied
    Kate,

    Thanks for explaining it.

    Regards,
    redduke

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello RedDuke,

    Thank you for your reply.

    That's because high order fill resolution is specific to order methods - the Print statement would only be triggered by the primary series. If you want a print statement to print out every minute, you'd need to take the step of adding the secondary data series instead.

    Please let us know if we may be of further assistance to you.

    Leave a comment:


  • RedDuke
    replied
    If I put Print(Time[0]) in onbarupdate it is only triggered once per hour. If historical is set to high, how it triggered every min. I need to put my code in 1 min series so to speak.

    Thank you
    Last edited by RedDuke; 07-18-2019, 06:30 PM.

    Leave a comment:


  • NinjaTrader_Kate
    replied
    Hello RedDuke,

    Thank you for your reply.

    High order fill resolution takes care of that for you - so basically it's like adding the second data series manually. You don't need to worry about it because on bar update will trigger based on that 1 minute time period.

    Please let us know if we may be of further assistance to you.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by aslane, Today, 02:31 PM
0 responses
7 views
0 likes
Last Post aslane
by aslane
 
Started by stoner, 10-16-2019, 01:38 PM
5 responses
47 views
0 likes
Last Post sledge
by sledge
 
Started by music_p13, Today, 12:04 PM
1 response
23 views
0 likes
Last Post NinjaTrader_Kate  
Started by zaro33, Today, 10:55 AM
1 response
7 views
0 likes
Last Post NinjaTrader_Heath  
Started by itrader46, Today, 10:16 AM
5 responses
11 views
0 likes
Last Post NinjaTrader_Jesse  
Working...
X