NexusFi: Find Your Edge


Home Menu

 





ZigZag expanded in time (code)


Discussion in EasyLanguage Programming

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




 
Search this Thread

ZigZag expanded in time (code)

  #1 (permalink)
Doctor Leo
St. Petersburg, Russia
 
Posts: 30 since Nov 2010
Thanks Given: 6
Thanks Received: 19

Hello everybody,

just thought the following code could be of interest for someone. It is a representation of zigzag, not in form of the well-known lines, but exactly the value of this indicator on each bar. Therefore you can follow its move during the forming of the most recent span, not only after a reversal occurs. The indicator uses two data streams: data1 is used for plotting and data2 — for determining the swing criterion. By default if is equal to 1 ATR of data2. The other lines on the chart are 2 standard errors from the uppermost or lowermost line (depending on the direction) and target levels for upwards and downwards movements. I hope the parameters are self-explanatory, but if you're in trouble please feel free to ask.

The indicator uses a function named __zigzagtrue_stddev__, please make sure the name is exactly that.

 
Code
input: period(numericSimple), factor_atr(numericSimple), factor_stddev(numericSimple), dir(numericRef), atr(numericRef), sd(numericRef);

var: xhigh(high), xlow(low);

xhigh = maxlist(high, xhigh);
xlow = minlist(low, xlow);

atr = avgtruerange(period) of data2 * factor_atr;
sd = stderror(close, period) of data2 * factor_stddev;

if low <= xhigh - atr and dir = 1 then begin
	dir = -1;
	xlow = low;
end;

if high >= xlow + atr and dir = -1 then begin
	dir = 1;
	xhigh = high;
end;

if dir = -1 then begin
	value1 = xlow;
end;
if dir = 1 then begin
	value1 = xhigh;
end;

__zigzagtrue_stddev__ = value1;
Now the indicator itself:

 
Code
input: period(20), factor_atr(2), factor_stddev(2), retracement(0.5);

var: xhigh(high), xlow(low), atr(0), dir(1), sd(0);

value1 = __zigzagtrue_stddev__(period, factor_atr, factor_stddev, dir, atr, sd);

if dir = -1 then begin
	setPlotColor(1, red);
	if dir[1] = 1 then value2 = value1 - atr;
	value3 = value1 + atr * retracement;
	value4 = value1 + sd;
	setPlotColor(2, red);
	setPlotColor(3, red);
	setPlotColor(4, white);
end;
if dir = 1 then begin
	setPlotColor(1, yellow);
	if dir[1] = -1 then value2 = value1 + atr;
	value3 = value1 - atr * retracement;
	value4 = value1 - sd;
	setPlotColor(2, yellow);
	setPlotColor(3, yellow);
	setPlotColor(4, white);
end;

plot1(value1);
plot2(value2);
plot3(value3);
plot4(value4);
If this stuff is apt for anyone please share your experience, would love also to hear about how this behaves on other instruments, in particular on index futures.

Hope I haven't dubbed someone else's work here on the forum.

Attached Thumbnails
Click image for larger version

Name:	Screen shot 2010-12-23 at 22.08.20 .png
Views:	805
Size:	57.3 KB
ID:	27299  
Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
What broker to use for trading palladium futures
Commodities
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
How to apply profiles
Traders Hideout
Better Renko Gaps
The Elite Circle
 
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,465 since Jun 2009
Thanks Given: 33,242
Thanks Received: 101,665


Thanks for sharing. Have you looked at SuperTrend? It seems similar.



Mike



Join the free Markets Chat beta: one platform, all the trade rooms!

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
Doctor Leo
St. Petersburg, Russia
 
Posts: 30 since Nov 2010
Thanks Given: 6
Thanks Received: 19

No, I hadn't seen your code before posting mine, no kidding Seriously, the idea is the same except that I use separate data streams which sometimes allow for using interesting solutions like mixing up instruments or using artificial indices, etc.

Reply With Quote




Last Updated on December 28, 2010


© 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