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

Buy sell on Indicator Arrows

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

    Buy sell on Indicator Arrows

    Hi Support,

    My custom indicator is set up to paint arrows on the chart, how do I set up a strategy to action buy and sell orders based on those arrows?

    #2
    Hello TrendFollowingCapital,

    Is the custom indicator one you are creating?

    The most simple/common way to expose a signal would be to make a specific plot which contains the values for the arrows, such as 1 0 -1 to denote up neutral or down. A strategy can then call your indicator to get this value much easier than trying to locate drawn objects. It is possible to locate objects but this only works in realtime or after the chart has been rendered so it is not a reliable way to find signals.



    When drawing the arrows, you can set the plots value as well. If you don't want to see the plot, you can set it to transparent for its color to hide it. If you also wanted to hide its price marker you can use the following:



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

    Comment


      #3
      Hi Jesse

      Thank you for the response, yes this is a custom indicator for which I have all the code.

      These are the plots in the indicator, please could you advise how to call these up and action signals in Strategy Builder:?

      AddPlot(new Stroke(Brushes.Pink, 5), PlotStyle.Hash, "LastLevel");
      AddPlot(new Stroke(Brushes.Red, 1), PlotStyle.Square, "TradingSignal");

      **********************************
      and more of the code:
      **********************************

      protected override void OnBarUpdate()
      {
      TradingSignal[0]=0;

      //Make sure we have bars
      if (CurrentBar < 2)
      return;

      //Draw.Text(this, "MyText"+CurrentBar, changecounter.ToString(), 0, High[0] + 2 * TickSize, Brushes.Blue);

      PlotBrushes[0][0] = PlotBrushes[0][1];

      // Print (CurrentBar);
      // Print (CurrentBar - lastLineBar2);

      if (ThreeHistoricalLevelsOnly)
      {
      //Only show the last 2 levels
      for (int index = CurrentBar - lastLineBar3; index < CurrentBar; index++)
      {
      PlotBrushes[0][index] = Brushes.Transparent;
      }
      }


      displacement = 0.5 * ArrowsDisplacement * TickSize;

      if (BarsPainting)
      {
      BarBrush = CandleOutlineBrush = candleAndWicksBrush;
      }

      if (!IsFirstTickOfBar)
      {
      return;
      }

      arrowsFont = new SimpleFont("Wingdings", ArrowsSize) { Bold = true };

      //Initialize StartTime
      if (CurrentBar == 2)
      StartTime = Time[0];

      //Add the bars
      numberOfBars++;

      //Check for specified number of bars within specified period
      CheckBars();

      //if we have drawn a line check price and change color based on close
      if (lastLineBar > 0)
      {
      if (lastLineBar!=changecounterbar)
      {
      changecounter=0;
      changecounterbar=lastLineBar;
      }

      //Print (CurrentBar);

      //PlotBrushes[0][lastLineBar-CurrentBar] = Brushes.Transparent;

      LastLevel[0] = lastLineClose;

      if (Close[0] > lastLineClose)
      {

      if (lastBrush != UpLinesColor)
      {
      lastBrush = UpLinesColor;

      changecounter = changecounter + 1;

      //Draw.VerticalLine(this, lastLineBar.ToString(), CurrentBar - lastLineBar, UpLines ? UpLinesColor : Brushes.Transparent, LinesStyle, LinesWidth);
      // vLine = Draw.VerticalLine(this, noOfOccurance.ToString(), CurrentBar - lastLineBar, UpLineColor, LineStyle, LineWidth);

      if (changecounter==1)
      {
      Draw.Text(this, "Arrow " + lastLineBar.ToString() , false, "\xE9", CurrentBar - lastLineBar, Low[CurrentBar - lastLineBar] - displacement, 0, UpArrows ? Uptrend1stRepaintColor : Brushes.Transparent , arrowsFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      PlotBrushes[0][0] = Uptrend1stRepaintColor;
      TradingSignal[0]=1;
      }

      if (changecounter==2)
      {
      Draw.Text(this, "Arrow " + lastLineBar.ToString() , false, "\xE9", CurrentBar - lastLineBar, Low[CurrentBar - lastLineBar] - displacement, 0, UpArrows ? Uptrend2ndRepaintColor : Brushes.Transparent , arrowsFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      PlotBrushes[0][0] = Uptrend2ndRepaintColor;
      TradingSignal[0]=2;
      }

      if (changecounter==3)
      {
      Draw.Text(this, "Arrow " + lastLineBar.ToString() , false, "\xE9", CurrentBar - lastLineBar, Low[CurrentBar - lastLineBar] - displacement, 0, UpArrows ? Uptrend3rdRepaintColor : Brushes.Transparent , arrowsFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      PlotBrushes[0][0] = Uptrend3rdRepaintColor;
      TradingSignal[0]=3;
      }

      if (changecounter<1 || changecounter>3)
      {
      Draw.Text(this, "Arrow " + lastLineBar.ToString() , false, "\xE9", CurrentBar - lastLineBar, Low[CurrentBar - lastLineBar] - displacement, 0, UpArrows ? UpArrowsColor : Brushes.Transparent , arrowsFont, TextAlignment.Center, Brushes.Transparent, Brushes.Transparent, 0);
      PlotBrushes[0][0] = UpArrowsColor;
      }

      candleAndWicksBrush = UpBarsColor;

      Comment


        #4
        Hello TrendFollowingCapital,

        Thank you for the reply.

        It looks like you are already using plots, and based on the syntax you may already have this exposed.

        Do you have a region at the bottom of the file for public properties? And do you have one shown for LastLevel and TradingSignal which would look like:

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


        If so, you should be able to call your indicator like the following:

        Code:
        double signal = MyIndicator(parameters).TradingSignal[0]
        You can also use the strategy builder to select your indicator in a condition. It should have a dropdown for Plots which you can select, and these should be listed if they are exposed in the way mentioned above. If you want you can also use the view code button to view the indicator syntax including plots syntax it generates.


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

        Comment


          #5
          Thanks Jesse, these are the Plots in the Strategy builder, any idea what to do here with them?
          Cross Above, Cross Below, Equals, Greater, Less as an option and then do I select Indicator,Price, Strategy or Misc and what values do i put in there.
          Really hope you can help, I would prefer to do this in the Strategy Builder as I am new to altering open code?

          Comment


            #6
            Also, in the drop down box of the "Value Plot", I have an option of "Trading Signal" - Which do I work with?

            Comment


              #7
              Hello TrendFollowingCapital,

              The image you provided would be how you can configure the visual for the plots in case you are using Misc -> Plot on chart.

              The Value Plot is what you are comparing in the condition, so if TradingSignal is listed there you should be able to use it for the condition.

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

              Comment


                #8
                Dear NT Customer Service,

                I am trying to do the same than TrendFollowingCapital but with a different indicator (see attachment). The indicator is called DivergenceInputSeries. I have tried to localize at the bottom a region for public properties, but it only shows "public partial class". Just to make sure, is it possible to modify this indicator so it buys or sells according to the arrow signals? Thanks in advance.
                I forgot, one last question: would it be possible to add an audio alert to the arrow signals? If yes, could you guide me or give me some information (examples or tutorials) that could help me?
                Download DivergenceInputSeriesNT8.zip for free from Uploadfiles.io instantly, no signup required and no popup ads
                Last edited by aja1946; 03-08-2020, 06:31 PM.

                Comment


                  #9
                  Hello aja1946,

                  The public partial class at the bottom of the file is auto generated code that happens when you compile. This allows strategies and other tools to use the indicator.

                  The partial class at the bottom would not have anything to do with modifying the logic of the script. This script was created to just draw arrows so if you wanted to make it expose a signal you would have to make it use a Plot. https://ninjatrader.com/support/help...ghtsub=addplot
                  In the logic where the arrows are being set you could set the plot to a specific value, other scripts could then read that value as a signal.

                  To play a sound you can use an alert or PlaySound:




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

                  Comment


                    #10
                    Hello Jesse,

                    First of all, thanks for your quick reply. Your response has been very helpful as I have been able to add the sound alert to the indicator. It took me a while to figure out where to index it, but finally it worked out. I have also indexed the Plot feature at the end of the script. I haven´t checked yet if the Plot works, but just for now, it has been a great achievement to make the sound alert work, as I had no idea of programming. Thanks again for your help.

                    Comment


                      #11
                      Hi,

                      I have the same issue, not able to send the BUY and SELL values from my indicator to strategy. I developed custom indicator using ninjatrader 7. I have added the plot, but the output that i'm expecting from the indicator is BUY and SELL price at the barclose as output from indicator or at least Long = 1 and Short -1.

                      PaintPriceMarkers = true; // Indicator plots values display in the y-axis => But , is it possible to get the price from indicator to strategy?

                      Thanks,
                      Murali

                      Comment


                        #12
                        Hello radhmu978,

                        It is possible to pass a price from an indicator to a strategy, you would use a Plot in the indicator for that purpose. You can see the SMA or Bollinger indicators for some very simple examples of passing a price value to a plot. The SampleMACrossOver strategy uses the SMA so those two scripts are good to look at to better understand the relation between indicator and strategy. If you need further assistance please create a new post in the Nt7 sub forums so we can provide more specific assistance.

                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          I have various plot, but my BUY, SELL is not just based on the plot, it is based on the lookback period in addition to crossover. So i have 2 boolean for LONG and SHORT, with Close[0] price as exposedvariable. This is what i get in SIBloodHound, but if i want to do this directly with ninjatrader strategy builder, I'm not able to see anything other than the plot variables in indicator window. These 2 bools are not visible in NT7 indicator window.

                          Click image for larger version

Name:	indicator-output.png
Views:	865
Size:	30.6 KB
ID:	1183182

                          Comment


                            #14
                            Hello radhmu978,

                            For a standard strategy/indicator you can see the SampleMACrossOver to see how to access signals in manual coding. Alternatively you can use the strategy wizard to generate a strategy that uses your indicator. When using the strategy wizard it will only shows Plots that the indicator has, it will not see bools or other properties. To use those you would need to manually code the script.

                            If you need further assistance on this question please create a specific NT7 post about your indicator as this question does not relate to this thread.



                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              ok thank you Jesse, will close this thread here.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Rapine Heihei, Today, 08:19 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Rapine Heihei, Today, 08:25 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Rapine Heihei  
                              Started by f.saeidi, Today, 08:01 PM
                              1 response
                              9 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Rapine Heihei, Today, 07:51 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post Rapine Heihei  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              5 responses
                              98 views
                              1 like
                              Last Post caryc123  
                              Working...
                              X