Zweig's Four Percent Model in EasyLanguage?

Questions about MultiCharts and user contributed studies.
jalexander
Posts: 9
Joined: 17 Mar 2014
Has thanked: 3 times

Zweig's Four Percent Model in EasyLanguage?

Postby jalexander » 17 Mar 2014

I am trying to create a signal in EasyLanguage that replicates Marty Zweig's Four Percent Model.

The signal is applied to a weekly chart of an index.

The approach gives a buy signal when the weekly close of the stock market is four percent above low points (local minima) and a sell signal when the weekly close is four percent below high points (local maxima). For example, the Value Line Index closed at a low point of 1016 on March 6, 2009. The index closed more than 4 percent higher the next week on March 13th, producing a buy signal. That buy signal remained in effect until the index closed down more than 4 percent on May 15th from the closing high of May 8th. The sell signal from that decline was reversed when the market closed up on May 29th more than 4 percent above the May 15th closing low.

See: http://www.trendprognosis.com/2009/05/f ... indicator/

Question: Does anyone have a suggestion for how to find the recent highs/lows from which a 4% signal should be given. Do I need to choose an arbitrary "lookback" period such as "find lowest price within past 6 bars" or is there a better way to find the "local minima" and "local maxima".

Thanks

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

Re: Zweig's Four Percent Model in EasyLanguage?

Postby TJ » 18 Mar 2014

I am trying to create a signal in EasyLanguage that replicates Marty Zweig's Four Percent Model.
The signal is applied to a weekly chart of an index.
The approach gives a buy signal when the weekly close of the stock market is four percent above low points (local minima) and a sell signal when the weekly close is four percent below high points (local maxima). For example, the Value Line Index closed at a low point of 1016 on March 6, 2009. The index closed more than 4 percent higher the next week on March 13th, producing a buy signal. That buy signal remained in effect until the index closed down more than 4 percent on May 15th from the closing high of May 8th. The sell signal from that decline was reversed when the market closed up on May 29th more than 4 percent above the May 15th closing low.
See: http://www.trendprognosis.com/2009/05/f ... indicator/
Question: Does anyone have a suggestion for how to find the recent highs/lows from which a 4% signal should be given. Do I need to choose an arbitrary "lookback" period such as "find lowest price within past 6 bars" or is there a better way to find the "local minima" and "local maxima".
Thanks
That's not difficult to do.

Go to Wiki... find the section on:
PowerLanguage Keyword Reference
https://www.multicharts.com/trading-sof ... /Main_Page

Look for the keywords:

HIGHEST
LOWEST

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Zweig's Four Percent Model in EasyLanguage?

Postby SUPER » 18 Mar 2014

Hope this helps.

Code: Select all

inputs: perOffLo(4.00), { percent off lowest close }
perOffHi(4.00); { percent off highest close }

variables: LC(0), { lowest close }
HC(0), { highest close }
trend(0); { 0 = no trades yet, +1 = up, -1 = down }

{ initialize variables }
if currentBar = 1 then begin
LC = close;
HC = close;
trend = 0;
end;

{ update trend variable and place trading orders }
if trend = 0 then begin
if ((close-LC) / LC) >= (perOffLo / 100) then trend = +1;
if ((HC-close) / HC) >= (perOffHi / 100) then trend = -1;
end
else if trend = +1 and ((HC-close) / HC) >= (perOffHi / 100) then begin
sell short this bar on close;
trend = -1;
LC = close;
end
else if trend = -1 and ((close-LC) / LC) >= (perOffLo / 100) then begin
buy this bar on close;
trend = +1;
HC = close;
end;

{ update LC & HC variables }
if close < LC then LC = close;
if close > HC then HC = close;


jalexander
Posts: 9
Joined: 17 Mar 2014
Has thanked: 3 times

Re: Zweig's Four Percent Model in EasyLanguage?

Postby jalexander » 18 Mar 2014

wow, can't ask for more than that. Thanks

jalexander
Posts: 9
Joined: 17 Mar 2014
Has thanked: 3 times

Re: Zweig's Four Percent Model in EasyLanguage?

Postby jalexander » 18 Mar 2014

Super, because I'm new to EasyLanguage I am trying to understand all your code. I have a few questions if you wouldn't mind.

1. Am I right in thinking this code misses the first buy or sell signal.

Code: Select all

if trend = 0 then begin
if ((close-LC) / LC) >= (perOffLo / 100) then trend = +1;
if ((HC-close) / HC) >= (perOffHi / 100) then trend = -1;
end
i.e. should there not be a buy or sell order placed here?

As I read it, the script waits for this up or down trend signal and THEN looks for the first trade... i.e. if the initial trend is up on a chart the first signal will be a sell?

2.

Code: Select all

else if trend = +1 and ((HC-close) / HC) >= (perOffHi / 100) then begin
sell short this bar on close;
trend = -1;
[b]LC = close; [/b]
end
On the above block, I don't understand why you have the line highlighted in bold.

Thanks!

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Zweig's Four Percent Model in EasyLanguage?

Postby SUPER » 19 Mar 2014

Super, because I'm new to EasyLanguage I am trying to understand all your code. I have a few questions if you wouldn't mind.

1. Am I right in thinking this code misses the first buy or sell signal.

Code: Select all

if trend = 0 then begin
if ((close-LC) / LC) >= (perOffLo / 100) then trend = +1;
if ((HC-close) / HC) >= (perOffHi / 100) then trend = -1;
end
i.e. should there not be a buy or sell order placed here?

As I read it, the script waits for this up or down trend signal and THEN looks for the first trade... i.e. if the initial trend is up on a chart the first signal will be a sell?

2.

Code: Select all

else if trend = +1 and ((HC-close) / HC) >= (perOffHi / 100) then begin
sell short this bar on close;
trend = -1;
[b]LC = close; [/b]
end
On the above block, I don't understand why you have the line highlighted in bold.

Thanks!
1. Yes your assumption is correct.

2. I have not highlighted any thing at all-I don't see it that way on my screen.

jalexander
Posts: 9
Joined: 17 Mar 2014
Has thanked: 3 times

Re: Zweig's Four Percent Model in EasyLanguage?

Postby jalexander » 19 Mar 2014

2. Sorry I meant this bit which I tried to highlight in bold:

Code: Select all

LC = close;

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Zweig's Four Percent Model in EasyLanguage?

Postby SUPER » 20 Mar 2014

2. Sorry I meant this bit which I tried to highlight in bold:

Code: Select all

LC = close;
to track high and low points


Return to “MultiCharts”