Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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("Tilson T3 Oscillator");
- indicator:description("Tilson T3 Oscillator");
- indicator:requiredSource(core.Tick);
- indicator:type(core.Oscillator);
- indicator.parameters:addInteger("F1", "First T3 Period", "First T3 Period", 4,2,2000);
- indicator.parameters:addInteger("F2", "Second T3 Period", "Second T3 Period", 5,2,2000);
- indicator.parameters:addInteger("N", "Normalize Period", "Normalize Period", 10,0,2000);
- indicator.parameters:addDouble("VF", "Volume Factor", "Volume Factor", 0.7);
- indicator.parameters:addColor("T3O1_color", "Color of Short T3O", "Color of Short T3O", core.rgb(255, 0, 0));
- indicator.parameters:addColor("T3O2_color", "Color of Long T3O", "Color of Long T3O", core.rgb(0, 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 T3Frame1=nil;
- local T3Frame2=nil;
- local NormalizeFrame=nil;
- local T=nil
- local first;
- local source = nil;
- -- Streams block
- local T3O1 = nil;
- local T3O2 = nil;
- local Temp1= nil;
- local Temp2= nil;
- -- Routine
- function Prepare()
- source = instance.source;
- first = source:first();
- T = instance.parameters.VF;
- NormalizeFrame = instance.parameters.N;
- T3Frame1= instance.parameters.F1;
- T3Frame2= instance.parameters.F2;
- Temp2 = instance:addInternalStream(0, 0);
- Temp1 = instance:addInternalStream(0, 0);
- T31 = core.indicators:create("T3", source, T, T3Frame1);
- T32 = core.indicators:create("T3", source, T, T3Frame2);
- local name = profile:id() .. "(" .. source:name() .. ", " .. T3Frame1 .. ", " .. T3Frame2 .. ", " .. NormalizeFrame .. ", " .. T .. ")";
- instance:name(name);
- T3O1 = instance:addStream("T3A", core.Line, name, "T3O Short", instance.parameters.T3O1_color, first);
- T3O2 = instance:addStream("T3B", core.Line, name, "T3O Long", instance.parameters.T3O2_color, first);
- end
- -- Indicator calculation routine
- -- TODO: Add your code for calculation output values
- function Update(period,mode)
- T31:update(mode);
- T32:update(mode);
- if period >= 3*T3Frame1+ NormalizeFrame then
- Normalize1(period,NormalizeFrame);
- T3O1[period] = (Temp1[period]*100+100)/2;
- end
- if period >= 3*T3Frame2+ NormalizeFrame then
- Normalize2(period,NormalizeFrame);
- T3O2[period] = (Temp2[period]*100+100)/2;
- end
- end
- function Normalize1(i, Frame)
- local High,Low;
- local Under;
- if Temp1[i-1] == nil then
- Temp1[i-1] = T31.DATA[i-1];
- end
- High = core.max (T31.DATA, core.range (i-Frame, i));
- Low = core.min (T31.DATA, core.range (i-Frame, i));
- if High - Low ==0 then
- Under = 1 ;
- else
- Under = (High - Low);
- end
- Temp1[i]=0.5*2*((T31.DATA[i]-Low )/ Under - 0.5)+0.5 * Temp1[i-1];
- if Temp1[i] > 0.9999 then
- Temp1[i] = 0.9999;
- end
- if Temp1[i] < -0.9999 then
- Temp1[i] = -0.9999;
- end
- end
- function Normalize2(i, Frame)
- local High,Low;
- local Under;
- if Temp2[i-1] == nil then
- Temp2[i-1] = T32.DATA[i-1];
- end
- High = core.max (T32.DATA, core.range (i-Frame, i));
- Low = core.min (T32.DATA, core.range (i-Frame, i));
- if High - Low ==0 then
- Under = 1 ;
- else
- Under = (High - Low);
- end
- Temp2[i]=0.5*2*((T32.DATA[i]-Low )/ Under - 0.5)+0.5 * Temp2[i-1];
- if Temp2[i] > 0.9999 then
- Temp2[i] = 0.9999;
- end
- if Temp2[i] < -0.9999 then
- Temp2[i] = -0.9999;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement