NexusFi: Find Your Edge


Home Menu

 





Simple zigzag for strength 1 (pinescript to ninjascript)


Discussion in NinjaTrader

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




 
Search this Thread

Simple zigzag for strength 1 (pinescript to ninjascript)

  #1 (permalink)
rafaelcoisa
são paulo
 
Posts: 5 since Aug 2021
Thanks Given: 0
Thanks Received: 3

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 NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
What broker to use for trading palladium futures
Commodities
Trade idea based off three indicators.
Traders Hideout
 
  #2 (permalink)
 sg72 
Orange County, CA, USA
 
Experience: Intermediate
Platform: NinjaTrader, Fidelity ATP
Trading: ES/NQ/RTY, Equity ETFs, Options
Posts: 59 since Sep 2018
Thanks Given: 44
Thanks Received: 48

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

Reply With Quote




Last Updated on October 3, 2021


© 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