--+------------------------------------------------------------------+ --| Copyright © 2016, Gehtsoft USA LLC | --| http://fxcodebase.com | --+------------------------------------------------------------------+ --| Support our efforts by donating | --| Paypal: https://goo.gl/9Rj74e | --| BitCoin : 15VCJTLaz12Amr7adHSBtL9v8XomURo9RF | --+------------------------------------------------------------------+ --| Developed by : Mario Jemic | --| mario.jemic@gmail.com | --+------------------------------------------------------------------+ function Init() strategy:name("MTF MCP Signal Template"); strategy:description("MTF MCP Signal Template"); strategy:setTag("NonOptimizableParameters", "Email,SendEmail,SoundFile,RecurrentSound,PlaySound, ShowAlert"); strategy.parameters:addGroup("Calculation"); strategy.parameters:addString("Type", "Currency pair Selector", "Currency pair Selector" , "All currency pair"); strategy.parameters:addStringAlternative("Type", "Multiple currency pair", "Multiple currency pair" , "Multiple currency pair"); strategy.parameters:addStringAlternative("Type", "All currency pair", "All currency pair" , "All currency pair"); strategy.parameters:addString("Method", "Permitted Trade", "Permitted Trade" , "All"); strategy.parameters:addStringAlternative("Method", "Show All", "Show All" , "All"); strategy.parameters:addStringAlternative("Method", "Show Long Only", "Show Long Only" , "Long"); strategy.parameters:addStringAlternative("Method", "Show Short Only", "Show Long Only" , "Short"); strategy.parameters:addString("Live", "End of Turn / Live", "", "End of Turn"); strategy.parameters:addStringAlternative("Live", "End of Turn", "", "End of Turn"); strategy.parameters:addStringAlternative("Live", "Live", "", "Live"); strategy.parameters:addString("toTime", "Converts to this timezone", "", core.TZ_LOCAL); strategy.parameters:addStringAlternative("toTime", "EST time zone", "", core.TZ_EST); strategy.parameters:addStringAlternative("toTime", "UTC", "Coordinated Universal Time", core.TZ_UTC); strategy.parameters:addStringAlternative("toTime", "The user's local time zone", "", core.TZ_LOCAL); strategy.parameters:addStringAlternative("toTime", "The display time zone", "The time zone chosen to display date and time in the host application", core.TZ_TS); strategy.parameters:addStringAlternative("toTime", "The currently connected server time zone", "The time zone chosen to display date and time in the host application", core.TZ_SERVER); strategy.parameters:addStringAlternative("toTime", "Financial time", "The midnight (0:00:00) is a start of the trading day for the currently connected server", core.TZ_FINANCIAL); for i= 1 ,10, 1 do strategy.parameters:addGroup(i..". Currency Pair "); AddPair(i); end for i= 1 ,13, 1 do strategy.parameters:addGroup(i..". Time Frame "); AddTF(i); end strategy.parameters:addGroup("Signals"); strategy.parameters:addBoolean("ShowAlert", "Show Alert", "", false); strategy.parameters:addBoolean("PlaySound", "Play Sound", "", false); strategy.parameters:addBoolean("RecurrentSound", "Recurrent Sound", "", false); strategy.parameters:addFile("SoundFile", "Sound File", "", ""); strategy.parameters:setFlag("SoundFile", core.FLAG_SOUND); strategy.parameters:addBoolean("SendEmail", "Send Email", "", true); strategy.parameters:addString("Email", "Email", "", ""); strategy.parameters:setFlag("Email", core.FLAG_EMAIL); end function AddTF(id) local Init={"m1", "m5", "m15", "m30", "H1", "H2", "H3", "H4", "H6", "H8", "D1", "W1", "M1" }; if id == 5 or id == 11 then strategy.parameters:addBoolean("TF_ON"..id, "Use This Slot", "", true); else strategy.parameters:addBoolean("TF_ON"..id, "Use This Slot", "", false); end strategy.parameters:addString("TF" .. id, "Pair", "", Init[id]); strategy.parameters:setFlag("TF" .. id, core.FLAG_PERIODS); end function AddPair(id) local Init={"EUR/USD","USD/JPY", "GBP/USD","USD/CHF", "EUR/CHF" , "AUD/USD","USD/CAD", "NZD/USD", "EUR/GBP", "EUR/JPY" , "GBP/JPY", "CHF/JPY","GBP/CHF", "EUR/AUD", "EUR/CAD" , "AUD/CAD", "AUD/JPY","CAD/JPY", "NZD/JPY", "GBP/CAD" }; strategy.parameters:addBoolean("PAIR_ON"..id, "Use This Slot", "", true); strategy.parameters:addString("Pair" .. id, "Pair", "", Init[id]); strategy.parameters:setFlag("Pair" .. id, core.FLAG_INSTRUMENTS); end local Type; local Pair_Count; local Pair={}; local Point={}; local TF_Count={}; local iTF={"m1", "m5", "m15", "m30", "H1", "H2", "H3", "H4", "H6", "H8", "D1", "W1", "M1" }; local TF={}; local Source={}; local Method, Live; local ShowAlert; local SoundFile; local Source1 ,Source2; local Email; local SendEmail; local RecurrentSound; local toTime; local Code={}; function Prepare() Type = instance.parameters.Type; Method = instance.parameters.Method; Live = instance.parameters.Live; toTime= instance.parameters.toTime; ShowAlert = instance.parameters.ShowAlert; if PlaySound then SoundFile = instance.parameters.SoundFile; RecurrentSound = instance.parameters.RecurrentSound; else SoundFile = nil; RecurrentSound = false; end SendEmail = instance.parameters.SendEmail; RecurrentSound = instance.parameters.RecurrentSound; if SendEmail then Email = instance.parameters.Email; else Email = nil; end assert(not(SendEmail) or (SendEmail and Email ~= ""), "Email address must be specified"); assert(not(PlaySound) or (PlaySound and SoundFile ~= " "), "Sound file must be specified"); if Type== "Multiple currency pair" then Pair_Count=0; for i= 1, 20 , 1 do if instance.parameters:getBoolean("PAIR_ON" .. i) then Pair_Count=Pair_Count+1; Pair[Pair_Count]= instance.parameters:getString ("Pair"..i); Point[Pair_Count]= core.host:findTable("offers"):find("Instrument", Pair[Pair_Count]).PointSize; end end elseif Type== "All currency pair" then Pair, Pair_Count,Point = getInstrumentList(); end TF_Count=0; for i = 1 , 13 , 1 do if instance.parameters:getBoolean("TF_ON" .. i) then TF_Count=TF_Count+1; TF[TF_Count]= iTF[i]; end end local name = profile:id() .. "(" .. instance.bid:instrument() .. ")"; instance:name(name); ID=0; for i= 1, Pair_Count,1 do Source[i]={}; for j= 1, TF_Count,1 do ID=ID+1; Code[ID+1000]={}; Code[ID+1000][1]=i; Code[ID+1000][2]=j; Source[i][j] = ExtSubscribe(ID, Pair[i], TF[j], instance.parameters.Type == "Bid", "bar"); end end end function getInstrumentList() local list={}; local count = 0; local row, enum; enum = core.host:findTable("offers"):enumerator(); row = enum:next(); while row ~= nil do count = count + 1; list[count] = row.Instrument; row = enum:next(); end return list, count; end -- when tick source is updated function ExtUpdate(id, source, period) local Signal1,Signal2; i= Code[id][1]; j= Code[id][2]; Signal1,Signal2=Verification(i,j); if Signal1~=Signal2 then if Signal1 == 1 then Signal ("MTF MCP Signal Template", "Long",i,j); end if Signal1 == -1 then Signal ("MTF MCP Signal Template", "Short",i,j); end end end function Verification(i,j) local period= Source[i][j].close:size()-1; if Live~= "Live" then period=period-1; Shift=1; end local Signal1=0; local Signal2=0; if Source[i][j].low[period]<= Source[i][j].low[period-1] and Source[i][j].close[period]>= Source[i][j].low[period-1] and Method ~= "Short" then Signal1 =1; end if Source[i][j].high[period]>= Source[i][j].high[period-1] and Source[i][j].close[period]<= Source[i][j].high[period-1] and Method ~= "Long" then Signal1=-1; end period=period-1; if Source[i][j].low[period]<= Source[i][j].low[period-1] and Source[i][j].close[period]>= Source[i][j].low[period-1] and Method ~= "Short" then Signal2 =1; end if Source[i][j].high[period]>= Source[i][j].high[period-1] and Source[i][j].close[period]<= Source[i][j].high[period-1] and Method ~= "Long" then Signal2=-1; end return Signal1,Signal2; end function checkReady(table) local rc; rc = core.host:execute("isTableFilled", table); return rc; end function Signal (Name, Label, i,j) local period =Source[i][j].close:size()-1; local date = Source[i][j]:date(period); date= core. host:execute ("convertTime", 1, toTime, date) local DATA = core.dateToTable (date); local delim = "\013\010"; local Note= " Alert : " .. Label ; local Symbol= " Instrument : " .. Source[i][j]:instrument() ; local Time = " Date : " .. DATA.month.." / ".. DATA.day .." Time: ".. DATA.hour .." / ".. DATA.min .." / ".. DATA.sec; local TF= " Time Frame : " .. Source[i][j]:barSize(); local text = Note .. delim .. Symbol .. delim .. TF .. delim .. Time; if ShowAlert then terminal:alertMessage( Source[i][j]:instrument(), Source[i][j].close[period], text, instance.bid:date(NOW)); end if SoundFile ~= nil then terminal:alertSound(SoundFile, RecurrentSound); end if Email ~= nil then terminal:alertEmail(Email, Name,text); end end dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");