Here is a source code for the Bill Williams 5-bar Fractal oscillator as it is described at
Fractals — Technical Indicators, Technical Analysis
1) Create the file fractal.lua
2) Copy the code below into this file
3) Save the file
or
1,2,3) Just right-click on
this link and choose "Save As..." from the menu.
4) Go to "Charts/Chart/Manage Custom Indicators" menu of the Trading Station
5) Click "Load"
6) Choose the fractal.lua file created at the previous steps
Unfortunately, the current version of the Marketscope does not support the labels, so, the fractals
are specified as the red (up) or green (down) bars in the oscillator area.
Code:
function Init()
indicator:name("Fractal");
indicator:description("Bill Williams Fractal oscillator")
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addColor("UpC", "Color of the up fractal", "", core.rgb(255, 0, 0));
indicator.parameters:addColor("DownC", "Color of the down fractal", "", core.rgb(0, 255, 0));
end
local source;
local up, down;
function Prepare()
source = instance.source;
local name = profile:id();
instance:name(name);
up = instance:addStream("Up", core.Bar, name .. ".Up", "Up", instance.parameters.UpC, 4, -2);
up:addLevel(1);
up:addLevel(0);
up:addLevel(-1);
down = instance:addStream("Down", core.Bar, name .. ".Down", "Down", instance.parameters.DownC, 4, -2);
end
function Update(period, mode)
if (period > 6) then
local curr = source.high[period - 2];
if (curr > source.high[period - 4] and curr > source.high[period - 3] and
curr > source.high[period - 1] and curr > source.high[period]) then
up[period - 2] = 1;
else
up[period - 2] = nil;
end
curr = source.low[period - 2];
if (curr < source.low[period - 4] and curr < source.low[period - 3] and
curr < source.low[period - 1] and curr < source.low[period]) then
down[period - 2] = -1;
else
down[period - 2] = nil;
end
end
end