See if this works. I haven't tested it.

- Code: Select all
`-- Indicator profile initialization routine`

-- Defines indicator profile properties and indicator parameters

function Init()

strategy:name("Gravity signal");

strategy:description("Signals when Price hits Gravity Edges");

strategy.parameters:addGroup("Gravity parameters");

strategy.parameters:addInteger("N", "Number of bars", "", 120);

strategy.parameters:addInteger("O", "Order", "", 3);

strategy.parameters:addDouble("E", "Eccart value", "", 1.61803399);

strategy.parameters:addGroup("Price parameters");

strategy.parameters:addString("Period", "Time frame", "", "m1");

strategy.parameters:setFlag("Period", core.FLAG_PERIODS);

strategy.parameters:addGroup("Signal parameters");

strategy.parameters:addBoolean("ShowAlert", "Show Alert", "", true);

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", "", false);

strategy.parameters:addString("Email", "Email address", "", "");

strategy.parameters:setFlag("Email", core.FLAG_EMAIL);

end

-- Streams/Indicators

local gSource, gTick;

local BELCOG;

local name;

-- Parameters

local SoundFile;

local RecurrentSound;

local Email;

local ShowAlert;

local N;

local O;

local E;

-- Variables

-- Init Routine

function Prepare(onlyName)

N = instance.parameters.N;

O = instance.parameters.O;

E = instance.parameters.E;

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");

RecurrentSound = instance.parameters.Recurrent;

local SendEmail = instance.parameters.SendEmail;

if SendEmail then

Email = instance.parameters.Email;

else

Email = nil;

end

assert(not(SendEmail) or (SendEmail and Email ~= ""), "Email address must be specified");

name = profile:id() .. "(" .. instance.bid:instrument() .. "," .. N .. "," .. O .. "," .. E .. ")";

instance:name(name);

if onlyName then

return;

end

assert(instance.parameters.Period ~= "t1", "Can't be applied on ticks!");

gSource = ExtSubscribe(1, nil, instance.parameters.Period, true, "bar");

gTick = ExtSubscribe(2, nil, "t1", true, "close");

BELCOG = core.indicators:create("BELCOG", gSource, N, O, E);

end

-- Process data routine

function ExtUpdate(id, source, period)

-- If ticksource, use bar period

if id == 2 then

period = gSource:size() - 1;

else

return;

end

if period < BELCOG.DATA:first() + 1 then

return;

end

BELCOG:update(core.UpdateLast);

if core.crossesOver(gSource.high, BELCOG.L3, period) then

Signal("Gravity OverBought");

elseif core.crossesUnder(gSource.low, BELCOG.L6, period) then

Signal("Gravity OverSold");

end

end

function Signal(Label)

if ShowAlert then

terminal:alertMessage(instance.bid:instrument(), instance.bid[NOW], Label, instance.bid:date(NOW));

end

if SoundFile ~= nil then

terminal:alertSound(SoundFile, RecurrentSound);

end

if Email ~= nil then

terminal:alertEmail(Email, Label, profile:id() .. "(" .. instance.bid:instrument() .. ")" .. instance.bid[NOW]..", " .. Label..", " .. instance.bid:date(NOW));

end

end

dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");