Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X