|
|
 |

09-23-2009, 05:55 PM
|
|
Member
|
|
Join Date: Oct 2008
Posts: 474
|
|
|
Example: Gator
Here is a source code for the GATOR oscillator as it is described at Gator Oscillator by Bill Williams | Forex Indicators Guide.
1) Create the file gator.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 gator.lua file created at the previous steps
IMPORTANT NOTE At the moment of indicator writing (Sep, 23 2009), the indicator core library has an error which prevents the gator indicator from working well. Please, download the fixed core here and replace indicore2 file with this file in the ""C:\Program Files\Candleworks\FXTS2\" and/or "C:\Program Files\Candleworks\FXOrder2Go\" folders, in case your version is earlier than Sep, 23 2009.
Code:
-- initializes the indicator
function Init()
indicator:name("Gator");
indicator:description("")
indicator:requiredSource(core.Tick);
indicator:type(core.Oscillator);
indicator.parameters:addInteger("JawN", "Number of periods for smoothing the alligator jaw", "", 13, 2, 1000);
indicator.parameters:addInteger("JawS", "Number of periods for shifting the alligator jaw", "", 8, 1, 100);
indicator.parameters:addInteger("TeethN", "Number of periods for smoothing the alligator teeth", "", 8, 2, 1000);
indicator.parameters:addInteger("TeethS", "Number of periods for shifting the alligator teeth", "", 5, 1, 100);
indicator.parameters:addInteger("LipsN", "Number of periods for smoothing the alligator lips", "", 5, 2, 1000);
indicator.parameters:addInteger("LipsS", "Number of periods for shifting the alligator lips", "", 3, 1, 100);
indicator.parameters:addString("MTH", "Alligator Smoothing method", "", "MVA");
indicator.parameters:addStringAlternative("MTH", "MVA", "", "MVA");
indicator.parameters:addStringAlternative("MTH", "EMA", "", "EMA");
indicator.parameters:addStringAlternative("MTH", "LWMA", "", "LWMA");
indicator.parameters:addColor("CL_color", "Color for covering line", "Color for covering line", core.rgb(255, 255, 255));
indicator.parameters:addColor("GO_color", "Color for higher bars", "Color for higher bars", core.rgb(0, 255, 0));
indicator.parameters:addColor("RO_color", "Color for lower bars", "Color for lower bars", core.rgb(255, 0, 0));
end
-- lines parameters
local JawN, JawS;
local TeethN, TeethS;
local LipsN, LipsC;
-- indicator source
local source;
-- alligator lines
local Jaw, Teeth, Lips;
-- alligator lines sources
local JawSrc, TeethSrc, LipsSrc;
-- gator bars
local Up, Down, UpRed, UpGreen, DownRed, DownGreen;
-- bar's parameters
local UpExtent, DownExtent;
local UpFirst, DownFirst;
-- process parameters and prepare for calculations
function Prepare()
JawN = instance.parameters.JawN;
JawS = instance.parameters.JawS;
TeethN = instance.parameters.TeethN;
TeethS = instance.parameters.TeethS;
LipsN = instance.parameters.LipsN;
LipsS = instance.parameters.LipsS;
source = instance.source;
JawSrc = core.indicators:create(instance.parameters.MTH, source, JawN, core.rgb(0, 0, 0));
TeethSrc = core.indicators:create(instance.parameters.MTH, source, TeethN, core.rgb(0, 0, 0));
LipsSrc = core.indicators:create(instance.parameters.MTH, source, LipsN, core.rgb(0, 0, 0));
local name = profile:id() .. "(" .. source:name() .. ", " .. JawN .. "(" .. JawS .. ")," .. TeethN .. "(" .. TeethS .. ")," .. LipsN .. "(" .. LipsS .. "))";
instance:name(name);
Jaw = instance:addInternalStream(JawSrc.DATA:first() + JawS, JawS);
Teeth = instance:addInternalStream(TeethSrc.DATA:first() + TeethS, TeethS);
Lips = instance:addInternalStream(LipsSrc.DATA:first() + LipsS, LipsS);
UpExtent = math.min(JawS, TeethS);
UpFirst = math.max(Jaw:first(), Teeth:first());
Up = instance:addStream("UP", core.Line, name .. ".UP", "UP", instance.parameters.CL_color, UpFirst, UpExtent);
Up:addLevel(0);
UpRed = instance:addStream("UPR", core.Bar, name .. ".UPR", "UPR", instance.parameters.RO_color, UpFirst, UpExtent);
UpGreen = instance:addStream("UPG", core.Bar, name .. ".UPG", "UPG", instance.parameters.GO_color, UpFirst, UpExtent);
DownExtent = math.min(TeethS, LipsS);
DownFirst = math.max(Teeth:first(), Lips:first());
Down = instance:addStream("DOWN", core.Line, name .. ".DN", "DN", instance.parameters.CL_color, DownFirst, DownExtent);
DownRed = instance:addStream("DNR", core.Bar, name .. ".DNR", "DNR", instance.parameters.RO_color, DownFirst, DownExtent);
DownGreen = instance:addStream("DNG", core.Bar, name .. ".DNG", "DNG", instance.parameters.GO_color, DownFirst, DownExtent);
end
-- Indicator calculation routine
function Update(period, mode)
-- calculate alligator
JawSrc:update(mode);
TeethSrc:update(mode);
LipsSrc:update(mode);
if (period + JawS >= 0 and period >= JawSrc.DATA:first()) then
Jaw[period + JawS] = JawSrc.DATA[period];
end
if (period + TeethS >= 0 and period >= TeethSrc.DATA:first()) then
Teeth[period + TeethS] = TeethSrc.DATA[period];
end
if (period + LipsS >= 0 and period >= LipsSrc.DATA:first()) then
Lips[period + LipsS] = LipsSrc.DATA[period];
end
-- calculate gator
if period >= UpFirst then
Up[period + UpExtent] = math.abs(Jaw[period + UpExtent] - Teeth[period + UpExtent]);
if period >= UpFirst + 1 then
if Up[period + UpExtent] >= Up[period + UpExtent - 1] then
UpGreen[period + UpExtent] = Up[period + UpExtent];
else
UpRed[period + UpExtent] = Up[period + UpExtent];
end
end
end
if period >= DownFirst then
Down[period + DownExtent] = -math.abs(Teeth[period + DownExtent] - Lips[period + DownExtent]);
if period >= DownFirst + 1 then
if Down[period + DownExtent] >= Down[period + DownExtent - 1] then
DownGreen[period + DownExtent] = Down[period + DownExtent];
else
DownRed[period + DownExtent] = Down[period + DownExtent];
end
end
end
end
Last edited by Nikolay.Gekht; 09-23-2009 at 05:57 PM..
|

11-01-2009, 11:46 PM
|
|
Registered User
|
|
Join Date: Sep 2009
Posts: 4
|
|
|
I have replaced the "indicore2" file and tried to add it to my chart, but it's not working. It showed "[string "gator.lua"]:97: index out of range". Is there any way to fix it?
|

11-02-2009, 11:24 AM
|
|
Member
|
|
Join Date: Oct 2008
Posts: 474
|
|
|
Could you please ensure that you did not try to "Save As" the indicore2.dll directly to Marketscope's folder when Marketscope is already started? In that case, IE or Mozilla will not be able to replace the file because it is locked and just creates the new file named like indicore2(2).dll.
|
 |
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|