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

The Strat candle bars port

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

    The Strat candle bars port

    HI,
    I'm trying to port this code from TOS.
    Its just to show if there are inside or outside candle bars.
    Maybe I should be using Draw.Text() instead of PLOT.
    I'm new to C# NT so can you help me?
    Thanks


    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class MyCustomIndicator : Indicator
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "MyCustomIndicator";
    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;
    }
    else if (State == State.Configure)
    {
    }
    }
    
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    
    
    
    
    [B]int H = high;
    int L = low;
    int C = close;
    int O = open;
    
    var insidebar = (H < H[1] && L > L[1]) || (H == H[1] && L > L[1]) || (H < H[1] && L == L[1]) || (H == H[1] && L == L[1]);
    var outsidebar = H > H[1] && L < L[1];
    var twoup = H > H[1] && L >= L[1];
    var twodown = H <= H[1] && L < L[1];
    input Show_Strat_Numbers = yes;
    input Show_Twos = no;
    
    plot barType = if Show_Strat_Numbers = true && insideBar then 1 else if Show_Strat_Numbers && outsidebar then 3 else if !insidebar && !outsidebar && Show_Twos then 2 else double.nan;
    barType.SetPaintingStrategy(PaintingStrategy.VALUE S_BELOW);[/B]
    
    }
    }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
    {
    private MyCustomIndicator[] cacheMyCustomIndicator;
    public MyCustomIndicator MyCustomIndicator()
    {
    return MyCustomIndicator(Input);
    }
    
    public MyCustomIndicator MyCustomIndicator(ISeries<double> input)
    {
    if (cacheMyCustomIndicator != null)
    for (int idx = 0; idx < cacheMyCustomIndicator.Length; idx++)
    if (cacheMyCustomIndicator[idx] != null && cacheMyCustomIndicator[idx].EqualsInput(input))
    return cacheMyCustomIndicator[idx];
    return CacheIndicator<MyCustomIndicator>(new MyCustomIndicator(), input, ref cacheMyCustomIndicator);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
    public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
    {
    public Indicators.MyCustomIndicator MyCustomIndicator()
    {
    return indicator.MyCustomIndicator(Input);
    }
    
    public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input )
    {
    return indicator.MyCustomIndicator(input);
    }
    }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
    {
    public Indicators.MyCustomIndicator MyCustomIndicator()
    {
    return indicator.MyCustomIndicator(Input);
    }
    
    public Indicators.MyCustomIndicator MyCustomIndicator(ISeries<double> input )
    {
    return indicator.MyCustomIndicator(input);
    }
    }
    }
    
    #endregion

    #3
    Click image for larger version

Name:	2021-09-26_19-55-42.png
Views:	238
Size:	71.1 KB
ID:	1172558

    Sorry, I should've said this:
    The Strat just shows you inside bars and outside bars.
    1 == Inside bar
    2 == Outside bar
    3 == dont worry about it
    Thats all I'm trying to do is show what kind of current bar it is in relation to the previous bar
    Pretty easy

    Comment


      #4
      Hello ezrollin,

      It appears you want to draw text below the low of the bar.

      Use Draw.Text() to draw text below the bar. For the price choose Low[0] - 1 * TickSize.

      If you are looking for how to get the Open, High, Low, and Close series, below are links to the help guide.



      Chelsea B.NinjaTrader Customer Service

      Comment


        #5
        I put
        Draw.Text(this, "tag1", "Hedfafadfasdfasdfasdfads", 10, 1000, Brushes.Green);
        under my OnBarUpdate and I dont see anything.
        I'm on the 1 second chart, I have visible checked, etc.
        I dont have live data, I have to keep clicking on "update historical data" to see the futures change. I compile and reload ninjascript every time.
        Theres a million steps to go through
        What am I doing wrong? thanks

        Comment


          #6
          Also, does NT have a scanner?

          Comment


            #7
            How do I change to a Renko chart? I dont see it on the options where you choose the candles types?

            Comment


              #8
              Hello ezrollin,

              It looks like this would appear 10 bars ago, at a price of 1000. (Without autoscaling enabled, this could be out of the viewable range of the chart)

              Have you opened the Drawing Objects window and confirmed the drawing object is not there? (right-click the chart -> Drawing Tools -> Drawing Objects)

              NinjaTrader has a Market Analyzer which can be used to scan stocks.


              To change the bar type right-click the chart -> select Data Series -> Set the Type drop-down to Renko -> click OK.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #9
                Click image for larger version

Name:	renko.png
Views:	360
Size:	45.9 KB
ID:	1174137
                I changed from candlesticks to renko via the data series. Now all my data is gone. I'm connected to TD. I cant reload. Whats wrong?

                Also... Is there a way to pre-define a candlestick. Like if the current stick is higher than the previous... then its a breakout and I can save it as such? Then reference that "breakout" candlestick elsewhere? thanks

                Comment


                  #10
                  Hello ezrollin,

                  This is Jim responding on behalf of Chelsea who is out of the office at this time.

                  TD Ameritrade does not provide single tick historical data to NinjaTrader, which is used to create Renko bars.

                  How Bars are built - https://ninjatrader.com/support/help...riousChartBars

                  Data By Provider - https://ninjatrader.com/support/help...y_provider.htm

                  As for "saving a candle," you can create private variables or a private List of variables, and then you can store certain information to those variables when those conditions become true. Then you could reference your variables to get the information you stored.

                  Publicly available C# information on Lists can be found here - https://docs.microsoft.com/en-us/dot...tframework-4.8
                  JimNinjaTrader Customer Service

                  Comment


                    #11
                    Click image for larger version

Name:	aaaa.png
Views:	332
Size:	530.9 KB
ID:	1175729

                    There are these predefined candlestick patterns. But we cant use them in our indicators or strategies?
                    Or most importantly, to add to them.
                    Can this be added in the future? thanks

                    Comment


                      #12
                      Hello ezrollin,

                      Yes, the CandleStickPattern indicator can be called from an indicator and from a strategy.

                      Below is a link to the help guide with sample code.
                      https://ninjatrader.com/support/help...ickpattern.htm

                      When the return value is 1, the pattern is found. When the return value is 0, no pattern is found.

                      The CandleStickPattern indicator is open source. Feel free to make a copy and modify the copy script how you wish.

                      Be sure to watch the 'Automate Your Trading with NinjaTrader's Strategy Builder' training video from the forum post with information about getting started with NinjaScript linked in post #2. This demonstrates how to select indicators in the Strategy Builder.
                      Last edited by NinjaTrader_ChelseaB; 10-21-2021, 07:49 AM.
                      Chelsea B.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bill2023, Yesterday, 08:51 AM
                      8 responses
                      43 views
                      0 likes
                      Last Post bill2023  
                      Started by yertle, Today, 08:38 AM
                      6 responses
                      25 views
                      0 likes
                      Last Post ryjoga
                      by ryjoga
                       
                      Started by algospoke, Yesterday, 06:40 PM
                      2 responses
                      24 views
                      0 likes
                      Last Post algospoke  
                      Started by ghoul, Today, 06:02 PM
                      3 responses
                      16 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      46 views
                      0 likes
                      Last Post jeronymite  
                      Working...
                      X