Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Problem with Zigzag that prints highs/lows and swing distance
Updated August 7, 2015
Problem with Zigzag that prints highs/lows and swing distance
June 18th, 2013, 05:39 PM
seoul, Korea
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039
90% of the time this thing plots the highs and lows and swing distance correctly but sometimes it doesn't I have played with all the variables but cant figure out what's up. Anyone more experienced can help?
Code
// ZigZag Pnts - Text Plots
//Treydog999
inputs:
HighLow( True ),
RetracePnts( .0005 ),
LineColor( Yellow ),
LineWidth( 1 ),
LineStyle ( 1 ) ,
PlotLines(false),
PriceOrSwing("Swing"),
DecimalPlaces(4),
Color(yellow),
TextSize(8);
variables:
SwingMult(0),
Price(close),
Price1(close),
Price2(close),
var0( 0 ),
var1( Price ),
var2( Date ),
var3( Time ),
var4( 0 ),
var5( false ),
var6( false ),
var7( false ),
var8( 0 ),
SwingDistance( 0 ) ;
//Set Swing Mult
SwingMult = MinMove*PriceScale;
//High Low switch
if HighLow = true then begin
price1 = high;
price2 = low;
end;
if highlow = false then begin
price1 = close;
price2 = close;
end;
// Zigzag calcs
var0 = SwingHigh( 1, Price1, 1, 2 ) ;
if var0 <> -1 then
begin
condition1 = var4 <= 0 and var0 >= var1 + RetracePnts ;
if condition1 then
begin
var5 = true ;
var6 = true ;
var4 = 1 ;
end
else
begin
condition1 = var4 = 1 and var0 >= var1 ;
if condition1 then
begin
var5 = true ;
var7 = true ;
end;
end ;
end
else
begin
var0 = SwingLow( 1, price2, 1, 2 ) ;
if var0 <> -1 then
begin
condition1 = var4 >= 0 and var0 <= var1 - RetracePnts ;
if condition1 then
begin
var5 = true ;
var6 = true ;
var4 = -1 ;
end
else
begin
condition1 = var4 = -1 and var0 <= var1 ;
if condition1 then
begin
var5 = true;
var7 = true ;
end ;
end;
end ;
end ;
if var5 then
begin
var1 = var0 ;
var2 = Date[1] ;
var3 = Time[1] ;
var5 = false ;
end ;
if var6 and PlotLines = True then
begin
var8 = TL_New( var2, var3, var1, var2[1], var3[1],
var1[1] ) ;
TL_SetExtLeft( var8, false ) ;
TL_SetExtRight( var8, false ) ;
TL_SetSize( var8, LineWidth ) ;
TL_SetColor( var8, LineColor ) ;
tl_setstyle(var8,LineStyle);
var6 = false ;
end
else if var7 and PlotLines = True then
begin
TL_SetEnd( var8, var2, var3, var1 ) ;
var7 = false ;
end ;
//Text Prints
SwingDistance = absvalue(var1 - var1[1])*SwingMult;
if var4 <> var4[1] and PriceOrSwing = "Price" then
value1 = text_new(var2, var3, var1, numtostr(var1,DecimalPlaces));
if var4 <> var4[1] and PriceOrSwing = "Swing" then
value1 = text_new(var2, var3, var1, numtostr(swingdistance,0));
if var4 <> var4[1] and PriceOrSwing = "Both" then begin
if DecimalPlaces = 4 then
value1 = text_new(var2, var3, var1, numtostr(var1,DecimalPlaces)+ NewLine + " " + numtostr(swingdistance,0) );
if DecimalPlaces = 2 then
value1 = text_new(var2, var3, var1, numtostr(var1,DecimalPlaces)+ NewLine + " " + numtostr(swingdistance,0) );
end;
if var4 = -1 then
text_setlocation(value1,var2,var3,var1 - truerange*.25);
if var4 = 1 then
text_setlocation(value1,var2,var3,var1 + truerange*.25);
if value1 > 0 then begin
text_setcolor(value1,color);
text_setstyle(value1,2,2);
text_setsize(value1,textsize);
end;
//debug
//value2 = text_new(var2, var3, var1 + .25*averagetruerange(10) , numtostr(var1,4));
//print(var0:0:4," ", var1:0:4, " ", var2, " ", var3, " ", var4, " ", var5, " ", var6, " ", var7, " ", var8);
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
June 19th, 2013, 09:32 PM
NYC + NY / USA
Experience: Advanced
Platform: "I trade, therefore, I AM!"; Theme Song: "Atomic Dog!"
Trading: EMD, 6J, ZB
Posts: 796 since Oct 2009
I also noticed the inability to push the fibs over, say, using the displacement or +- offset, in this manner the lines and percentages can be located in the clear margin, especially if you set a high number for the margin property
is there anyway to displace right these fibs?
June 19th, 2013, 10:39 PM
seoul, Korea
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039
kronie
I also noticed the inability to push the fibs over, say, using the displacement or +- offset, in this manner the lines and percentages can be located in the clear margin, especially if you set a high number for the margin property
is there anyway to displace right these fibs?
No you can not displace right or left.
June 20th, 2013, 06:46 AM
seoul, Korea
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039
Here is an example. all of the plots on this chart except this one is correct. no idea how it does it. the zigzag plot is correct but the exit value which uses the same variable var1 is now the wrong when its set to string. If its not clear i am refering to the 1.3265 13 plot the 2nd 1.3265 is in fact correct.
June 26th, 2013, 08:18 PM
seoul, Korea
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039
any easy language guru's out there lend a helping hand?
June 27th, 2013, 05:17 AM
Posts: 2,436 since Apr 2013
Thanks Given: 482
Thanks Received: 1,629
When a current swing high updates by making a higher high (vice versa for the low) you correctly update the trendline end point and text location, but the code is missing the update for the text string. Add this and it should work fine.
Regards,
ABCTG
June 27th, 2013, 07:00 PM
seoul, Korea
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039
ABCTG
When a current swing high updates by making a higher high (vice versa for the low) you correctly update the trendline end point and text location, but the code is missing the update for the text string. Add this and it should work fine.
Regards,
ABCTG
Yes, I have tried that and also cleaned up the variables. multicharts is stupid as they dont name anything. anyway what happens now is the swing distance when updated does not calculate correctly if there is an update. I have tried several iterations, using TL_GetBeginVal works great but if I choose the option not to plot the lines then i cant grab the value. so i added swingstart variable to extract that but now i on updates i get the distance between the update and the previous end swing so the value can be like 1 tick or something instead of from the start of the move.
Code
// ZigZag Pnts - Text Plots
//Treydog999
inputs:
HighLow( True ),
RetracePnts( .0005 ),
LineColor( Yellow ),
LineWidth( 1 ),
LineStyle ( 1 ) ,
PlotLines(false),
PriceOrSwing("Both"),
DecimalPlaces(4),
Color(yellow),
TextSize(8);
variables:
SwingMult(0),
Price(close),
Price1(close),
Price2(close),
SwingPrice( 0 ),
SwingPrice1( Price ),
SwingDate( Date ),
SwingTime( Time ),
TLDir( 0 ),
SaveSwing( false ),
AddTL( false ),
UpdateTL( false ),
var8( 0 ),
SwingDistance( 0 ),
SwingStart(0) ;
//Set Swing Mult
SwingMult = MinMove*PriceScale;
//High Low switch
if HighLow = true then begin
price1 = high;
price2 = low;
end;
if highlow = false then begin
price1 = close;
price2 = close;
end;
// Zigzag calcs
SwingPrice = SwingHigh( 1, Price1, 1, 2 ) ;
if SwingPrice <> -1 then
begin
condition1 = TLDir <= 0 and SwingPrice >= SwingPrice1 + RetracePnts ;
if condition1 then
begin
SaveSwing = true ;
AddTL = true ;
TLDir = 1 ;
end
else
begin
condition1 = TLDir = 1 and SwingPrice >= SwingPrice1 ;
if condition1 then
begin
SaveSwing = true ;
UpdateTL = true ;
end;
end ;
end
else
begin
SwingPrice = SwingLow( 1, price2, 1, 2 ) ;
if SwingPrice <> -1 then
begin
condition1 = TLDir >= 0 and SwingPrice <= SwingPrice1 - RetracePnts ;
if condition1 then
begin
SaveSwing = true ;
AddTL = true ;
TLDir = -1 ;
end
else
begin
condition1 = TLDir = -1 and SwingPrice <= SwingPrice1 ;
if condition1 then
begin
SaveSwing = true;
UpdateTL = true ;
end ;
end;
end ;
end ;
if SaveSwing then
begin
SwingPrice1 = SwingPrice ;
SwingDate = Date[1] ;
SwingTime = Time[1] ;
SaveSwing = false ;
end ;
//added Updates text when you need to update the trend line. - Me
If UpdateTL = True then begin
SwingDistance = //absvalue(SwingPrice1 - SwingPrice1[1])*SwingMult;
//absvalue(TL_GetBeginVal(var8)-swingprice1)*swingmult;
absvalue(SwingStart - SwingPrice1)*SwingMult;
If PriceOrSwing = "Both" then begin
if DecimalPlaces = 4 then
Text_Setstring(value1, numtostr(SwingPrice1,DecimalPlaces)+ NewLine + " " + numtostr(swingdistance,0) );
if DecimalPlaces = 2 then
Text_Setstring(value1, numtostr(SwingPrice1,DecimalPlaces)+ NewLine + " " + numtostr(swingdistance,0)) ;
end;
IF PriceOrSwing = "Price" then
Text_SetString(value1, numtostr(SwingPrice1,DecimalPlaces));
If PriceOrSwing = "Swing" then
Text_SetString(value1, numtostr(swingdistance,0));
end;
//end
If AddTL and Plotlines = false then
SwingStart = SwingPrice1;
if AddTL and PlotLines = True then
begin
SwingStart = SwingPrice1;
var8 = TL_New( SwingDate, SwingTime, SwingPrice1, SwingDate[1], SwingTime[1], SwingPrice1[1] ) ;
TL_SetExtLeft( var8, false ) ;
TL_SetExtRight( var8, false ) ;
TL_SetSize( var8, LineWidth ) ;
TL_SetColor( var8, LineColor ) ;
tl_setstyle(var8,LineStyle);
AddTL = false ;
end
else if UpdateTL and PlotLines = True then
begin
TL_SetEnd( var8, SwingDate, SwingTime, SwingPrice1 ) ;
UpdateTL = false ;
end ;
//Text Prints
SwingDistance = absvalue(SwingPrice1 - SwingPrice1[1])*SwingMult;
if TLDir <> TLDir[1] and PriceOrSwing = "Price" then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(SwingPrice1,DecimalPlaces));
if TLDir <> TLDir[1] and PriceOrSwing = "Swing" then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(swingdistance,0));
if TLDir <> TLDir[1] and PriceOrSwing = "Both" then begin
if DecimalPlaces = 4 then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(SwingPrice1,DecimalPlaces)+ NewLine + " " + numtostr(swingdistance,0) );
if DecimalPlaces = 2 then
value1 = text_new(SwingDate, SwingTime, SwingPrice1, numtostr(SwingPrice1,DecimalPlaces)+ NewLine + " " + numtostr(swingdistance,0) );
end;
if TLDir = -1 then
text_setlocation(value1,SwingDate,SwingTime,SwingPrice1 - truerange*.25);
if TLDir = 1 then
text_setlocation(value1,SwingDate,SwingTime,SwingPrice1 + truerange*.25);
//Text styling
if value1 > 0 then begin
text_setcolor(value1,color);
text_setstyle(value1,2,2);
text_setsize(value1,textsize);
end;
//value2 = text_new(SwingDate, SwingTime, SwingPrice1 + .25*averagetruerange(10) , numtostr(SwingPrice1,4));
//print(SwingPrice:0:4," ", SwingPrice1:0:4, " ", SwingDate, " ", SwingTime, " ", TLDir, " ", SaveSwing, " ", AddTL, " ", UpdateTL, " ", var8);
August 7th, 2015, 06:16 AM
Mumbai India
Experience: None
Platform: TradeStation
Trading: Forex
Posts: 39 since Nov 2014
Thanks Given: 58
Thanks Received: 10
Hi @treydog999 :
Were you finally able to get this to work? Will be extremely useful to have.
Thank you
August 7th, 2015, 06:21 AM
seoul, Korea
Experience: Intermediate
Platform: Multicharts
Broker: CQG, DTN IQfeed
Trading: YM 6E
Posts: 897 since Jul 2012
Thanks Given: 291
Thanks Received: 1,039
courier12
Hi @
treydog999 :
Were you finally able to get this to work? Will be extremely useful to have.
Thank you
Sorry I never did figure it out. The plot and data seemed to be linked.
Last Updated on August 7, 2015