function Init() indicator:name("NonLagMA indicator"); indicator:description("NonLagMA indicator"); indicator:requiredSource(core.Bar); indicator:type(core.Indicator); indicator.parameters:addGroup("Calculation"); indicator.parameters:addInteger("Length", "Length", "Length", 9); indicator.parameters:addInteger("Filter", "Filter", "Filter", 0); indicator.parameters:addDouble("Deviation", "Deviation", "Deviation", 0); indicator.parameters:addGroup("Style"); indicator.parameters:addColor("clrUP", "UP color", "UP color", core.rgb(0, 0, 255)); indicator.parameters:addColor("clrDN", "DN color", "DN color", core.rgb(255, 0, 0)); indicator.parameters:addInteger("widthLinReg", "Line width", "Line width", 1, 1, 5); indicator.parameters:addInteger("styleLinReg", "Line style", "Line style", core.LINE_SOLID); indicator.parameters:setFlag("styleLinReg", core.FLAG_LINE_STYLE); indicator.parameters:addInteger("Period", "Period", "Period", 0); indicator.parameters:addColor("color", "Label Color", "Color of Label", core.rgb(255, 0, 0)); indicator.parameters:addInteger("Size", "Font Size", "Size", 15); end local first; local source = nil; local Length; local Filter; local Deviation; local buffUP=nil; local buffDN=nil; local trend; local buff; local Coeff; local Phase; local Len; local One; local count; local Period; local total; local Size; function Prepare() source = instance.source; Length=instance.parameters.Length; Filter=instance.parameters.Filter; Deviation=instance.parameters.Deviation; trend = instance:addInternalStream(0, 0); buff = instance:addInternalStream(0, 0); Size=instance.parameters.Size; first = source:first()+2; Period=instance.parameters.Period; count = instance:addInternalStream(0, 0); total=instance:addInternalStream(0,0); instance:ownerDrawn(true); local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Length .. ", " .. instance.parameters.Filter .. ", " .. instance.parameters.Deviation .. ")"; instance:name(name); One = instance:addStream("Single", core.Line, name .. ".One", "One", instance.parameters.clrUP, first); One:setWidth(instance.parameters.widthLinReg); One:setStyle(instance.parameters.styleLinReg); Coeff=3.*math.pi; Phase=Length-1; Len=Length*4.+Phase; end function Update(period, mode) if (period0. then buff[period]=(1.+Deviation/100.)*Sum/Weight; end if Filter>0. then if math.abs(buff[period]-buff[period-1])Filter*source:pipSize() then trend[period]=1; end if buff[period-1]-buff[period]>Filter*source:pipSize() then trend[period]=-1; end if trend[period]>0 then One[period]=buff[period]; One:setColor(period, instance.parameters.clrUP); if trend[period]<0 then One[period]=buff[period]; One:setColor(period, instance.parameters.clrUP); end end if trend[period]<0 then One[period]=buff[period]; One:setColor(period, instance.parameters.clrDN); if trend[period]>0 then One[period]=buff[period]; One:setColor(period, instance.parameters.clrDN); end end total[period]=0; count[period]=0; if (period=source.open[period-59] and One[period-59]> One[period-60] and One[period-60]<= One[period-61] then count[period]=count[period]+1; total[period]=total[period]+1; elseif One[period-59]> One[period-60] and One[period-60]<= One[period-61] then total[period]=total[period]+1; end if source.close[period]<=source.open[period-59] and One[period-59]= One[period-61] then count[period]=count[period]+1; total[period]=total[period]+1; elseif One[period-59]< One[period-60] and One[period-60]>= One[period-61] then total[period]=total[period]+1; end end local init=false; function Draw(stage, context) if stage == 0 then if not init then context:createFont (1, "Arial", Size, Size, 0) init = true; end text1="Number of profitable Trades : " .. tostring(count[source:size()-1]); text2="Number of Trades : " .. tostring(total[source:size()-1]); width1, height1 = context:measureText (1, text1, 0); width2, height2 = context:measureText (1, text2, 0); local MAX= math.max(width1,width2); context:drawText (1, text1, instance.parameters.color, -1, context:right ()-MAX, context:top (), context:right (), context:top ()+ height1, context.LEFT); context:drawText (1, text2, instance.parameters.color, -1, context:right ()-MAX, context:top ()+height1, context:right (), context:top () +height1*2, context.LEFT); end end