Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Conditions for an Entry Strategy Builder

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

    #16
    Hello,

    Your line 'myFL = FIRELINETR();' is supplying no arguments to the indicator.

    You need to supply FIRELINE, BANDASUPERIOR, BANDAINFERIOR, SUBBANDASUPERIOR, SUBBANDAINFERIOR arguments to the indicator.

    myFL = FIRELINETR(FIRELINE, BANDASUPERIOR, BANDAINFERIOR, SUBBANDASUPERIOR, SUBBANDAINFERIOR)

    Please note that these are supposed to be substituted by actual numbers (these may be ints or doubles). If you look at your screenshot of the Properties page for the indicator, you can see the arguments there and inputs you have assigned to them. This is what is being passed to the indicator.

    myFL = FIRELINETR(14968, 14924, 14903, 0, 0);


    You need to contact the vendor or author that creates the script for any information about how to use the script.

    Comment


      #17
      Hello Gaby,

      Thanks a lot!

      I tried to compile what you told me but I get a CS0103 ERROR:

      How can I fix this error? see the code

      Click image for larger version

Name:	image.png
Views:	172
Size:	61.7 KB
ID:	1276880

      Code:
      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(FIRELINE, BANDASUPERIOR, BANDAINFERIOR, SUBBANDASUPERIOR, SUBBANDAINFERIOR);
      }
      }
      
      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;
      
      if (CurrentBars[0] < 2)
      return;
      
      if (Close[0] < myFL(BANDASUPERIOR) && Close[0] > myFL(BANDAINFERIOR))
      return;
      
      if (Close[0] < myFL(SUBBANDASUPERIOR) && Close[0] > myFL(SUBBANDAINFERIOR))
      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;
      }
      }
      
      [HASHTAG="t3322"]region[/HASHTAG] Properties
      [NinjaScriptProperty]
      [Range(0, int.MaxValue)]
      [Display(Name="FIRELINE", Description="Valor Fireline", Order=1, GroupName="Parameters")]
      public int FIRELINE
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(0, int.MaxValue)]
      [Display(Name="BANDASUPERIOR", Description="Valor superior de la banda", Order=2, GroupName="Parameters")]
      public int BANDASUPERIOR
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(0, int.MaxValue)]
      [Display(Name="BANDAINFERIOR", Description="Valor Inferior de la banda", Order=3, GroupName="Parameters")]
      public int BANDAINFERIOR
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(0, int.MaxValue)]
      [Display(Name="SUBBANDASUPERIOR", Description="Valor superior de la Subbanda", Order=4, GroupName="Parameters")]
      public int SUBBANDASUPERIOR
      { get; set; }
      
      [NinjaScriptProperty]
      [Range(0, int.MaxValue)]
      [Display(Name="SUBBANDAINFERIOR", Description="Valor inferior de la Subbanda", Order=5, GroupName="Parameters")]
      public int SUBBANDAINFERIOR
      { get; set; }
      
      #endregion
      
      }
      }
      ​

      Comment


        #18
        Hello,

        You are passing in the input variables for myFL, and you have the code for the inputs in the Properties section of your script, but they haven't been set in State.SetDefaults so they have no value.

        You need to give FIRELINE, BANDASUPERIOR, BANDAINFERIOR, SUBBANDASUPERIOR, SUBBANDAINFERIOR default values in State.SetDefaults.

        In addition, the code 'myFL(BANDASUPERIOR)' is not correct since myFL has already been assigned the indicator. You can just use the plot values from it. For example, myFL[0] or myFL.SomePlotName[0]

        So instead of if (Close[0] < myFL(BANDASUPERIOR)) you would use if (Close[0] < myFL[0]).

        After compiling, to test the strategy out again please remove the strategy instance from the chart and re-add to make sure the new defaults are loaded.

        Comment


          #19
          Hello Gaby,

          Thank you so much for the help!

          Could you please make an example of that or help me with the code a bit? I am just starting with coding and I do not understand everything....

          Thanks again!!!

          Comment


            #20
            Hello,


            You can see an example of how to assign the inputs a default value in State.SetDefaults by looking at the code for the FIRELINETR indicator, it is doing the same thing.


            Please let me know if you have any other questions.

            Comment


              #21
              Hello Gaby,

              the thing is I want that my strategy automatically sets the values that I previously put in my FIRELINETR indicator…

              the question here is, how can I do that? That the strategy automatically becomes the values from the indicator, so that everytime I change the values, the strategy works with this values?



              thanks a lot!!

              Comment


                #22
                Hello,

                A strategy cannot pull values from an indicator, the values will have to be supplied from the strategy as parameters to the indicator call.

                However, you can default the values to the same default values as the indicator.

                Please let me know if you have any other questions.​

                Comment


                  #23
                  Hello Gaby,

                  Okey thanks!!!

                  Now I would like to make the same thing with the 15 minutes EMA indicator (this is a programmed indicator by myself), that turns GREEN or RED depending on the EMA crossover.

                  what conditions should I make so that the strategy only takes the BUY ENTRIES when the EMA20 in 15mins is GREEN and takes the SELL ENTRIES when is RED?


                  Here what I have:

                  Click image for larger version

