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

How to Print to Log

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

    How to Print to Log

    I need help printing to log for 3 items in this Indicator. Need the hoSeries, hcSeries, and the olSeries. Attached is the section of the code.

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;
    using System.Collections.Generic;
    using System.Collections;
    using System.Windows.Forms;
    using System.IO;
    using System.Linq;
    #endregion

    namespace NinjaTrader.Indicator
    {
    [Description("David Cline : 'Candlesticks, Condensed' - TASC February 2015")]
    public class CondensedCandlesticks : Indicator
    {
    #region Variables
    private int segmentCount = 6;
    private int period = 10;
    private int rankLevels = 10;
    private float textSize = 8;

    private double segmentDivisor = 0;
    private int rightSideMarginPrevious = 0;
    private bool buttonsloaded = false;

    private CondensedCandlesticksSortOrder sortOrder = CondensedCandlesticksSortOrder.Descending;

    private Dictionary<string, Dictionary<string, double>> candlePatterns = new Dictionary<string, Dictionary<string, double>>();
    private Dictionary<string, Dictionary<string, float>> candleMetrics = new Dictionary<string, Dictionary<string, float>>();
    private Dictionary<string, float> topRankSort = new Dictionary<string, float>();

    private DataSeries rangeSeries;
    private DataSeries hoSeries;
    private DataSeries hcSeries;
    private DataSeries olSeries;
    private StringSeries patternSeries;

    private string[] rankedPatternList = null;
    private string topRankedPattern = "";

    private System.Windows.Forms.Control[] controls = null;
    private System.Windows.Forms.ToolStrip strip = null;
    private System.Windows.Forms.ToolStripButton showHideRank = null;
    private System.Windows.Forms.ToolStripButton updateRank = null;
    private System.Windows.Forms.ToolStripSeparator space1 = null;
    private System.Windows.Forms.ToolStripSeparator space2 = null;

    private Font boldFont = new Font("Arial", 8, FontStyle.Bold);
    private Font regularFont = new Font("Arial", 8);
    #endregion

    protected override void Initialize()
    {
    Overlay = true;

    rangeSeries = new DataSeries(this);
    hoSeries = new DataSeries(this);
    hcSeries = new DataSeries(this);
    olSeries = new DataSeries(this);
    patternSeries = new StringSeries(this);

    segmentDivisor = 100.0 / SegmentCount;
    }

    protected override void OnStartUp()
    {
    if (ChartControl != null)
    {
    controls = ChartControl.Controls.Find("tsrTool", false);
    rightSideMarginPrevious = ChartControl.BarMarginRight;
    }

    if (controls != null && controls.Length > 0)
    {
    strip = (System.Windows.Forms.ToolStrip)controls[0];

    showHideRank = new System.Windows.Forms.ToolStripButton("showHide");
    showHideRank.Font = regularFont;
    showHideRank.ForeColor = Color.White;
    showHideRank.BackColor = Color.Green;
    showHideRank.Text = "Show Rank";

    updateRank = new System.Windows.Forms.ToolStripButton("update");
    updateRank.Font = regularFont;
    updateRank.ForeColor = Color.White;
    updateRank.BackColor = Color.Green;
    updateRank.Text = "Update Rank";

    showHideRank.Click += showHideRank_Click;
    updateRank.Click += updateRank_Click;

    space1 = new System.Windows.Forms.ToolStripSeparator();
    space2 = new System.Windows.Forms.ToolStripSeparator();
    strip.Items.Add(space1);
    strip.Items.Add(showHideRank);

    buttonsloaded = true;
    }
    }

    protected override void OnBarUpdate()
    {
    int span = Math.Min(CurrentBar, period);

    rangeSeries.Set(High[0] - Low[0]);

    double averageRange = SMA(rangeSeries, span)[0];
    double rangePercent = (rangeSeries[0] / 100);
    double rangeMultiplier = (rangeSeries[0] / averageRange);
    if (rangeMultiplier > 1)
    rangeMultiplier = 1;

    hoSeries.Set(Math.Round(((((High[0] - Open[0]) / rangePercent) * rangeMultiplier) / segmentDivisor), 0));
    hcSeries.Set(Math.Round(((((High[0] - Close[0]) / rangePercent) * rangeMultiplier) / segmentDivisor), 0));
    olSeries.Set(Math.Round(((((High[0] - Low[0]) / rangePercent) * rangeMultiplier) / segmentDivisor), 0));

    string candleSignature = hoSeries[0].ToString() + "-" + hcSeries[0].ToString() + "-" + olSeries[0].ToString();
    PatternSeries[0] = candleSignature;

    DrawText("calc" + CurrentBar, true, candleSignature, 0, Low[0] - 6 * TickSize, 0, Color.Blue, new Font("Arial", TextSize), StringAlignment.Center, Color.Empty, Color.White, 9);

    double candleReturn = Close[0]-Close[span];

    if (!candlePatterns.ContainsKey(candleSignature))
    candlePatterns.Add(candleSignature, new Dictionary<string, double> () { {"Ups", 0}, {"Downs", 0}, {"Totals", 0}, {"Count", 0} });

    candlePatterns[candleSignature]["Count"]++;
    candlePatterns[candleSignature]["Totals"] += candleReturn;

    #2
    Hello jsatt11,

    Printing to the log can be done by using the Log() method with NinjaTrader -
    http://www.ninjatrader.com/support/h...x.html?log.htm

    Let me know if I can be of further assistance.
    Last edited by NinjaTrader_CalH; 02-10-2015, 10:51 AM.
    Cal H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by bortz, 11-06-2023, 08:04 AM
    47 responses
    1,603 views
    0 likes
    Last Post aligator  
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    8 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    4 views
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    12 views
    0 likes
    Last Post Javierw.ok  
    Working...
    X