Plot and Export Indicator : ZigZag  [SOLVED]

Questions about MultiCharts and user contributed studies.
shane1800
Posts: 84
Joined: 28 Feb 2014
Has thanked: 5 times
Been thanked: 5 times

Plot and Export Indicator : ZigZag

Postby shane1800 » 06 Mar 2014

Hi,

I added the ZigZag % indicator to my chart and would like to export the actual ZigZag values so I can modify in Excel. I notice it says No Plot. Anyways to plot this so I can export?

See attached yellow line.
Attachments
Screen Shot 2014-03-06 at 8.36.52 PM.png
(38.1 KiB) Downloaded 1126 times

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Plot and Export Indicator : ZigZag

Postby JoshM » 08 Mar 2014

I added the ZigZag % indicator to my chart and would like to export the actual ZigZag values so I can modify in Excel. I notice it says No Plot. Anyways to plot this so I can export?
If you want to output these values, you need to edit the code of the indicator and use FileAppend to output the data to a file, which then can be subsequently opened in Excel.

shane1800
Posts: 84
Joined: 28 Feb 2014
Has thanked: 5 times
Been thanked: 5 times

Re: Plot and Export Indicator : ZigZag

Postby shane1800 » 08 Mar 2014

Thanks Josh. Looking at the ZigZag code, I'm not sure what to put in the "Appended Text" field to represent the ZigZag value. Do you know?

FileAppend("C:\test.txt","Appended Text");

Code: Select all

inputs:
Price( Close ),
RetracePct( 5 ),
LineColor( Yellow ),
LineWidth( 1 ) ;

variables:
var0( 0 ),
var1( Price ),
var2( Date ),
var3( Time ),
var4( 0 ),
var5( 1 + RetracePct * .01 ),
var6( 1 - RetracePct * .01 ),
var7( false ),
var8( false ),
var9( false ),
var10( 0 ) ;



var0 = SwingHigh( 1, Price, 1, 2 ) ;
if var0 <> -1 then
begin
condition1 = var4 <= 0 and var0 >= var1 * var5 ;
if condition1 then
begin
var7 = true ;
var8 = true ;
var4 = 1 ;
end
else
begin
condition1 = var4 = 1 and var0 >= var1 ;
if condition1 then

begin
var7 = true ;
var9 = true ;
end ;
end;
end
else
begin
var0 = SwingLow( 1, Price, 1, 2 ) ;
if var0 <> -1 then
begin
condition1 = var4 >= 0 and var0 <= var1 * var6 ;
if condition1 then

begin
var7 = true ;
var8 = true ;
var4 = -1 ;
end
else
begin
condition1 = var4 = -1 and var0 <= var1 ;
if condition1 then
begin
var7 = true;
var9 = true ;
end ;
end;
end ;
end ;

if var7 then

begin
var1 = var0 ;
var2 = Date[1] ;
var3 = Time[1] ;
var7 = false ;
end ;

if var8 then

begin
var10 = TL_New( var2, var3, var1, var2[1], var3[1],
var1[1] ) ;
TL_SetExtLeft( var10, false ) ;
TL_SetExtRight( var10, false ) ;
TL_SetSize( var10, LineWidth ) ;
TL_SetColor( var10, LineColor ) ;
var8 = false ;
end
else if var9 then

begin
TL_SetEnd( var10, var2, var3, var1 ) ;
var9 = false ;
end ;

FileAppend("C:\test.txt","Appended Text");


User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Plot and Export Indicator : ZigZag  [SOLVED]

Postby JoshM » 09 Mar 2014

Thanks Josh. Looking at the ZigZag code, I'm not sure what to put in the "Appended Text" field to represent the ZigZag value. Do you know?
Before I answer this, I wanted to give a quick comment on MultiCharts' default indicators. In general, you're better off by adding descriptive variable names, whitespace, and comments to enhance the readability of code. The default indicators, such as the ZigZag code, are not a great example of understandable programming (and make it look a lot harder than it actually is).

On to the programming code:

Code: Select all

inputs:
Price( Close ),
RetracePct( 5 ),
LineColor( Yellow ),
LineWidth( 1 ) ;

variables:
var0( 0 ),
var1( Price ),
var2( Date ),
var3( Time ),
var4( 0 ),
var5( 1 + RetracePct * .01 ),
var6( 1 - RetracePct * .01 ),
var7( false ),
var8( false ),
var9( false ),
var10( 0 ) ;

Variables:
outputString(""),
printLastValueOnce(false);

var0 = SwingHigh( 1, Price, 1, 2 ) ;
if var0 <> -1 then
begin
condition1 = var4 <= 0 and var0 >= var1 * var5 ;
if condition1 then
begin
var7 = true ;
var8 = true ;
var4 = 1 ;
end
else
begin
condition1 = var4 = 1 and var0 >= var1 ;
if condition1 then

