the Gann's idea was that the levels that are located on the main cross and diagonal cross are potential to become major support/resistance levels.. i ahve calculated this numbers in excell for few currencies pairs to test this concept.. and amazingly it does work! my next step was to develop an indicator that would make it easier to follow these numbers once the new high or low is achieved..
i attach my poor attempt to draw those levels on the chart .. now it is drawing all the levels in the square.. i have stumbled while trying to highlight the major levels with different color.. could you help me?
- Code: Select all
function Init()
indicator:name("Gann Square Levels");
indicator:description("Shows Gann Square's levels of support and resistance");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);
indicator:setTag("group", "Support/Resistance");
indicator.parameters:addGroup("Calculation");
indicator.parameters:addString("Calc_Mode", "Calculation Mode", "", "HIGH");
indicator.parameters:addStringAlternative("Calc_Mode", "Highest High", "", "HIGH");
indicator.parameters:addStringAlternative("Calc_Mode", "Lowest Low", "", "LOW");
indicator.parameters:addDouble("High_Low_Price", "High/Low price", "", 0.00001);
indicator.parameters:addInteger("D", "Number of decimal places","",5);
indicator.parameters:addInteger("Step", "Step size (pips)", "", "50");
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("clrLS", "Lines' color", "The color of Gann Square's level lines", core.rgb(0, 0, 0));
indicator.parameters:addInteger("widthLS", "Lines' width", "The width of Gann Square's level lines", 1, 1, 5);
indicator.parameters:addInteger("styleLS", "Lines' style", "The style of Gann Square's level lines", core.LINE_SOLID);
indicator.parameters:setFlag("styleLS", core.FLAG_LINE_STYLE);
indicator.parameters:addColor("clrMajorLS", "Lines' color", "The color of Gann Square's level lines", core.rgb(255, 0, 0));
indicator.parameters:addInteger("widthMajorLS", "Major Lines' width", "The width of Gann Square's major level lines", 1, 1, 5);
indicator.parameters:addInteger("styleMajorLS", "Major Lines' style", "The style of Gann Square's major level lines", core.LINE_SOLID);
indicator.parameters:setFlag("styleMajorLS", core.FLAG_LINE_STYLE);
end
local source;
local ref;
local instr;
local BS;
local BSLen;
local host;
local offset;
local weekoffset;
local stream = {};
local CalcMode;
local O_HIGH = 1;
local O_LOW = 2;
local h_l_Price;
local D;
local pStep;
local colorLS;
local widthLS;
local styleLS;
local widthMajorLS;
local styleMajorLS;
local colorMajorLS;
local majorStr = ",2,3,4,5,6,7,8,9,11,13,15,17,21,";
local LS = {};
local N = 121;
function Prepare()
host = core.host;
offset = host:execute("getTradingDayOffset");
weekoffset = host:execute("getTradingWeekOffset");
source = instance.source;
instr = source:instrument();
BS = instance.parameters.BS;
-- create streams
local sname;
sname = profile:id() .. "(" .. source:name() .. ")";
instance:name(sname);
local j;
colorLS = instance.parameters.clrLS;
widthLS = instance.parameters.widthLS;
styleLS = instance.parameters.styleLS;
colorMajorLS = instance.parameters.clrMajorLS;
widthMajorLS = instance.parameters.widthMajorLS;
styleMajorLS = instance.parameters.styleMajorLS;
h_l_Price = instance.parameters.High_Low_Price;
D = instance.parameters.D;
pStep = instance.parameters.Step;
if instance.parameters.Calc_Mode == "HIGH" then
CalcMode = O_HIGH;
else
CalcMode = O_LOW;
end
for i = 1, N - 1, 1 do
if string.find(tostring(i), majorStr) == nil then
LS[i] = instance:addStream("LS"..i, core.Line, sname .. "." .. "LS" .. i, "LS" .. i, colorLS, 0);
LS[i]:setWidth(widthLS);
LS[i]:setStyle(styleLS);
else
LS[i] = instance:addStream("LS"..i, core.Line, sname .. "." .. "LS" .. i, "LS" .. i, colorMajorLS, 0);
LS[i]:setWidth(widthMajorLS);
LS[i]:setStyle(styleMajorLS);
end;
end
end
function Update(period, mode)
local ds;
local i;
ds = pStep/10^(D-1);
LS[1][period] = h_l_Price;
if CalcMode == O_HIGH then
for i = 2, N - 1, 1 do
LS[i][period] = LS[i-1][period] - ds;
end
else
for i = 2, N - 1, 1 do
LS[i][period] = LS[i-1][period] + ds;
end
end
end