-- More information about this indicator can be found at: -- http://fxcodebase.com/code/viewtopic.php?f=17&t=66641 -- Id: --+------------------------------------------------------------------+ --| 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 | --+------------------------------------------------------------------+ --| Patreon : https://goo.gl/GdXWeN | --| BitCoin : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF | --| BitCoin Cash: 1BEtS465S3Su438Kc58h2sqvVvHK9Mijtg | --| Ethereum : 0x8C110cD61538fb6d7A2B47858F0c0AaBd663068D | --| LiteCoin : LLU8PSY2vsq7B9kRELLZQcKf5nJQrdeqwD | --+------------------------------------------------------------------+ local Number = 2; local Symbols={"\225","\226", "Some Text", "Some Text"}; local Font={"Wingdings", "Wingdings", "Arial", "Arial"}; local Alert_Name={ "Long/Short" ,"Short/Long", "My Alert"}; local Signal_Name={"Cross Over", "Cross Under", "We have a Cross"}; --////////////////////////////////////////////////////////////////////////////// --\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ function Init() indicator:name("Perfect Trend Line"); indicator:description(""); indicator:requiredSource(core.Bar); indicator:type(core.Indicator); indicator.parameters:addGroup("Calculation"); indicator.parameters:addColor("SlowLength", "Slow Length", "Slow Length", 7); indicator.parameters:addDouble("SlowPipDisplace", "Slow Pip Displace", "Slow PipD isplace", 0); indicator.parameters:addColor("FastLength", "Fast Length", "Fast Length", 3); indicator.parameters:addDouble("FastPipDisplace", "Fast Pip Displace", "Fast PipD isplace", 0); indicator.parameters:addGroup("Style"); indicator.parameters:addColor("color1", "1. Line Color", "1. Line Color", core.rgb(0, 255, 0)); indicator.parameters:addInteger("width1", "Line width", "", 1, 1, 5); indicator.parameters:addInteger("style1", "Line style", "", core.LINE_SOLID); indicator.parameters:setFlag("style1", core.FLAG_LINE_STYLE); indicator.parameters:addColor("color2", "2. Line Color", "2. Line Color", core.rgb(255, 0, 0)); indicator.parameters:addInteger("width2", "Line width", "", 1, 1, 5); indicator.parameters:addInteger("style2", "Line style", "", core.LINE_SOLID); indicator.parameters:setFlag("style2", core.FLAG_LINE_STYLE); indicator.parameters:addInteger("Size", "Alert Size", "Alert Size", 20); indicator.parameters:addColor("Up", "Up Alert Color", "Alert Color", core.rgb(0, 255, 0)); indicator.parameters:addColor("Down", "Down Alert Color", "Alert Color", core.rgb(255, 0, 0)); --////////////////////////////////////////////////////////////////////////////// --\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ indicator.parameters:addGroup("Alert Parameters"); indicator.parameters:addString("Signal_Execution", "Signal Execution", "", "End of Turn"); indicator.parameters:addStringAlternative("Signal_Execution", "End of Turn", "", "End of Turn"); indicator.parameters:addStringAlternative("Signal_Execution", "Live", "", "Live"); indicator.parameters:addString("Alert_Execution", "Alert Execution", "", "Live"); indicator.parameters:addStringAlternative("Alert_Execution", "End of Turn", "", "End of Turn"); indicator.parameters:addStringAlternative("Alert_Execution", "Live", "", "Live"); indicator.parameters:addString("Alert_Triger", "Alert Triger", "", "Both"); indicator.parameters:addStringAlternative("Alert_Triger", "Timer", "", "Timer"); indicator.parameters:addStringAlternative("Alert_Triger", "Price", "", "Price"); indicator.parameters:addStringAlternative("Alert_Triger", "Both", "", "Both"); indicator.parameters:addInteger("Timer", "Execution Timer (in seconds)", "", 1, 0, 1000); indicator.parameters:addInteger("ToTime", "Convert the date to", "", 6); indicator.parameters:addIntegerAlternative("ToTime", "EST", "", 1); indicator.parameters:addIntegerAlternative("ToTime", "UTC", "", 2); indicator.parameters:addIntegerAlternative("ToTime", "Local", "", 3); indicator.parameters:addIntegerAlternative("ToTime", "Server", "", 4); indicator.parameters:addIntegerAlternative("ToTime", "Financial", "", 5); indicator.parameters:addIntegerAlternative("ToTime", "Display", "", 6); indicator.parameters:addBoolean("Show", "Show Dialog box Alert", "", true); indicator.parameters:addBoolean("OnlyOnce", "Alert Once", "Subsequent Alert will be ignored.", false); indicator.parameters:addBoolean("ShowAlert", "Show Alert", "", true); --indicator.parameters:addBoolean("Show_Unconfirmed", "Show Unconfirmed Signals", "", false); indicator.parameters:addGroup("Alerts Sound"); indicator.parameters:addBoolean("PlaySound", "Play Sound", "", true); indicator.parameters:addBoolean("RecurrentSound", "Recurrent Sound", "", false); indicator.parameters:addGroup("Alerts Email"); indicator.parameters:addBoolean("SendEmail", "Send Email", "", false); indicator.parameters:addString("Email", "Email", "", ""); indicator.parameters:setFlag("Email", core.FLAG_EMAIL); local Color={}; Color[1]= core.rgb(0, 255, 0); Color[2]= core.rgb(255, 0, 0); for i= 1, Number, 1 do Parameters (i, Alert_Name[i], Signal_Name[i],Color[i]); end --////////////////////////////////////////////////////////////////////////////// --\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ end function Parameters ( id, Label1,Label2,internal_color ) indicator.parameters:addGroup(Label1 .. " Alert"); indicator.parameters:addBoolean("Alert_ON"..id , "Show " .. Label2 .." Alert" , "", true); indicator.parameters:addBoolean("Signal_ON"..id , "Show " .. Label2 .." Signal" , "", true); indicator.parameters:addFile("Sound"..id, Label2 .. " Sound", "", ""); indicator.parameters:setFlag("Sound"..id, core.FLAG_SOUND); indicator.parameters:addString("Alert_Label1"..id, "Alert Label", "", Label1); indicator.parameters:addString("Alert_Label2"..id, "Alert Signal", "", Label2); indicator.parameters:addColor("Color"..id, "Label Color", "",internal_color); indicator.parameters:addInteger("Size"..id, "Label Size", "", 10, 1 , 100); end local Sound={}; local Label1={}; local Label2={}; local Signal_ON={}; local Alert_ON={}; local Email; local SendEmail; local RecurrentSound ,SoundFile ; local Show; local PlaySound; --local Live; --local FIRST=true; local OnlyOnce; local ItIs={}; local Color={}; local Size={}; local OnlyOnceFlag; local ShowAlert; local Alert={}; local AlertLevel={}; local ToTime; local Shift=0; local Timer; --local Show_Unconfirmed; local Signal_Execution, Alert_Execution,Alert_Triger; local Alignment={}; --////////////////////////////////////////////////////////////////////////////// --\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ local first; local source = nil; local trena; local SlowLength, SlowPipDisplace,FastLength, FastPipDisplace; local AlertUp, AlertDown; function Prepare(nameOnly) source = instance.source; SlowLength=instance.parameters.SlowLength; SlowPipDisplace=instance.parameters.SlowPipDisplace; FastLength=instance.parameters.FastLength; FastPipDisplace=instance.parameters.FastPipDisplace; first = source:first(); local name = profile:id() .. "(" .. source:name() .. ")"; instance:name(name); if nameOnly then return; end trena= instance:addInternalStream(0, 0); line1 = instance:addStream("line1", core.Line, "line1", "line1", instance.parameters.color1, first); line1:setWidth(instance.parameters.width1); line1:setStyle(instance.parameters.style1); line2 = instance:addStream("line2", core.Line, "line2", "line2", instance.parameters.color2, first); line2:setWidth(instance.parameters.width2); line2:setStyle(instance.parameters.style2); AlertUp = instance:createTextOutput ("AlertUp", "Alert Up", "Wingdings", instance.parameters.Size, core.H_Center, core.V_Bottom, instance.parameters.Up, 0); AlertDown = instance:createTextOutput ("AlertDown", "Alert Down", "Wingdings", instance.parameters.Size, core.H_Center, core.V_Top, instance.parameters.Down, 0); --////////////////////////////////////////////////////////////////////////////// --\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ Alert_Triger= instance.parameters.Alert_Triger; if Alert_Triger ~= "Timer" then core.host:execute("subscribeTradeEvents", 1, "offers"); end Timer= instance.parameters.Timer Initialization(); instance:ownerDrawn(true); if Alert_Triger ~= "Price" then-- this will work for Timer and Both core.host:execute ("setTimer", 3 , Timer); end end function ReleaseInstance() core.host:execute ("killTimer", 3 ); end function Update(period, mode) if period < source:first() + math.max(SlowLength, FastLength) then return; end AlertUp:setNoData(period); AlertDown:setNoData(period); min1, max1=mathex.minmax(source,period-SlowLength+1, period); min2, max2=mathex.minmax(source,period-FastLength+1, period); local high1 = max1 + SlowPipDisplace*source:pipSize(); local low1 = min1- SlowPipDisplace*source:pipSize(); local high2 = max2+ FastPipDisplace*source:pipSize(); local low2 = min2- FastPipDisplace*source:pipSize(); if source.close[period]>line1[period-1] then line1[period] = low1; else line1[period] = high1; end if source.close[period]>line2[period-1] then line2[period] = low2; else line2[period] = high2; end local trend=0; if (source.close[period]line1[period] and source.close[period]>line2[period]) then trend = -1; end if (line1[period]>line2[period] or trend==1) then trena[period]=1; end if (line1[period]