Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Using the ArrowUp/Down for a strategy parameter

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

    Using the ArrowUp/Down for a strategy parameter

    Hello, I'm new to Ninjatrader, I really like the script and have spent already hours of learning the program. But at this moment I have some issues.

    I have an indicator and this indicator gives me an arrow up and an arrow down as an indication. I have already tried to give these indications a value (Arrow up is 1, Arrow down is -1, else is 0), but this is still not working.

    This is the part of the script where I use the ArrowDown and ArrowUp part:
    else if (Close[0] > Value[1])
    {
    trail = Close[0] - loss;
    SignalValue = 1;
    Draw.ArrowDown(this, CurrentBar.ToString(), false, 1, Value[1], Brushes.Orange);
    }

    else
    {
    trail = Close[0] + loss;
    Draw.ArrowUp(this, CurrentBar.ToString(), false, 1, Value[1], Brushes.Orange);


    I have tried to set a value together with the "Draw" commant, but this is also not working.
    Hopefully anybody knows how to deal with this.

    #2
    Hello HPBTholen,

    Thanks for your post and welcome to the NinjaTrader forums!

    The easiest way to accomplish your goal would be to add a plot to your indicator and set its brush to Transparent. For example, in State.Configure: AddPlot(Brushes.Transparent, "MySignal");

    In OnBarUpdate():

    // at the top:
    MySignal[0] = 0; // always set the signal to 0 on every new bar

    //then in your code
    // for a down arrow use:
    MySignal[0] = -1; // rewrite the v alue for a negative signal

    //for an up arrow use:
    MySignal[0] = 1; // rewrite they value for a positive signal.

    In the #region Properties you would need to provide an output like:
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> MySignal
    // plots have to use double data type
    {
    get { return Values[0]; } // Note that Values[0] is assigned to the first plot so if you have other plots this may need to be a different number.
    }


    Using a transparent brush means the plot will not disturb the display which is important as the signal is only +/- a value of 1.

    Note: you can also read the same signal in the Market analyzer by using the Indicator column and selecting the indicator and selecting MySignal plot.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      Thank you for your help! It helped me already a lot.


      I put it in the indicator and are getting the 'MySignal values". I checked this via de print the MyValues on every bar close and then I get the values '-1', '0' and '1' in my output. However, if I use MySignal as a condition, my strategy is doing nothing. Even with the most simple;

      if (MySignal[0] == -1 )
      {
      EnterShort(Convert.ToInt32(DefaultQuantity), @"Enter Short");
      }


      By this, I do not understand why MySignal is not giving a condition signal, which I can use for my strategy.

      Do you know what this problem might be?
      String, double or bool the MySignal?

      Comment


        #4
        Hello HPBTholen,

        Thanks for your reply.

        In the strategy builder, you would need to select the indicator that contains the signal plot and you would have to select the "Value Plot" of MySignal to then compare to the values of +1 or -1.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          Thank you for your reply! I'm sorry, because I have it in my script like this: (ATRTrailingStop1.MySignal[0] == -1), and in the beginning I have private ATRTrailingStop ATRTrailingStop1;
          So, this would not be the problem, in my opinion. Do you have any other possibilities?

          Comment


            #6
            Hello HPBTholen,

            Thanks for your reply.

            Do you also have the initializing part for that in State.DataLoaded?

            If you are unsure I suggest creating the condition in the Strategy builder, then click "view code" and you would see a statement in State.Dataloaded that you can copy (assuming the parameters are the same).

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi Paul,

              Thank you for replying and helping me again. I already have that too in State.DataLoaded. I tried some of the ways to implement the script, but none of these ways gave me an output. I will uload the script in another post. Maybe you can see what condition is missing or what I'm doing wrong...

              Comment


                #8
                Here are the scripts, both in one file

                Comment


                  #9
                  Hello HPBTholen,

                  Thanks for your reply.

                  In the indicator section you have an issue:

                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> MySignal
                  {
                  get { return Values[0]; }
                  }

                  [Browsable(false)]
                  [XmlIgnore]
                  public Series<double> TrailingStop
                  {
                  get { return Values[0]; }
                  }


                  Both of these are the plot outputs and they are using the same Values[0]. The first AddPlot listed in your code is tied to Values[0], the second addPlot is tied to Values[1], so change the Value[] in MySignal to Values[1] to align with the plot.

                  In the strategy, remove public Series<double> MySignal; and MySignal = new Series<double>(this, MaximumBarsLookBack.TwoHundredFiftySix); as these are not needed.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Paul, thank you for your reply again!!

                    The properties of the indicator are now set like this:

                    [Browsable(false)]
                    [XmlIgnore]
                    public Series<double> MySignal
                    {
                    get { return Values[1]; }
                    }

                    Do I have to put the Value[1] also at OnBarUpdate() for the indicator? Because if I do, it is still not working.
                    And for the strategy, with the condition (ATRTrailingStop1.MySignal[1] == 1) it is also not working yet.

                    I still do not understand why, because what I want seems very easy to me, but is still hard working in a script.

                    Comment


                      #11
                      Hello HPBTholen,

                      Thanks for your reply.

                      Just to make sure we are on the same page, please attach the current source code (cs) file of your indicator.

                      You can find it at Documents>NinjaTrader8>bin>Custom>Indicator>
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi Paul,

                        Thanks for replying. Here I attached the current source code of my indicator. Thanks for asking

                        Comment


                          #13
                          Hello HPBTholen,

                          Thanks for your reply.

                          It looks like you change the assignment of the +/-1 value. Currently you are assigning it to the previous bar MySignal[1] = 1; please change it back to MySignal[0] = 1;

                          To explain:

                          The plot mySignal is being associated with Values[1] which is not a bars ago index but an array index and I suspect that is the confusing issue.

                          By using the plot name we eliminate the need to specify the array index, thus you could also do Values[1][0] = 1; but I find it much easier to read mySignal[0] = 1;

                          To clarify: Value[a][b] where [a] is the array index that relates in this case to the plots and b is the current bar index.

                          Please check the example "Indicator which adds three value series" on this page: https://ninjatrader.com/support/help...8/?addplot.htm
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello Paul,

                            Thanks for your reply. I did this before, but it was still not working. When I checked the source code at at Documents>NinjaTrader8>bin>Custom>Indicator>, I saw it was not saved in the source code. Now I get the signals and trades. So, it seems that it is doing what it has to do.

                            Thank you very much for your help!
                            Last edited by HPBTholen; 08-19-2020, 06:46 AM.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by slightly, Today, 12:49 AM
                            0 responses
                            2 views
                            0 likes
                            Last Post slightly  
                            Started by sdauteuil, 09-23-2021, 10:16 AM
                            4 responses
                            1,208 views
                            0 likes
                            Last Post jacobpescaia44  
                            Started by agclub, 04-21-2024, 08:57 PM
                            5 responses
                            34 views
                            0 likes
                            Last Post agclub
                            by agclub
                             
                            Started by ESHunter, Yesterday, 08:06 PM
                            2 responses
                            18 views
                            0 likes
                            Last Post ESHunter  
                            Started by ETFVoyageur, 05-07-2024, 07:05 PM
                            19 responses
                            150 views
                            0 likes
                            Last Post ETFVoyageur  
                            Working...
                            X