-- More information about this indicator can be found at: -- http://fxcodebase.com/code/viewtopic.php?f=28&t=61403 --+------------------------------------------------------------------+ --| Copyright © 2018, Gehtsoft USA LLC | --| http://fxcodebase.com | --+------------------------------------------------------------------+ --| Developed by : Mario Jemic | --| mario.jemic@gmail.com | --+------------------------------------------------------------------+ --| Support our efforts by donating | --| Paypal: https://goo.gl/9Rj74e | --| BitCoin : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF | --| BitCoin Cash: 1BEtS465S3Su438Kc58h2sqvVvHK9Mijtg | --| Ethereum : 0x8C110cD61538fb6d7A2B47858F0c0AaBd663068D | --| LiteCoin : LLU8PSY2vsq7B9kRELLZQcKf5nJQrdeqwD | --+------------------------------------------------------------------+ -- Indicator profile initialization routine -- Defines indicator profile properties and indicator parameters function Init() indicator:name("Two Component Time Price Opportunity Profile Template"); indicator:description(""); indicator:requiredSource(core.Bar); indicator:type(core.Indicator); indicator.parameters:addGroup("Calculation"); indicator.parameters:addInteger("BoxSize", "Size of price box in pips", "", 50); indicator.parameters:addInteger("Period", "Period", "Use -1 to fetch all", -1); indicator.parameters:addString("Method", "Method", "Method" , "Open"); indicator.parameters:addStringAlternative("Method", "Open", "Open" , "Open"); indicator.parameters:addStringAlternative("Method", "Close", "Close" , "Close"); indicator.parameters:addStringAlternative("Method", "Both", "Both" , "Both"); indicator.parameters:addGroup("Style"); indicator.parameters:addInteger("NumberOfPoints", "Number of points", "Number of points to display histogram", 200); indicator.parameters:addDouble("transparency", "Transparency", "Transparency", 50); indicator.parameters:addColor("Open", "Open Color", "", core.rgb(0, 255, 0)); indicator.parameters:addColor("Close", "Close Color", "", core.rgb(255, 0, 0)); end -- Indicator instance initialization routine -- Processes indicator parameters and creates output streams -- Parameters block local BoxSize; local NumberOfPoints; local oTPO = {}; local cTPO = {}; local source = nil; local first; local Open,Close; local Transparency; local Method; local Period; -- Routine function Prepare(nameOnly) local name = profile:id() .. "(" .. instance.source:name() .. ")"; instance:name(name); if (nameOnly) then return; end BoxSize = instance.parameters.BoxSize; Open = instance.parameters.Open; Close = instance.parameters.Close; Method = instance.parameters.Method; Period = instance.parameters.Period; source = instance.source; first = source:first(); source = instance.source; instance:setLabelColor(Open); instance:ownerDrawn(true); oTPO = {}; cTPO = {}; omax = 0; cmax=0; end local init = false; local Last; local omax = 0; local cmax = 0; function Draw (stage, context) if stage ~= 2 then return; end NumberOfPoints = instance.parameters.NumberOfPoints; if not init then init=true; context:createPen (1, 1, 1, Open); context:createSolidBrush (2, Open); context:createPen (3, 1, 1, Close); context:createSolidBrush (4, Close); Transparency= context:convertTransparency (instance.parameters.transparency) end local Box= context:priceWidth (0, BoxSize*source:pipSize()); if Method == "Open" then for k, v in pairs(oTPO) do length = (v / omax) * NumberOfPoints; visible, y1 = context:pointOfPrice (k * source:pipSize()); visible, y2 = context:pointOfPrice (k * source:pipSize()); x1= context:right ()-length; x2= context:right (); context:drawRectangle (-1, 2, x1, y1 , x2, y2-Box,Transparency) end elseif Method == "Close" then for k, v in pairs(cTPO) do length = (v / cmax) * NumberOfPoints; visible, y1 = context:pointOfPrice (k * source:pipSize()); visible, y2 = context:pointOfPrice (k * source:pipSize()); x1= context:right ()-length; x2= context:right (); context:drawRectangle (-1, 4, x1, y1 , x2, y2-Box,Transparency) end else local Start={}; for k, v in pairs(oTPO) do length = (v / omax) * NumberOfPoints; visible, y1 = context:pointOfPrice (k * source:pipSize()); visible, y2 = context:pointOfPrice (k * source:pipSize()); x1= context:right ()-length; x2= context:right (); Start[k]=x1; context:drawRectangle (-1, 2, x1, y1 , x2, y2-Box,Transparency) end for k, v in pairs(cTPO) do length = (v / cmax) * NumberOfPoints; visible, y1 = context:pointOfPrice (k * source:pipSize()); visible, y2 = context:pointOfPrice (k * source:pipSize()); if Start[k]~= nil then x1= Start[k]-length; x2= Start[k]; else x1= context:right ()-length; x2= context:right (); end context:drawRectangle (-1, 4, x1, y1 , x2, y2-Box,Transparency) end end end local Init; -- Indicator calculation routine function Update(period) if source:serial(source:first()) ~= Init then oTPO = {}; cTPO = {}; omax = 0; cmax=0; Init=source:serial(source:first()) ; end if Period == -1 then if period <= source:size()-2 then Calculate(period); Last = source:serial(period); elseif Last ~= source:serial(period-2) and period-2 == source:size()-2 then Last = source:serial(period-2); Calculate(period-2); end elseif Period ~= -1 and period <= source:size()-2 then if period >= source:size()-2 -Period+1 then Calculate(period); Last = source:serial(period); elseif Last ~= source:serial(period-2) and period-2 == source:size()-2 then Last = source:serial(period-2); Calculate(period-2); end end end function Calculate (period) local open; open = source.open[period] / source:pipSize(); open = open - open % BoxSize; local close; close = source.close[period] / source:pipSize(); close = close - close % BoxSize; local v = rawget(oTPO, open); if v == nil then v = 0; end v = v + 1; if v > omax then omax = v; end local v = rawset(oTPO, open, v); local v = rawget(cTPO, close); if v == nil then v = 0; end v = v + 1; if v > cmax then cmax = v; end local v = rawset(cTPO, close, v); end