Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder did not work when used in Strategy Analyzer

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

    Strategy Builder did not work when used in Strategy Analyzer

    Hi, the strategy that I created from Strategy Builder (SuperTrend and RSI) does not work on Strategy Analyzer. I tried testing each condition and it works on strategy analyzer, its even working when I combine 3 conditions, however, when I combine 4 conditions, it did not work.. Can you help me on this? Attached is the screenshot in Strategy Builder. Thanks

    Click image for larger version

Name:	Buy Screenshot.png
Views:	131
Size:	38.8 KB
ID:	1323160 Click image for larger version

Name:	Sell Screenshot.png
Views:	48
Size:	39.6 KB
ID:	1323161

    Below is the copy of the main code:

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class SuperTrendRSI : Strategy
    {
    private RSI RSI1;
    private NinjaTrader.NinjaScript.Indicators.TradingIndicato rs.SuperTrend SuperTrend1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"SuperTrend + RSI";
    Name = "SuperTrendRSI";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = false;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Start_Time = DateTime.Parse("08:00", System.Globalization.CultureInfo.InvariantCulture) ;
    Stop_Time = DateTime.Parse("16:00", System.Globalization.CultureInfo.InvariantCulture) ;
    Order_Quantity = 1;
    Profit_Target = 20;
    Stop_Loss = 20;
    ST_Multiplier = 3;
    ST_ATR = 7;
    RSI_Period = 14;
    RSI_Smooth = 3;
    RSI_BuyTrigger = 30;
    RSI_SellTrigger = 70;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    RSI1 = RSI(Close, Convert.ToInt32(RSI_Period), Convert.ToInt32(RSI_Smooth));
    SuperTrend1 = SuperTrend(Close, ST_Multiplier, Convert.ToInt32(ST_ATR));
    SetProfitTarget(@"", CalculationMode.Ticks, Profit_Target);
    SetStopLoss(@"", CalculationMode.Ticks, Stop_Loss, true);
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((Times[0][0].TimeOfDay >= Start_Time.TimeOfDay)
    && (Times[0][0].TimeOfDay <= Stop_Time.TimeOfDay)
    && (Position.MarketPosition == MarketPosition.Flat)
    && (RSI1.Default[0] < RSI_BuyTrigger)
    && (SuperTrend1.Buy[0] > 0))
    {
    EnterLong(Convert.ToInt32(Order_Quantity), "");
    BackBrushAll = Brushes.Lime;
    }

    // Set 2
    if ((Times[0][0].TimeOfDay >= Start_Time.TimeOfDay)
    && (Times[0][0].TimeOfDay <= Stop_Time.TimeOfDay)
    && (Position.MarketPosition == MarketPosition.Flat)
    && (RSI1.Default[0] > RSI_SellTrigger)
    && (SuperTrend1.Sell[0] > 0))
    {
    EnterShort(Convert.ToInt32(Order_Quantity), "");
    BackBrushAll = Brushes.Red;
    }

    // Set 3
    if ((Times[0][0].TimeOfDay >= Stop_Time.TimeOfDay)
    && (Position.MarketPosition == MarketPosition.Long))
    {
    ExitLong(Convert.ToInt32(Position.Quantity), "", @"");
    }

    // Set 4
    if ((Times[0][0].TimeOfDay >= Stop_Time.TimeOfDay)
    && (Position.MarketPosition == MarketPosition.Short))
    {
    ExitShort(Convert.ToInt32(Position.Quantity), "", @"");
    }

    #2
    Hello mrrdiamante,

    Thank you for your post.

    Can you provide further details as to what you mean by "does not work"?

    Is the strategy generating no results? Are you getting any errors?

    Please answer all of the following questions:
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
    • Do you see similar results when running the same test on the SampleMaCrossOver strategy in NinjaTrader with the same settings as your strategy?
    • Who are you connected to? This is displayed in green in the lower-left corner of the Control Center window.
    • Are you connected to your data feed provider when running this test?
    • What instrument(s) (and expiry if applicable) have you selected?
    • What Data Series Type have you selected? Example: Tick, Minute, Day
    • What From and To date is selected?
    • If you open a chart for the same instrument(s) and the same date range, then right-click the chart and select 'Reload all historical data' is the historical data showing on the chart?
    • Is your strategy a multi-instrument or multi-time frame strategy?
    • Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

    Comment


      #3
      Hi,

      Can you provide further details as to what you mean by "does not work"? The strategy is generating no results in strategy analyzer.

      Is the strategy generating no results? Are you getting any errors? No errors. The strategy is generating no results in strategy analyzer.

      Please answer all of the following questions:
      • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?) 8.1.3.1 64-bit
      I think the below questions are not relevant as I am using the same template for my other strategy and it is working fine in any timeframe and any instrument and I'm not getting any errors on the log. I am just changing the main conditions for the buy and sell trigger.

      For buy trigger (2 conditions):
      1. SuperTrend Buy Signal
      2. RSI < Buy Trigger Number (e.g. 30)

      For sell trigger (2 conditions):
      1. SuperTrend Buy Signal
      2. RSI > Sell Trigger Number (e.g. 70)

      I did I trial and error test to single out which of the 4 conditions is not working by individually testing them and combining them. When I use any of the 4 conditions above individually or any 3 combinations of it, it is working and generating results in strategy analyzer, however, when I use 4 of them, it does not generate any results in strategy analyzer. Also, when I deploy it in chart, it does now show also any results in the performance and there was no error in the log.
      • Do you see similar results when running the same test on the SampleMaCrossOver strategy in NinjaTrader with the same settings as your strategy?
      • Who are you connected to? This is displayed in green in the lower-left corner of the Control Center window.
      • Are you connected to your data feed provider when running this test?
      • What instrument(s) (and expiry if applicable) have you selected?
      • What Data Series Type have you selected? Example: Tick, Minute, Day
      • What From and To date is selected?
      • If you open a chart for the same instrument(s) and the same date range, then right-click the chart and select 'Reload all historical data' is the historical data showing on the chart?
      • Is your strategy a multi-instrument or multi-time frame strategy?
      • Do you receive an error on the screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?

      Comment


        #4
        Hello,

        If the strategy is not firing any trades you'll need to debug it.

        To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the date time of the bar and all values compared in every condition that places an order.

        The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

        The debugging print output should clearly show what the condition is, what time the conditions are being compared, all values being compared, and how they are being compared.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Further, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        After enabling TraceOrders remove the instance of the strategy from the Configured list in the Strategies window and add a new instance of the strategy from the Available list.

        I am happy to assist you with analyzing the output from the output window.


        Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.


        Below is a link to a support article that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.

        https://support.ninjatrader.com/s/ar...nd-TraceOrders

        Comment


          #5
          Hi,

          I think I don't need to print the script. I was able to pinpoint the problem.. Actually, there was no problem with the code. It's just that my conditions was too strict that it did not trigger any trades.. hahaha.. apologies for this.

          Also, I'm checking the code visually by plotting in the chart the indicators and painting it red or green when triggered..

          Click image for larger version

Name:	Visual Test.png
Views:	61
Size:	439.8 KB
ID:	1323235

          Thanks again for the quick response.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          48 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X