-- Id: 14409 -- 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() --The strategy profile initialization strategy:name("Trade Monitor"); strategy:setTag("NonOptimizableParameters", "Email,SendEmail,SoundFile,RecurrentSound,PlaySound,ShowAlert"); strategy:description("Sends out an e-mail when: 1. An entry order is placed; 2. An order is opened; 3. An order is closed (partially or fully); 4. An order limit, stop, trailing stop, is modified or set."); strategy.parameters:addGroup("Signal Parameters"); strategy.parameters:addBoolean("ShowAlert", "Show Alert", "", false); strategy.parameters:addBoolean("PlaySound", "Play Sound", "", false); strategy.parameters:addFile("SoundFile", "Sound File", "", ""); strategy.parameters:setFlag("SoundFile", core.FLAG_SOUND); strategy.parameters:addBoolean("Recurrent", "RecurrentSound", "", false); strategy.parameters:addGroup("Email Parameters"); strategy.parameters:addBoolean("SendEmail", "Send email", "", true); strategy.parameters:addString("Email", "Email address", "", ""); strategy.parameters:setFlag("Email", core.FLAG_EMAIL); end -- Signal Parameters local ShowAlert; local SoundFile; local RecurrentSound; local SendEmail, Email; function Prepare() ShowAlert = instance.parameters.ShowAlert; local PlaySound = instance.parameters.PlaySound if PlaySound then SoundFile = instance.parameters.SoundFile; else SoundFile = nil; end assert(not(PlaySound) or SoundFile ~= "", "Sound file must be chosen"); RecurrentSound = instance.parameters.Recurrent; local SendEmail = instance.parameters.SendEmail; if SendEmail then Email = instance.parameters.Email; else Email = nil; end assert(not(SendEmail) or Email ~= "", "Email address must be specified"); local name = profile:id(); instance:name(name); core.host:execute("subscribeTradeEvents", 1001, "orders"); core.host:execute("subscribeTradeEvents", 1002, "trades"); ExtSetupSignal(profile:id() .. ":", ShowAlert); ExtSetupSignalMail(name); end function ExtUpdate(id, source, period) -- The method called every time when a new bid or ask price appears. -- do nothing end -- The strategy instance finalization. function ReleaseInstance() end local one_minute = 60.0 / 86400.0; function ExtAsyncOperationFinished(cookie, successful, message, message1, message2) if cookie == 1001 then if message1 == "W" then local order = core.host:findTable("orders"):find("OrderID", message); if core.host:execute("getServerTime") - order.Time < one_minute then if order.Type == "S" or order.Type == "STE" then ExtSignal(instance.bid, NOW, "The stop order " .. message .. " placed", SoundFile, Email, RecurrentSound); elseif order.Type == "L" or order.Type == "LTE" then ExtSignal(instance.bid, NOW, "The limit order " .. message .. " placed", SoundFile, Email, RecurrentSound); else ExtSignal(instance.bid, NOW, "The entry order " .. message .. " placed", SoundFile, Email, RecurrentSound); end end end elseif cookie == 1002 then position = core.host:findTable("closed trades"):find("TradeID", message); if position ~= nil then if core.host:execute("getServerTime") - position.CloseTime < one_minute then ExtSignal(instance.bid, NOW, "The order " .. position.TradeID .. " closed", SoundFile, Email, RecurrentSound); end else position = core.host:findTable("trades"):find("TradeID", message); if core.host:execute("getServerTime") - position.Time < one_minute then ExtSignal(instance.bid, NOW, "The order " .. message .. " opened", SoundFile, Email, RecurrentSound); end end end end dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");