Go Back   DailyFX Forex Forum | FX Forum

View Single Post
  #7 (permalink)  
Old 08-06-2009, 06:57 AM
pmxgs0 pmxgs0 is offline
Member
 
Join Date: Aug 2009
Posts: 13
pmxgs0 is an unknown quantity at this point
Pivot Out of scale

Quote:
Originally Posted by gidien View Post
Hi reginad,

here is the code for a full automatic PIVOT LEVEL indicator. The only thing you can change is the time, when the pivot levels were calculated.

For explample if parameter Stunden to 6 then the pivot calculate from six a clock yesterday to six a clock today.

The code also includes the FIBO PIVOT Level calculation.

You do not have to think about which timeframe your are use, the indicator check this for you, and set the right parameter.



-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
-- TODO: Add minimal and maximal value of numeric parameters and default color of the streams
function Init()
indicator:name("PIVOT");
indicator:description("PIVOT LINES");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);

indicator.parameters:addInteger("HH", "Stunden", "Stunden", 0,0,24);
indicator.parameters:addColor("R3_color", "R3", "R3", core.rgb(0,0,128));
indicator.parameters:addColor("R2_color", "R2", "R2", core.rgb(0,0,255));
indicator.parameters:addColor("R1_color", "R1", "R1", core.rgb(0,128,255));
indicator.parameters:addColor("S3_color", "S3", "S3", core.rgb(128,0,0));
indicator.parameters:addColor("S2_color", "S2", "S2", core.rgb(255,0,0));
indicator.parameters:addColor("S1_color", "S1", "S1", core.rgb(255,128,128));
indicator.parameters:addColor("PP_color", "PP", "PP", core.rgb(255,255,0));
indicator.parameters:addColor("MIN_color", "LOW PREV", "LOW PREV", core.rgb(255,255,0));
indicator.parameters:addColor("MAX_color", "MAX PREV", "MAX PREV", core.rgb(255,255,0));
indicator.parameters:addColor("CLOSE_color", "CLOSE PREV", "CLOSE PREV", core.rgb(255,255,0));
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- TODO: Refine the first period calculation for each of the output streams.
-- TODO: Calculate all constants, create instances all subsequent indicators and load all required libraries
-- Parameters block

local first;
local source = nil;
local TF = nil;
local N = nil;
local HH = nil;
local MM = nil;
local SS = nil;
local MAX = nil;
local MIN = nil;
-- Streams block
local HIGH = nil;

-- Routine
function Prepare()
HH = instance.parameters.HH;
MM = instance.parameters.MM;
SS = instance.parameters.SS;
TF = instance.parameters.TF;
source = instance.source;


-- CHECK which TIMEFRAME is used
TF = source:barSize();

if TF == "m5" then
N = 304;
end
if TF == "m15" then
N = 104;
end
if TF == "m30" then
N = 52;
end
if TF == "h1" then
N = 26;
end




first = N + source:first();
first_COUNT = source:first();
local name = profile:id() .. "(" .. source:name() .. ")";
instance:name(name);

-- Internal DATE Stream
DATE = instance:addInternalStream (first_COUNT);

-- STREAM OUTPUT
MAX = instance:addStream("MAX", core.Line, name, "MAX", instance.parameters.MAX_color,first+2*N-1);
MIN = instance:addStream("MIN", core.Line, name, "MIN", instance.parameters.MIN_color,first+2*N-1);
CLOSE_P = instance:addStream("CLOSE_P", core.Line, name, "CLOSE_P", instance.parameters.CLOSE_color,first+2*N-1);
R3 = instance:addStream("R3", core.Line, name, "R3", instance.parameters.R3_color,first+2*N-1);
R2 = instance:addStream("R2", core.Line, name, "R2", instance.parameters.R2_color,first+2*N-1);
R1 = instance:addStream("R1", core.Line, name, "R1", instance.parameters.R1_color,first+2*N-1);
S1 = instance:addStream("S1", core.Line, name, "S1", instance.parameters.S1_color,first+2*N-1);
S2 = instance:addStream("S2", core.Line, name, "S2", instance.parameters.S2_color,first+2*N-1);
S3 = instance:addStream("S3", core.Line, name, "S3", instance.parameters.S3_color,first+2*N-1);
PP = instance:addStream("PP", core.Line, name, "PP", instance.parameters.PP_color,first+2*N-1);

end



-- Indicator calculation routine
-- TODO: Add your code for calculation output values
function Update(period)


-- GET DATE of the PERIOD
DATE[period] = source:date(period);
CC = core.dateToTable(DATE[period]);


if period >= first and source:hasData(period)then
if CC.hour == HH and CC.min == 0 and CC.sec == 0 then
MAX[period] = core.max(source.high, core.rangeTo(period,N));
MIN[period] = core.min(source.low, core.rangeTo(period,N));
CLOSE_P[period] = source.close[period];
else
MAX[period] = MAX[period-1];
MIN[period] = MIN[period-1];
CLOSE_P[period] = CLOSE_P[period-1];

end
-- PIVOT LEVEL
PP[period] = (MAX[period]+MIN[period]+CLOSE_P[period]) / 3;
R3[period] = MAX[period] + 2*(PP[period]-MIN[period]);
R2[period] = PP[period] + (MAX[period]-MIN[period]);
R1[period] = 2*PP[period] - MIN[period];
S1[period] = 2*PP[period] - MAX[period];
S2[period] = PP[period] - (MAX[period] - MIN[period]);
S3[period] = MIN[period] - 2*(MAX[period] - PP[period]);
-- PIVOT LEVEL
end


-- FIBONACCI LEVEL
-- PP[period] = ((MAX[period] - MIN[period]) * 0.500) + MIN[period];
-- R3[period] = MAX[period];
-- R2[period] = ((MAX[period] - MIN[period]) * 0.764) + MIN[period];
-- R1[period] = ((MAX[period] - MIN[period]) * 0.618) + MIN[period];
-- S1[period] = ((MAX[period] - MIN[period]) * 0.382) + MIN[period];
-- S2[period] = ((MAX[period] - MIN[period]) * 0.236) + MIN[period];
-- S3[period] = MIN[period];
-- FIBONACCI LEVEL



end
Thanks for providing the indicator.
I loaded the indicator, but I think there is some error in it because the chart scale becomes strange and impossible to read price bars.
Any help would be greatly appreciated.
Attached Thumbnails
fibonacci-pivots-formula-ppscr.jpg  

Reply With Quote
 


Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.

All times are GMT -5. The time now is 06:32 AM.
Copyright ©2009 Daily FX. All Rights Reserved.