begin
var7 = true ;
var9 = true ;
end ;
end;
end
else
begin
var0 = SwingLow( 1, Price, 1, 2 ) ;
if var0 <> -1 then
begin
condition1 = var4 >= 0 and var0 <= var1 * var6 ;
if condition1 then

begin
var7 = true ;
var8 = true ;
var4 = -1 ;
end
else
begin
condition1 = var4 = -1 and var0 <= var1 ;
if condition1 then
begin
var7 = true;
var9 = true ;
end ;
end;
end ;
end ;


// Generate data string and output to file
if (var8 = true) or (LastBarOnChart_s = true and printLastValueOnce = false) then begin

once ClearDebug;

outputString = Text(FormatDate("dd-MM-yyyy", ELDateToDateTime(Date)),
";", NumToStr(var1, 4));

Print(outputString);

FileAppend("C:\text.csv", Text(outputString, NewLine));

if (LastBarOnChart_s = true) then
printLastValueOnce = true;
end;



if var7 then

begin
var1 = var0 ;
var2 = Date[1] ;
var3 = Time[1] ;
var7 = false ;
end ;

if var8 then

begin
var10 = TL_New( var2, var3, var1, var2[1], var3[1],
var1[1] ) ;

TL_SetExtLeft( var10, false ) ;
TL_SetExtRight( var10, false ) ;
TL_SetSize( var10, LineWidth ) ;
TL_SetColor( var10, LineColor ) ;
var8 = false ;
end
else if var9 then

begin
TL_SetEnd( var10, var2, var3, var1 ) ;
var9 = false ;
end ;
I added the following things to the default indicator:

Code: Select all

Variables:
outputString(""),
printLastValueOnce(false);
And:

Code: Select all

// Generate data string and output to file
if (var8 = true) or (LastBarOnChart_s = true and printLastValueOnce = false) then begin

once ClearDebug;

outputString = Text(FormatDate("dd-MM-yyyy", ELDateToDateTime(Date)),
";", NumToStr(var1, 4));

Print(outputString);

FileAppend("C:\text.csv", Text(outputString, NewLine));

if (LastBarOnChart_s = true) then
printLastValueOnce = true;
end;
In this last part we first clear the output window of the PowerLanguage Editor once. Then generate a string with the `var1` variable in it. This string is then printed to the output window and the `C:\text.csv` file. Lastly, the `printLastValueOnce` variable is used to output the last ZigZag point.

This gives the following output:

Code: Select all

10-09-2012;1.2573
21-09-2012;1.3126
08-10-2012;1.2857
11-10-2012;1.3031
18-10-2012;1.2874
26-10-2012;1.3118
27-11-2012;1.2703
10-12-2012;1.3095
19-12-2012;1.2925
04-01-2013;1.3244
15-01-2013;1.3048
11-02-2013;1.3639
08-03-2013;1.2966
14-03-2013;1.3107
10-04-2013;1.2779
18-04-2013;1.3173
02-05-2013;1.3001
20-05-2013;1.3179
31-05-2013;1.2835
27-06-2013;1.3395
12-07-2013;1.2781
04-09-2013;1.3417
12-09-2013;1.3118
04-11-2013;1.3800
20-11-2013;1.3359
06-01-2014;1.3800
24-01-2014;1.3537
03-02-2014;1.3695
11-02-2014;1.3487
07-03-2014;1.3790
Or, graphically:

Image
Attachments
scr.09-03-2014 06.42.25.png
(83.29 KiB) Downloaded 1218 times

shane1800
Posts: 84
Joined: 28 Feb 2014
Has thanked: 5 times
Been thanked: 5 times

Re: Plot and Export Indicator : ZigZag

Postby shane1800 » 10 Mar 2014

That works wonderfully well. I appreciate you taking the time to help me with this.

shane1800
Posts: 84
Joined: 28 Feb 2014
Has thanked: 5 times
Been thanked: 5 times

Re: Plot and Export Indicator : ZigZag

Postby shane1800 » 14 Mar 2014

I missed this for some reason before. When I place a 10% on INTC I notice that the output values are correct but the dates are off.

For example:
6/2/2014; 26.67

26.67 is the correct value for last ZigZag high but date should be 1/15/2014. Do you see the same thing?
Attachments
Screen Shot 2014-03-14 at 2.17.43 PM.png
(126.61 KiB) Downloaded 1077 times

shane1800
Posts: 84
Joined: 28 Feb 2014
Has thanked: 5 times
Been thanked: 5 times

Re: Plot and Export Indicator : ZigZag

Postby shane1800 » 16 Mar 2014

Got some help, here's the fix:

Replace
"ELDateToDateTime(Date)" with "ELDateToDateTime(var2)"

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Plot and Export Indicator : ZigZag

Postby TJ » 16 Mar 2014

Got some help, here's the fix:
Replace
"ELDateToDateTime(Date)" with "ELDateToDateTime(var2)"
Good to know it is working.


Return to “MultiCharts”