NexusFi: Find Your Edge


Home Menu

 





ZigZag with Depth and Backstep


Discussion in EasyLanguage Programming

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




 
Search this Thread

ZigZag with Depth and Backstep

  #1 (permalink)
eggzactly
lisbon Portugal
 
Posts: 2 since Jan 2013
Thanks Given: 0
Thanks Received: 1

Hi,

Can someone please help me and add Depth and Backstep calculation to the ZigZag% indicator

Thanks in advance,

ELD Code

{ Search Tag: WA-ZigZag % }

using elsystem;
using elsystem.drawing;
using elsystem.drawingobjects;

inputs:
double HighPivotPrice( High ) [
DisplayName = "HighPivotPrice",
ToolTip = "Enter an EasyLanguage expression to use in the calculation of high ZigZag pivots."],

double LowPivotPrice( Low ) [
DisplayName = "LowPivotPrice",
ToolTip = "Enter an EasyLanguage expression to use in the calculation of low ZigZag pivots."],

double RetracePct( 5 ) [
DisplayName = "RetracePct",
ToolTip = "Retracement Percentage. Enter The amount of retracement of the price specified in the price input that will cause a new zigzag line to be drawn."],

int LineColor( MyColors( "DodgerBlue" ) ) [
DisplayName = "LineColor",
ToolTip = "Enter the color to be used for the zigzag lines."],

int LineWidth( 1 ) [
DisplayName = "LineWidth",
ToolTip = "Enter the width, specified as a number, of the zigzag lines. This value can have any integer value from 0 to 6."];

variables:
intrabarpersist bool UseBNPoint( false ),
int DrawingObjectBarNumber( 0 ),
TrendLine ZigZagTrendline( NULL ),
DTPoint SwingDTPoint( NULL ),
DTPoint LastSwingDTPoint( NULL ),
BNPoint SwingBNPoint( NULL ),
BNPoint LastSwingBNPoint( NULL ),
double NewSwingPrice( 0 ),
double SwingPrice( Close ), { used as a convenient 2-element array }
int TLDir( 0 ), { TLDir = -1 implies prev TL dn, +1 implies prev TL up }
double RetraceFctrUp( 1 + RetracePct * .01 ),
double RetraceFctrDn( 1 - RetracePct * .01 ),
bool SaveSwing( false ),
bool AddTL( false ),
bool UpdateTL( false );

method TrendLine CreateNewTrendline()
variables: TrendLine tempTL;
begin
if UseBNPoint then
tempTL = TrendLine.Create( LastSwingBNPoint, SwingBNPoint )
else { use DTPoint }
tempTL = TrendLine.Create( LastSwingDTPoint, SwingDTPoint );

{
Setting 'Persist' to false causes the trendline to be deleted on an
intrabar tick. When set to false, a trendline that is created on the
closing tick of the bar is saved/retained.
}
tempTL.Persist = false;
tempTL.Lock = true; { prevent inadvertent moving }
tempTL.Color = GetColorFromInteger( 255, LineColor );
tempTL.ExtLeft = false;
tempTL.ExtRight = false;
tempTL.Weight = LineWidth;

{
this is how the trendline is "shown"; the trendline is added to the
DrawingObjects collection; if you want to remove the trendline, you can
use the Delete method of the DrawingObjects class; DrawingObjects collection
is not available in RadarScreen (it is NULL), so we only add the trendlines
to the collection if not NULL
}
if DrawingObjects <> NULL then
DrawingObjects.Add( tempTL );

return tempTL;
end;

{ convert integer color to a color object and return the color object }
method Color GetColorFromInteger( int Alpha, int ColorInteger )
begin
return Color.FromARGB( Alpha, GetRValue( ColorInteger ),
GetGValue( ColorInteger ), GetBValue( ColorInteger ) );
end;

