Simple zigzag for strength 1 (pinescript to ninjascript) - futures io
futures io



Simple zigzag for strength 1 (pinescript to ninjascript)


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Simple zigzag for strength 1 (pinescript to ninjascript)

(login for full post details)
  #1 (permalink)
rafaelcoisa
são paulo
 
 
Posts: 1 since Aug 2021
Thanks: 0 given, 0 received

Hello everyone,

would anyone know how to translate the script below (pinescript) to ninjascript?

The script is very simple, it only connects the pivots strength 1 with a line, including the pivots on 'outside bars' (bars with pivot high and low at the same time).

I've already tested the built-in Zigzag of Ninjatrader, all the ones available on the Ninjatrader User Script Sharing site, and all the free ones available here in futures.io, but I still think this one below is the best one for monitoring the formation of all legs in the chart.

 
Code
//@version=4
study(title="zigzag pivot high pivot low", overlay=true, max_lines_count=500, max_labels_count=500)

var dirUp = false
var lastLow = 0.0
var lastHigh = 0.0
var timeLow = bar_index
var timeHigh = bar_index
var line li = na

if dirUp
if pivotlow(1,0)
lastLow := low
timeLow := bar_index
line.delete(li)
li := line.new(timeHigh, lastHigh, timeLow, lastLow, xloc.bar_index, color=dirUp ? color.yellow : color.blue, width=2, style=line.style_solid)
if pivothigh(1,0)
lastHigh := high
timeHigh := bar_index
dirUp := false
li := line.new(timeHigh, lastHigh, timeLow, lastLow, xloc.bar_index, color=dirUp ? color.yellow : color.blue, width=2, style=line.style_solid)

if not dirUp
if pivothigh(1,0)
lastHigh := high
timeHigh := bar_index
line.delete(li)
li := line.new(timeHigh, lastHigh, timeLow, lastLow, xloc.bar_index, color=dirUp ? color.yellow : color.blue, width=2, style=line.style_solid)
if pivotlow(1,0)
lastLow := low
timeLow := bar_index
dirUp := true
li := line.new(timeHigh, lastHigh, timeLow, lastLow, xloc.bar_index, color=dirUp ? color.yellow : color.blue, width=2, style=line.style_solid)
A guy (thanks man) tried to do this translation for Quantower C# script like in the script below, but without the 'outside bar' feature.

 
Code
using System;
using System.Drawing;
using TradingPlatform.BusinessLayer;

namespace Zigzag
{
public class Zigzag : Indicator
{
public Zigzag()
: base()
{
Name = "Zigzag";
Description = "Sample ZigZag drawing";
SeparateWindow = false;
}

protected override void OnInit()
{
}

protected override void OnUpdate(UpdateArgs args)
{
}

public override void OnPaintChart(PaintChartEventArgs args)
{
var gr = Graphics.FromHdc(args.Hdc);

var converter = this.CurrentChart.Windows[args.WindowIndex].CoordinatesConverter;
int x1, xprev, y1, yprev;
int max = this.Count - 2;
bool trendingup = true;
bool pivotpoint = false;
int previouspivot = max;
Pen pen;

for (int i = max; i >= 0; i--)
{
double hprice0 = this.High(offset: i);
double lprice0 = this.Low(offset: i);
double hprice1 = this.High(offset: i + 1);
double lprice1 = this.Low(offset: i + 1);
if (trendingup)
{
if (hprice0 < hprice1)
{
pivotpoint = true;
trendingup = false;
}
}
else
{
if (lprice0 > lprice1)
{
pivotpoint = true;
trendingup = true;
}
}
if (i == 0)
{
pivotpoint = true;
trendingup = !trendingup;
hprice1 = this.High(offset: 0);
lprice1 = this.Low(offset: 0);
i -= 1;
}
if (pivotpoint)
{
DateTime t1 = new DateTime(ticks: (this.HistoricalData[i + 1].TicksLeft + this.HistoricalData[i + 1].TicksRight + 1) / 2, DateTimeKind.Utc);
DateTime tprevious = new DateTime(ticks: (this.HistoricalData[previouspivot].TicksLeft + this.HistoricalData[previouspivot].TicksRight + 1) / 2, DateTimeKind.Utc);
x1 = (int)converter.GetChartX(t1);
xprev = (int)converter.GetChartX(tprevious);

if (trendingup)
{
y1 = (int)converter.GetChartY(lprice1);
double priceprev = this.High(offset: previouspivot);
yprev = (int)converter.GetChartY(priceprev);
pen = new Pen(Color.Green, 2);
}
else
{
y1 = (int)converter.GetChartY(hprice1);
double priceprev = this.Low(offset: previouspivot);
yprev = (int)converter.GetChartY(priceprev);
pen = new Pen(Color.YellowGreen, 2);

}
gr.DrawLine(pen, x1, y1, xprev, yprev);
previouspivot = i + 1;
pivotpoint = false;
}
}
}
}
}
Here, an image of the script working:

Reply With Quote

Can you help answer these questions
from other members on futures io?
Tradestation 10 work offline
TradeStation
How to Register my Company in this Platform
Stocks and ETFs
Alternative to Mcginley Dynamic MA
Sierra Chart
RangeRider for NT8 V10
The Elite Circle
Simple code to end my indicator
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Vinny E-Mini & Algobox Review TRADE ROOM
281 thanks
Would you share your Holy Grail?
83 thanks
EURUSD M6E/6E Euro
63 thanks
Spoo-nalysis ES e-mini futures S&P 500
47 thanks
TST/OneUp/LeeLoo/Earn2Trade
17 thanks
 
(login for full post details)
  #2 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
 
Posts: 36 since Sep 2018
Thanks: 32 given, 34 received

There's a built-in zigzag indicator in NT8. Have you looked into whether that does what you need?

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Simple zigzag for strength 1 (pinescript to ninjascript)


Last Updated on October 3, 2021


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts