NexusFi: Find Your Edge


Home Menu

 





help edit the code Ninja Trader


Discussion in NinjaTrader

Updated
    1. trending_up 207 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread

help edit the code Ninja Trader

  #1 (permalink)
kirdov1975
Toulon France
 
Posts: 1 since Aug 2022
Thanks Given: 0
Thanks Received: 0

I want to create an indicator that will draw horizontal lines on top and bottom for a given number of ticks on each new candlestick. The code compiled without errors, but the lines do not have a deviation of approximately 8 ticks and are not redrawn. those. new lines do not appear on the new candle, but the old ones continue to hang
#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

namespace NinjaTrader.NinjaScript.Indicators
{
public class CustomHorizontalLines : Indicator
{
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Ticks Distance", Description="The number of ticks above and below the opening price to plot horizontal lines", Order=1, GroupName="Parameters")]
public int TicksDistance
{ get; set; }

[NinjaScriptProperty]
[XmlIgnore]
[Display(Name="Line Color", Order=2, GroupName="Parameters")]
public Brush LineColor
{ get; set; }

[Browsable(false)]
public string LineColorSerializable
{
get { return Serialize.BrushToString(LineColor); }
set { LineColor = Serialize.StringToBrush(value); }
}

protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Draws horizontal lines above and below the opening price based on the specified number of ticks.";
Name = "CustomHorizontalLines";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
TicksDistance = 49;
LineColor = Brushes.Gray;
}
}

protected override void OnBarUpdate()
{
if (CurrentBar <= 0)
return;

double openingPrice = Open[0];

double priceAbove = openingPrice + (TicksDistance * TickSize);
double priceBelow = openingPrice - (TicksDistance * TickSize);

// Remove previous horizontal lines
RemoveDrawObject("AboveLine");
RemoveDrawObject("BelowLine");

// Draw horizontal lines above and below the opening price
Draw.HorizontalLine(this, "AboveLine", priceAbove, LineColor);
Draw.HorizontalLine(this, "BelowLine", priceBelow, LineColor);
}
}
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private CustomHorizontalLines[] cacheCustomHorizontalLines;
public CustomHorizontalLines CustomHorizontalLines(int ticksDistance, Brush lineColor)
{
return CustomHorizontalLines(Input, ticksDistance, lineColor);
}

public CustomHorizontalLines CustomHorizontalLines(ISeries<double> input, int ticksDistance, Brush lineColor)
{
if (cacheCustomHorizontalLines != null)
for (int idx = 0; idx < cacheCustomHorizontalLines.Length; idx++)
if (cacheCustomHorizontalLines[idx] != null && cacheCustomHorizontalLines[idx].TicksDistance == ticksDistance && cacheCustomHorizontalLines[idx].LineColor == lineColor && cacheCustomHorizontalLines[idx].EqualsInput(input))
return cacheCustomHorizontalLines[idx];
return CacheIndicator<CustomHorizontalLines>(new CustomHorizontalLines(){ TicksDistance = ticksDistance, LineColor = lineColor }, input, ref cacheCustomHorizontalLines);
}
}
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.CustomHorizontalLines CustomHorizontalLines(int ticksDistance, Brush lineColor)
{
return indicator.CustomHorizontalLines(Input, ticksDistance, lineColor);
}

public Indicators.CustomHorizontalLines CustomHorizontalLines(ISeries<double> input , int ticksDistance, Brush lineColor)
{
return indicator.CustomHorizontalLines(input, ticksDistance, lineColor);
}
}
}

namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.CustomHorizontalLines CustomHorizontalLines(int ticksDistance, Brush lineColor)
{
return indicator.CustomHorizontalLines(Input, ticksDistance, lineColor);
}

public Indicators.CustomHorizontalLines CustomHorizontalLines(ISeries<double> input , int ticksDistance, Brush lineColor)
{
return indicator.CustomHorizontalLines(input, ticksDistance, lineColor);
}
}
}

#endregion

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
What broker to use for trading palladium futures
Commodities
Strategy stop orders partially filled
EasyLanguage Programming
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Funded Trader platforms
72 thanks
Spoo-nalysis ES e-mini futures S&P 500
21 thanks
The Trading Pit "Futures VIP" Account Journal
15 thanks
GFIs1 1 DAX trade per day journal
14 thanks
Just another trading journal: PA, Wyckoff & Trends
12 thanks
  #2 (permalink)
 
trendisyourfriend's Avatar
 trendisyourfriend 
Quebec Canada
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,179
Thanks Received: 6,022

Have you tried using ...
Calculate = Calculate.OnEachTick; // Change Calculate property to OnEachTick

Also, you do not need the removedrawobject("tagname")

When you post code, use the Code symbol (signe cardinal ou tic-tac-to dans la barre des menus)

Reply With Quote




Last Updated on July 20, 2023


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts