Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Conditions for an Entry Strategy Builder

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

    Conditions for an Entry Strategy Builder

    Hello,

    I am trying to set some conditions for my Entry:

    1 - When the EMA8 crosses below EMA20 (below SMA50)
    2- The EMA20 doesnt cross the SMA50
    3 - the EMA8 crosses above EMA20 (below SMA50)

    Entry on the First Bar when the EMA 8 and the EMA20 cross above has made. Which conditions should I take to have this Entry?

    Click image for larger version

Name:	image.png
Views:	632
Size:	50.9 KB
ID:	1274971

    This would be a SELL Entry. of course for a BUY entry the conditions are the opposite.

    Thanks!!!​

    #2
    Hello tradingnasdaqprueba,

    Thank you for your inquiry.

    Can you please clarify your conditions for entry? Your first condition and third condition cannot both happen on the same bar (EMA8 cannot both cross above and cross below the EMA20 on the same bar).

    If you want to check if a cross has happened within the last x number of bars, you can specify that in your condition. This way you can check if a cross above or a cross below has happened within a specified number of bars ago.

    CrossAbove - https://ninjatrader.com/support/help...crossabove.htm
    CrossBelow - https://ninjatrader.com/support/help...crossbelow.htm

    For your second condition, you can have a bool which is true when a cross has occurred and false when no cross occurred. Add a set to check if a CrossAbove(EMA(20), SMA(50)) or a CrossBelow(EMA(20), SMA(50)) has occurred and if so, set the bool to true.

    Then in another set, you can add a condition to check if your bool is false to enter.

    Comment


      #3
      Hello Gaby,

      I made this sets, but nothing happens... what I did wrong?

      Click image for larger version

Name:	image.png
Views:	488
Size:	37.8 KB
ID:	1275101

      Click image for larger version

Name:	image.png
Views:	483
Size:	40.5 KB
ID:	1275102

      Click image for larger version

Name:	image.png
Views:	490
Size:	40.3 KB
ID:	1275103


      Thanks!​​​

      Comment


        #4
        Hello,

        Your actions contain no order methods, so your strategy is taking no trades. In the Actions section, click on 'add' and you can select one under 'Order Management'.

        Also, please note that your first set is using 'If Any' so only your first condition in that set will ever evaluate as true.

        Please let me know if you have any other questions.

        Comment


          #5
          Hello Gaby,

          I only want to paint the Candle so that when the conditions are met, the color of the Candle changes.

          The conditions for my Entry are the following:

          BUY ENTRIES:

          1 - EMA10 CROSSBELOW EMA20 IN THE LAST 15-20 CANDLES
          2 - EMA10 CROSSABOVE EMA20 IN THE ACTUAL CANDLE
          3 - BAR CLOSE IS ABOVE EMA20
          4- THERE WAS NO CROSS ABOVE BETWEEN EMA20 AND SMA50 IN THE LAST 20 CANDLES (CROSSLOW = FALSE)
          5 - EMA20 IS ABOVE SMA50 IN THE ACTUAL CANDLE
          ENTRY WOULD BE THE FOLLOWING CANDLE OF THE EMA10 CROSSABOVE EMA20 WHEN ALL CONDITIONS ARE MET


          SELL ENTRIES:

          1 - EMA10 CROSSABOVE EMA20 IN THE LAST 15-20 CANDLES
          2 - EMA10 CROSSBELOW EMA20 IN THE ACTUAL CANDLE
          3 - BAR CLOSE IS BELOW EMA20
          4- THERE WAS NO CROSS BELOW BETWEEN EMA20 AND SMA50 IN THE LAST 20 CANDLES CROSUP = FALSE
          5 - EMA20 IS BELOW SMA50 IN THE ACTUAL CANDLE
          ENTRY WOULD BE THE FOLLOWING CANDLE OF THE EMA10 CROSSBELOW EMA20 WHEN ALL CONDITIONS ARE MET

          Here my actual sets for the conditions, still nothing happens here:

          Click image for larger version

Name:	image.png
Views:	499
Size:	30.1 KB
ID:	1275319
          Click image for larger version

Name:	image.png
Views:	479
Size:	30.7 KB
ID:	1275320
          Click image for larger version

Name:	image.png
Views:	488
Size:	39.8 KB
ID:	1275321
          Click image for larger version

