-- Id: 1288 -- More information about this indicator can be found at: -- http://fxcodebase.com/ --+------------------------------------------------------------------+ --| Copyright © 2019, Gehtsoft USA LLC | --| http://fxcodebase.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 | --+------------------------------------------------------------------+ function Init() strategy:name("Stochastic Divergence"); strategy:setTag("NonOptimizableParameters", "Email,SendEmail,SoundFile,RecurrentSound,PlaySound,ShowAlert"); strategy:description("Signals when the Stochastic Divergence detected"); strategy.parameters:addInteger("K", "K", "Parameter of stochastic", 5); strategy.parameters:addInteger("SD", "SD", "Parameter of stochastic", 3); strategy.parameters:addInteger("D", "D", "Parameter of stochastic", 3); strategy.parameters:addString("Period", "Time frame", "", "m1"); strategy.parameters:setFlag("Period", core.FLAG_PERIODS); strategy.parameters:addBoolean("ShowAlert", "Show Alert", "", true); strategy.parameters:addBoolean("PlaySound", "Play Sound", "", false); strategy.parameters:addFile("SoundFile", "Sound file", "", ""); end local SoundFile; local gSource = nil; -- the source stream function Prepare() ShowAlert = instance.parameters.ShowAlert; if instance.parameters.PlaySound then SoundFile = instance.parameters.SoundFile; else SoundFile = nil; end assert(not(PlaySound) or (PlaySound and SoundFile ~= ""), "Sound file must be specified"); ExtSetupSignal(profile:id() .. ":", ShowAlert); assert(instance.parameters.Period ~= "t1", "Can't be applied on ticks!"); gSource = ExtSubscribe(1, nil, instance.parameters.Period, true, "bar"); local name = profile:id() .. "(" .. instance.bid:instrument() .. "(" .. instance.parameters.Period .. ")" .. "," .. instance.parameters.K .. "," .. instance.parameters.SD .. "," .. instance.parameters.D .. ")"; instance:name(name); end local Stochastic = nil; -- when tick source is updated function ExtUpdate(id, source, period) if Stochastic == nil then assert(core.indicators:findIndicator("STOCHASTIC_DIVERGENCE") ~= nil, "STOCHASTIC_DIVERGENCE" .. " indicator must be installed"); Stochastic = core.indicators:create("STOCHASTIC_DIVERGENCE", gSource, instance.parameters.K,instance.parameters.SD,instance.parameters.D, false); end Stochastic:update(core.UpdateLast); if period <= instance.parameters.K + 10 then return ; end local v; if Stochastic:getStream(1):hasData(period - 2) then v = Stochastic:getStream(1)[period - 2]; if v ~= 0 then ExtSignal(gSource, period, "Bearish", SoundFile); end end if Stochastic:getStream(2):hasData(period - 2) then v = Stochastic:getStream(2)[period - 2]; if v ~= 0 then ExtSignal(gSource, period, "Bullish", SoundFile); end end end dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");