once
begin
{
When this study is applied to tick bars or advanced bars, we use BNPoint
positioning of text labels. This ensures that the text labels are positioned
on the correct bar even when multiple bars occur in the same second (as can
occur with very short-term tick bars). When positioning time-based bars, on
the other hand, we’ll use DTPoint positioning. This type of positioning can
account for missing bars in the data stream (periods of no trading activity,
as can occur with ‘thin’ issues). Missing bars, of course, cannot occur when
using tick-based charts or advanced bars, since these bar-building mechanisms
do not move along the x-axis until enough trades have occurred to complete a
bar. Thus, the approach illustrated here gives us the best of both worlds
– sub-second positioning and automatic accounting for missing bars.
}
UseBNPoint = BarType = 0 or ( BarType > 4 and BarType <> 14 );

if UseBNPoint then
SwingBNPoint = BNPoint.Create( CurrentBar + MaxBarsBack - 1, Close )
else
SwingDTPoint = DTPoint.Create( BarDateTime, Close );
end;

{ set the bar number for the drawing object }
if UseBNPoint then
DrawingObjectBarNumber = CurrentBar + MaxBarsBack - 1;

NewSwingPrice = SwingHigh( 1, HighPivotPrice, 1, 2 );

if NewSwingPrice <> -1 then
begin
if TLDir <= 0 and NewSwingPrice >= SwingPrice * RetraceFctrUp then
begin
SaveSwing = true;
AddTL = true;
TLDir = 1;
end
else if TLDir = 1 and NewSwingPrice >= SwingPrice then
begin
SaveSwing = true;
UpdateTL = true;
end;
end
else
begin
NewSwingPrice = SwingLow( 1, LowPivotPrice, 1, 2 );
if NewSwingPrice <> -1 then
begin
if TLDir >= 0 and NewSwingPrice <= SwingPrice * RetraceFctrDn then
begin
SaveSwing = true;
AddTL = true;
TLDir = -1;
end
else if TLDir = -1 and NewSwingPrice <= SwingPrice then
begin
SaveSwing = true;
UpdateTL = true;
end;
end;
end;

{ save new swing and reset SaveSwing }
if SaveSwing then
begin
if UseBNPoint then
begin
LastSwingBNPoint = SwingBNPoint;
SwingBNPoint = BNPoint.Create( DrawingObjectBarNumber[1], NewSwingPrice );
end
else
begin
LastSwingDTPoint = SwingDTPoint;
SwingDTPoint = DTPoint.Create( BarDateTime[1], NewSwingPrice );
end;

SwingPrice = NewSwingPrice;
SaveSwing = false;
end;

if AddTL then { add new trendline }
begin
ZigZagTrendline = CreateNewTrendline();
AddTL = false;
end
else if UpdateTL then { update trendline }
begin
if ZigZagTrendline <> NULL then
begin
if UseBNPoint then
ZigZagTrendline.SetEndPoint( SwingBNPoint )
else
ZigZagTrendline.SetEndPoint( SwingDTPoint );
end;

UpdateTL = false;
end;

Reply With Quote
The following user says Thank You to eggzactly for this post:

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
Request for MACD with option to use different MAs for fa …
NinjaTrader
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
55 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
What percentage per day is possible? [Poll]
31 thanks
GFIs1 1 DAX trade per day journal
29 thanks

  #2 (permalink)
 
nothingbutprofits's Avatar
 nothingbutprofits 
rochester new york/USA
 
Experience: Advanced
Platform: ThinkOrSwim & NT
Broker: NT, TOS
Trading: ES NQ RTY CL NG
Posts: 78 since Feb 2021
Thanks Given: 245
Thanks Received: 48

What trading platform?

eggzactly View Post
Hi,

Can someone please help me and add Depth and Backstep calculation to the ZigZag% indicator

Thanks in advance,

ELD Code

{ Search Tag: WA-ZigZag % }

end;


Reply With Quote
  #3 (permalink)
 
syswizard's Avatar
 syswizard 
Philadelphia PA
 
Experience: Advanced
Platform: Multicharts
Broker: Ironbeam, Rithmic
Trading: Emini ES / NQ / CL / RTY / YM / BTC
Posts: 344 since Jan 2019
Thanks Given: 20
Thanks Received: 146



nothingbutprofits View Post
What trading platform?

Looks like EasyLangage.

Reply With Quote
The following user says Thank You to syswizard for this post:





Last Updated on April 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