Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Losing my mind: Can't bring an indicator into my strategy

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

    Losing my mind: Can't bring an indicator into my strategy

    I can bring in all kind of indicators but somehow this one I cannot, I get the error message below. I cannot for the life of me figured out what the issue is, it's an indicator just like everything else.

    'NinjaTrader.NinjaScript.Strategies.Strategy.Secon dEntry(int, int, int, int, int, bool, bool, bool, bool, string, System.Windows.Media.Brush, System.Windows.Media.Brush, System.Windows.Media.Brush, System.Windows.Media.Brush, System.Windows.Media.Brush, System.Windows.Media.Brush, System.Windows.Media.Brush)' is a 'method' but is used like a 'type'


    my strategy snippet: and you can clearly see i can bring in my legCountRev 2 and EMA, but I cannot bring in the "SecondEntry".
    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
    
    
    Code:
    public class ScenarioPlay : Strategy
    {
    private LegCountRev2 legCount;
    private SecondEntry s2;  //error with that
    private EMA ema21;
    private double signBarStrength = .65;
    private Order currentOrder;
    private Boolean inTrade = false;
    public int scalpTick = 8;
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "ScenarioPlay";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    SecondEntry Snippet: //This namespace holds Indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators.PAT { public class SecondEntry : Indicator { #region variables private double pivotHigh = 0; private double pivotLow = 9999999; private double lastHigh = 0; private double lastLow = 9999999; private double longRisk = 0; private double shortRisk = 0; private double longPos = 0; private double shortPos = 0; private double longTarget = 0; private double longStop = 0; private double shortTarget = 0; private double shortStop = 0; private double longPrice = 0; private double shortPrice = 0; private int legDown = 1; private int legUp = 1; private int lastBarS = 0; private int lastBarL = 0; private int upLabel = 0; private int downLabel = 0; private bool isUpLeg = true; private bool isDownLeg = true; private bool isLongEntry = true; private bool isShortEntry = true; private Brush riskL; private Brush riskS; private Brush empty = Brushes.Transparent; #endregion protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Second Entry indicator"; Name = "Second Entry"; Calculate = Calculate.OnPriceChange; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true;

    #2
    Hello thaison316,

    Thank you for the post.

    From the given error it seems you may be calling it incorrectly or have placed the indicator in an invalid location/namespace.

    The following from the error is unexpected:
    Code:
    NinjaTrader.NinjaScript.Strategies.Strategy.SecondEntry
    this would not be an expected namespace for an indicator. You would likely need:


    Code:
    NinjaTrader.NinjaScript.Indicators.PAT.SecondEntry
    The given snippet seems to be a combination of scripts so its hard to tell what specifically is happening. I would suggest to attach the .cs file for the indicator and strategy so we can more easily see the code you had used and what is not correct. You can just leave it as is with the error, that would help to highlight the problem.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      the scenairoplay.cs si the strategy and the secondentry.cs is the indicator. The indicator is in the correct name space.
      Attached Files

      Comment


        #4
        Hello thaison316,

        Thank you for the post.

        You used a custom namespace/folder for your indicator. Because of that it does not exist in the Indicators namespace which the strategy is expecting, you would need to use the fully qualified name like below:

        Code:
        private NinjaTrader.NinjaScript.Indicators.PAT.SecondEntry s2;

        Please let me know if I may be of additional assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          thank you that works, is it recommended to use default namespace?

          Comment


            #6
            Hello thaison316,

            It does not really matter if you use the default namespace, its just that when you coded it so you just missed adding the full namespace. If you make folders and place indicators inside folders and then use the Strategy Builder it would have generated the full namespace code like that. Once you are aware you need to specify where the indicator is located then this error is unlikely to happen again as you just adjust your coding style to include the full namespace.


            Please let me know if I may be of additional assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Is there a way to have a default constructor? My indicator has a bunch of input values with default sets but when I want to use it inside a strategy, it is making my input all of those parameters in.
              I want to be able to use it with all the defaults.


              private NinjaTrader.NinjaScript.Indicators.PAT.SecondEntry s2;

              s2 = NinjaTrader.NinjaScript.Indicators.PAT.SecondEntry () // giving me an error here because it has no constructor that takes in 0 argument.

              Comment


                #8
                Hello thaison316,

                Any defaults you need set should be set from OnStateChange and SetDefaults:

                https://ninjatrader.com/support/help...=OnStateChange

                You can consider that as the indciators default constructor in this situation, that will be called at the correct times when the defaults for the indicators need to be set.

                The error you are getting is because you have public user inputs and your indicator requires that you pass a value. For example if you look at the SMA indicator it has a public property named Period, because of that you would need to pass a value when calling the SMA(12).

                If you type the name of your indicator with ( at the end it should bring up the intelleprompt and show what it wants as input, for example typing SMA( will show it needs an int as input.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Yes, all the default is set inside on state change. You are right, system generated a public variables. If you look at the code below, I have a lot of default options for inputs, so everytime I do a SecondEntry() I have to pull all those in again. Isn't there a way to do a default constructor that takes in 0 argument and the default will be used?

                  protected override void OnStateChange()
                  {
                  if (State == State.SetDefaults)
                  {
                  Description = @"Second Entry indicator";
                  Name = "Second Entry";
                  Calculate = Calculate.OnPriceChange;
                  IsOverlay = true;
                  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;
                  Target = 4;
                  MaxStop = 8;
                  EntryPlacement = 1;
                  StopPlacement = 1;
                  Margin = 5;
                  IsOnly2ndEntries = true;
                  IsSignalOn = true;
                  AlertSound = "";
                  IsAlertOn = false;
                  IsSwapEntryDrawing = false;
                  isLongEntryBrush = Brushes.Lime;
                  isShortEntryBrush = Brushes.Red;
                  FutureSignalTarget = Brushes.Lime;
                  FutureSignalStop = Brushes.Red;
                  FutureSignalEntry = Brushes.Yellow;
                  FutureSignalRiskOver = Brushes.Magenta;
                  FutureSignalRiskUnder = Brushes.Yellow;
                  TextFont = new NinjaTrader.Gui.Tools.SimpleFont("Arial", 9);
                  }
                  else if (State == State.Configure)
                  {
                  }
                  }

                  Comment


                    #10
                    Hello thaison316,

                    If you want a constructor with 0 parameters you would need to not have public properties. Indicators will generate overloads for any public properties that you add by design, that's really the main reason you would use a public property to begin with. The items you have shown could be made private instead and you would continue setting the defaults like you had shown.

                    You can also comment out the NinjaScriptProperty on the public property. //[NinjaScriptProperty]

                    As a suggestion, you can simplify indicator logic by using the Strategy Builder to generate yourself a simple example. The general way that you would call an indicator can be demonstrated if you create a new empty strategy and then use an indicator in a condition. After clicking View code you can see how the indicator is made into a variable so each time its used you don't need to provide those defaults through the constructor. In OnBarUpdate you just use the indicator variable which is simple like sma1[0] to get the value.

                    Please let me know if I may be of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      thank you so much for the prompt respond

                      Comment


                        #12
                        Ok, back at this. I follow your tip (thank you!), use the strategy generator, and see how they implement the code. I have the code below, everything is fine, I can build and I can enable it, the problem is, the indicator just doesn't come up. I even try to Print("inside indicator") on OnBarUpdate() inside the generator to see if it would trigger, it did not. The indicator works fine because I can add it as an indicator on my chart and it works fine as an indicator. Any thoughts?

                        Code:
                        else if (State == State.DataLoaded)
                        {
                        SecondEntry1 = SecondEntry(Close, 4, 8, 1, 1, 5, true, false, true, false, @"", Brushes.Lime, Brushes.Red, Brushes.Lime, Brushes.Red, Brushes.Yellow, Brushes.Fuchsia, Brushes.Yellow);
                        //SetTrailStop(Convert.ToString((Low[0] + (0.25 * TickSize)) ), CalculationMode.Currency, 0, false);
                        AddChartIndicator(SecondEntry1);
                        }

                        Comment


                          #13
                          Uploading my 2 files. The names are a bit different but it's the same thing. I tried and removed everything and recreate it. Same problem.
                          Attached Files

                          Comment


                            #14
                            Hello thaison316,

                            I tried the strategy however i see the indicator plotted. Did you remove the strategy and re apply it after adding AddChartIndicator?

                            One item that sticks out is the following syntax. You cannot use price data from OnStateChange so the following line would not work. You are also using the price data as a string and not a price, thats being used as a signal name.

                            Code:
                            SetStopLoss(Convert.ToString((High[0] + (1 * TickSize)) ), CalculationMode.Currency, 0, false);
                            You are using the following overload set:
                            SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool isSimulatedStop)

                            The first parameter should be the name of your entry:

                            Code:
                            SetStopLoss("MyEntryName", CalculationMode.Currency, 0, false);
                            a 0 for currency would also be unexpected, you would need to enter an amount where the 0 is.

                            Please let me know if I may be of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Sorry, the stoploss was on there from the generated code, we can remove that. Yes, I did reapply and even removed it completely and readd. If you use the indicator by itself, you will see that it works. That is my problem, the indicator is not plotting on the strategy.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jeronymite, Today, 08:43 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post jeronymite  
                              Started by jeronymite, Today, 07:01 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post jeronymite  
                              Started by LeitoGTR, Today, 06:41 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post LeitoGTR  
                              Started by 2inthebush, Today, 03:29 PM
                              2 responses
                              13 views
                              0 likes
                              Last Post 2inthebush  
                              Started by forrestang, Today, 02:17 PM
                              5 responses
                              25 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Working...
                              X