Name:	image.png
Views:	492
Size:	39.4 KB
ID:	1275322


          Thanks!!!​​​​​

          Comment


            #6
            Hello,

            If the strategy is applied to a chart, is there data with new bars appearing on the chart the Strategy is applied to?

            Is the strategy showing as enabled on the Strategies tab of the Control Center?

            If the strategy is in the Strategy Analyzer, is there data appearing on the Chart Display of the Strategy Analyzer?

            Importantly, are there errors appearing on the Log tab of the Control Center?

            Try testing the Sample MA Crossover strategy included with NinjaTrader on the same chart or Strategy Analyzer using the same instrument, bar type, interval, and date range.

            Do you see results with the Sample MA Crossover strategy? (This would confirm for us data is available and the issue is with the logic in the custom script)


            If the strategy is getting data and the strategy is enabled or a backtest is run with no errors in the Log tab of the Control Center, and the Sample MA Crossover is returning results, then would likely indicate the logic conditions in the custom strategy did not evaluate as true.

            In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating.

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

            https://ninjatrader.com/support/foru...121#post791121

            Print the time of the bar and all values used in the conditions that submit entry orders. Include labels for all values and comparison operators.

            Let me know if you need any assistance creating a print.

            Save the output from the output window to a text file and provide this with your reply.

            I'll be happy to assist with analyzing the output.

            Comment


              #7
              Hey Gaby,

              Thanks for the help! You are AWESOME!!!

              I could make the strategy work by simply removing the TRUE/FALSE condition, this has to be a simple codition as: EMA(20) > SMA(50) (also, there is no cross).

              The thing is that I would like to change the color no from the next opening bar when the conditions are met, but the bar ago... How can I do this? I tried different configurations but I don`t get what I want... This would be very helpfull because it happens sometimes with my other strategies.

              See the image:

              Click image for larger version

Name:	image.png
Views:	491
Size:	16.7 KB
ID:	1275732


              Also the SETS that I have:

              Click image for larger version

Name:	image.png
Views:	479
Size:	45.6 KB
ID:	1275733
              Click image for larger version

Name:	image.png
Views:	485
Size:	46.1 KB
ID:	1275734

              Thanks for the help!!!​​

              Comment


                #8
                Hello,

                You would need to unlock your script to change the color of the bar 1 bar ago. After unlocking, you could use BarBrushes to accomplish this.

                BarBrushes - https://ninjatrader.com/support/help...barbrushes.htm

                Code:
                BarBrushes[1] = Brushes.MediumPurple;
                Please let us know if you have any other questions.

                Comment


                  #9
                  Hello Gaby,

                  Now works perfect thanks!

                  I also would like to do this: I have created an indicator to automatically draw a region between 2 prices where I consider a Market Range, I would like that my strategy doesnt work between these Prices, so that the candle is only coloured when a condition is TRUE outside this region.

                  See image:

                  Click image for larger version

Name:	image.png
Views:	488
Size:	15.4 KB
ID:	1276162

                  Comment


                    #10
                    Hello,

                    You can add a condition that says

                    Code:
                    if (Close[0] < yourUpperPriceBound && Close[0] > yourLowerPriceBound) {
                    
                    //do something
                    
                    }
                    This condition says, if the price is lower than your upper price boundary and higher than your lower price boundary, then do something (such as color a candle).

                    Comment


                      #11
                      Hey Gaby,

                      Okey understand, but how can I link it with my indicator? How would be the steps?

                      Thanks!

                      Comment


                        #12
                        Hello,

                        You can modify the script to expose the values you want to use in another indicator.

                        This example from our help guide illustrates how to expose indicator values that are not plots so they may be accessed by another script:

                        https://ninjatrader.com/support/help...alues_that.htm

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

                        Comment


                          #13
                          Hello Gaby,

                          I need your help here... I want to get the values from the indicator below (Between BANDASUPERIOR and BANDAINFERIOR or Between SUBBANDASUPERIOR and SUBBANDAINFERIOR) to my Strategy so that when the bar closes between the values, the strategy stops colouring the bars, the strategy stops. I made the below coding in my strategy but I dont know how to proceed I get a lot of CS1501 and CS0103 errors…

                          Click image for larger version

Name:	dataurl327981.png
Views:	534
Size:	15.0 KB
ID:	1276334

                          CODE FIRELINE

                          Code:
                          namespace NinjaTrader.NinjaScript.Indicators
                          {
                          public class FIRELINETR : Indicator
                          {
                          protected override void OnStateChange()
                          {
                          if (State == State.SetDefaults)
                          {
                          Description = @"Enter the description for your new custom Indicator here.";
                          Name = "FIRELINETR";
                          Calculate = Calculate.OnBarClose;
                          IsOverlay = false;
                          DisplayInDataBox = true;
                          DrawOnPricePanel = true;
                          DrawHorizontalGridLines = true;
                          DrawVerticalGridLines = true;
                          PaintPriceMarkers = true;
                          ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                          //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                          //See Help Guide for additional information.
                          IsSuspendedWhileInactive = true;
                          FIRELINE = 0;
                          BANDASUPERIOR = 0;
                          BANDAINFERIOR = 0;
                          SUBBANDASUPERIOR = 0;
                          SUBBANDAINFERIOR = 0;
                          }
                          else if (State == State.Configure)
                          {
                          }
                          }
                          
                          protected override void OnBarUpdate()
                          {
                          if (BarsInProgress != 0)
                          return;
                          
                          if (CurrentBars[0] < 1)
                          return;
                          
                          // Set 1
                          if ((BANDASUPERIOR != 0)
                          && (BANDAINFERIOR != 0)
                          && (FIRELINE != 0))
                          
                          {
                          Draw.HorizontalLine(this, @"BANDASYFL Horizontal Line_1", false, FIRELINE, Brushes.Fuchsia, DashStyleHelper.Solid, 5);
                          Draw.RegionHighlightY(this, @"BANDASYFL Region highlight y_1", false, BANDASUPERIOR, BANDAINFERIOR, Brushes.Gold, Brushes.Gold, 10);
                          }
                          
                          // Set 2
                          if ((SUBBANDASUPERIOR != 0)
                          && (SUBBANDAINFERIOR != 0))
                          {
                          Draw.RegionHighlightY(this, @"BANDASYFL Region highlight y_2", false, SUBBANDASUPERIOR, SUBBANDAINFERIOR, Brushes.Blue, Brushes.Blue, 10);
                          
                          }
                          }


                          CODE STRATEGY


                          Code:
                          namespace NinjaTrader.NinjaScript.Strategies
                          {
                          public class BOTSECTOR2 : Strategy
                          {
                          private SMA SMA1;
                          private EMA EMA1;
                          private EMA EMA2;
                          public FIRELINETR myFL;
                          
                          protected override void OnStateChange()
                          {
                          if (State == State.SetDefaults)
                          {
                          Description = @"Enter the description for your new custom Strategy here.";
                          Name = "BOTSECTOR2";
                          Calculate = Calculate.OnBarClose;
                          EntriesPerDirection = 1;
                          EntryHandling = EntryHandling.AllEntries;
                          IsExitOnSessionCloseStrategy = true;
                          ExitOnSessionCloseSeconds = 30;
                          IsFillLimitOnTouch = false;
                          MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
                          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;
                          }
                          else if (State == State.Configure)
                          {
                          }
                          else if (State == State.DataLoaded)
                          {
                          SMA1 = SMA(Close, 50);
                          EMA1 = EMA(Close, 20);
                          EMA2 = EMA(Close, 10);
                          myFL = FIRELINETR();
                          }
                          }
                          
                          protected override void OnBarUpdate()
                          {
                          if (BarsInProgress != 0)
                          return;
                          
                          if (CurrentBars[0] < 2)
                          return;
                          
                          // Set 1
                          if ((Close[0] > SMA1[0])
                          && (EMA1[0] < SMA1[0])
                          && (Open[0] < Close[0])
                          && (CrossAbove(EMA2, EMA1, 2)))
                          {
                          BarBrush = Brushes.Yellow;
                          }
                          
                          // Set 2
                          if ((Close[0] < SMA1[0])
                          && (EMA1[0] > SMA1[0])
                          && (Open[0] > Close[0])
                          && (CrossBelow(EMA2, EMA1, 2)))
                          {
                          BarBrush = Brushes.Yellow;
                          }
                          
                          }
                          }
                          }


                          Click image for larger version

Name:	dataurl327983.png
Views:	462
Size:	22.2 KB
ID:	1276335

                          Thanks for your help!!!

                          Comment


                            #14
                            Hello,

                            It looks like you aren't passing in any arguments to the FIRELINETR indicator. Looking at the code for the indicator, it takes at least 5 arguments (FIRELINE, BANDASUPERIOR, BANDAINFERIOR, SUBBANDASUPERIOR, SUBBANDAINFERIOR).

                            Pass in the arguments for the indicator in order for it to be able to calculate.

                            Comment


                              #15
                              Hello Gaby,

                              Could you please make an example of this please? That would be very helpfull.

                              Thanks for your help!!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              62 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              134 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              75 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              50 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X