Name:	image.png
Views:	180
Size:	80.5 KB
ID:	1277065Click image for larger version

Name:	image.png
Views:	129
Size:	30.4 KB
ID:	1277066



                  And the code of the indicator:

                  Code:
                  public class EMA20DIRECCION : Indicator
                  {
                  
                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"Enter the description for your new custom Indicator here.";
                  Name = "EMA20DIRECCION";
                  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;
                  AddPlot(Brushes.Green, "MyEMAGreen");
                  AddPlot(Brushes.Red, "MyEMARed");
                  slowPeriod = 10;
                  fastPeriod = 20;
                  
                  }
                  else if (State == State.Configure)
                  {
                  }
                  }
                  
                  
                  
                  protected override void OnBarUpdate()
                  {
                  //Add your custom indicator logic here.
                  if (CurrentBar == 0) return;
                  
                  if (EMA(Input, fastPeriod)[0] < EMA(Input,slowPeriod)[0])
                  {
                  Values[0][0] = EMA(Input, fastPeriod)[0];
                  Values[0][1] = EMA(Input, fastPeriod)[1];
                  }
                  if (EMA(Input, fastPeriod)[0] > EMA(Input,slowPeriod)[0])
                  {
                  Values[1][0] = EMA(Input, fastPeriod)[0];
                  Values[1][1] = EMA(Input, fastPeriod)[1];
                  }
                  }
                  
                  [HASHTAG="t3322"]region[/HASHTAG] Properties
                  [Browsable(false)]
                  [XmlIgnore()]
                  public Series<double> MyEMAGreen
                  {
                  get { return Values[0]; }
                  }
                  
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="slowPeriod", Order=1, GroupName="Parameters")]
                  public int slowPeriod
                  { get; set; }
                  
                  [NinjaScriptProperty]
                  [Range(1, int.MaxValue)]
                  [Display(Name="fastPeriod", Order=2, GroupName="Parameters")]
                  public int fastPeriod
                  { get; set; }
                  
                  [Browsable(false)]
                  [XmlIgnore()]
                  public Series<double> MyEMARed
                  {
                  get { return Values[1]; }
                  }
                  #endregion
                  }
                  }​
                  ​
                  Thanks!!!!
                  Last edited by tradingnasdaqprueba; 11-08-2023, 02:54 PM.

                  Comment


                    #24
                    Hello,

                    Thank you for your response.

                    I suggest using one plot for your indicator, setting the bar color with BarBrush with the condition, and setting a second (transparent) plot to -1 for red and 1 for green to use as a signal for a host (your strategy).

                    Please see this forum post that has an example script demonstrating using a plot as a signal:

                    https://forum.ninjatrader.com/forum/...der#post812238

                    If you have any questions, please let me know.

                    Comment


                      #25
                      Hello Gaby,

                      I did it as you said but the strategy does not work... also I get some visual errors in my indicator... please see:

                      CODE:

                      Code:
                      //This namespace holds Indicators in this folder and is required. Do not change it.
                      namespace NinjaTrader.NinjaScript.Indicators
                      {
                      public class EMA20DIRECCION : Indicator
                      {
                      private int last;
                      private bool triggered;
                      
                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = @"Enter the description for your new custom Indicator here.";
                      Name = "EMA20DIRECCION";
                      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;
                      AddPlot(Brushes.Green, "MyEMAGreen");
                      AddPlot(Brushes.Red, "MyEMARed");
                      AddPlot(Brushes.Transparent, "SignalPlot");
                      slowPeriod = 10;
                      fastPeriod = 20;
                      
                      }
                      else if (State == State.DataLoaded)
                      {
                      last = 0;
                      triggered = false;
                      }
                      }
                      
                      
                      
                      protected override void OnBarUpdate()
                      {
                      if (IsFirstTickOfBar || Calculate == Calculate.OnBarClose)
                      {
                      Value[0] = 0;
                      triggered = false;
                      last = 0;
                      }
                      
                      if (CurrentBar == 0) return;
                      
                      if (EMA(Input, fastPeriod)[0] < EMA(Input,slowPeriod)[0])
                      {
                      Values[0][0] = EMA(Input, fastPeriod)[0];
                      Values[0][1] = EMA(Input, fastPeriod)[1];
                      Value[0] = -1;
                      last = -1;
                      triggered = true;
                      }
                      if (EMA(Input, fastPeriod)[0] > EMA(Input,slowPeriod)[0])
                      {
                      Values[1][0] = EMA(Input, fastPeriod)[0];
                      Values[1][1] = EMA(Input, fastPeriod)[1];
                      Value[0] = 1;
                      last = 1;
                      triggered = true;
                      }
                      
                      else if (ResetAfterTrigger == true && triggered == true)
                      {
                      Value[0] = 0;
                      triggered = false;
                      }
                      }
                      
                      [HASHTAG="t3322"]region[/HASHTAG] Properties
                      
                      [Browsable(false)]
                      [XmlIgnore]
                      public Series<double> SignalPlot
                      {
                      get { return Values[0]; }
                      }
                      
                      [NinjaScriptProperty]
                      [Display(Name = "Reset after trigger", Order = 0, GroupName = "Parameters")]
                      public bool ResetAfterTrigger
                      { get; set; }
                      
                      [Browsable(false)]
                      [XmlIgnore()]
                      public Series<double> MyEMAGreen
                      {
                      get { return Values[0]; }
                      }
                      
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="slowPeriod", Order=1, GroupName="Parameters")]
                      public int slowPeriod
                      { get; set; }
                      
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="fastPeriod", Order=2, GroupName="Parameters")]
                      public int fastPeriod
                      { get; set; }
                      
                      [Browsable(false)]
                      [XmlIgnore()]
                      public Series<double> MyEMARed
                      {
                      get { return Values[1]; }
                      }
                      #endregion
                      }
                      }

                      Click image for larger version

Name:	image.png
Views:	171
Size:	20.2 KB
ID:	1277498


                      STRATEGY

                      Click image for larger version

Name:	image.png
Views:	120
Size:	47.1 KB
ID:	1277499
                      Click image for larger version

Name:	image.png
Views:	120
Size:	46.7 KB
ID:	1277500​​

                      Comment


                        #26
                        Hello,

                        In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.

                        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

                        Enable TraceOrders, 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 or enabling TraceOrders.

                        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

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Today, 05:17 AM
                        0 responses
                        50 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        126 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        69 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        42 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        46 views
                        0 likes
                        Last Post TheRealMorford  
                        Working...
                        X