Period Signal

Moderator: admin

Period Signal

Postby iamrich » Tue Aug 03, 2010 9:41 am

I just would like to have a sound after a new period. E.g. EUR/USD m10, after closing a new period a sound. Is that possible? If yes, could someone help me. Thank you.
iamrich
 
Posts: 10
Joined: Tue Aug 03, 2010 9:33 am

Re: Period Signal

Postby Nikolay.Gekht » Mon Aug 09, 2010 10:23 am

Yes. Just use a signal. The thing you want is a signal applied to the bars of the parituclar instrument with no condition, which signals every time.

Code: Select all
function Init()
    strategy:name("Play Sound when new candle appears");
    strategy:description("");

    strategy.parameters:addGroup("Price");
    strategy.parameters:addString("Period", "Time frame", "", "m1");
    strategy.parameters:setFlag("Period", core.FLAG_PERIODS);

    strategy.parameters:addGroup("Alert");
    strategy.parameters:addBoolean("PlaySound", "Play Sound", "", true);
    strategy.parameters:addFile("SoundFile", "Sound file", "", "");
end

local gSource;
local SoundFile;

function Prepare()
    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");

    assert(instance.parameters.Period ~= "t1", "Can't be applied on ticks!");
    gSource = ExtSubscribe(1, nil, instance.parameters.Period, true, "bar");
    local name = profile:id() .. "(" .. gSource:name() .. ")";
    instance:name(name);
end

function ExtUpdate(id, source, period)
    if id == 1 then
        terminal:alertSound(SoundFile, false);
    end
end

dofile(core.app_path() .. "\\strategies\\standard\\include\\helper.lua");
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Period Signal

Postby iamrich » Mon Aug 16, 2010 11:19 am

Thanks a lot. I can't debug it in the Lua Indicator Debugger.
At line stragety:name... i get an error "attempt to index global 'strategy' (a nil value)"

function Init()
strategy:name("PeriodSignal");
strategy:description("Play Sound when new candle appears");

What's wrong?
iamrich
 
Posts: 10
Joined: Tue Aug 03, 2010 9:33 am

Re: Period Signal

Postby Apprentice » Mon Aug 16, 2010 11:54 am

I tested the signal and works perfectly.
NewPeriodSignal.lua
(1.2 KiB) Downloaded 841 times



How to Download and Install a Custom Signal
viewtopic.php?f=29&t=602

To Add signal use Signals - > Menage Signals Screen
(Ensure that you use the appropriate time frame.)
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Period Signal

Postby iamrich » Mon Aug 16, 2010 12:04 pm

You are right. The signal works. However I was wondering if I could also debug a signal. I tried with "Lua Indicator Debugger". But that doesn't work as I wrote before. Is there another debugger for signals?
iamrich
 
Posts: 10
Joined: Tue Aug 03, 2010 9:33 am

Re: Period Signal

Postby Apprentice » Mon Aug 16, 2010 12:08 pm

For this purpose you need to use Lua Strategy Debugger.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Period Signal

Postby iamrich » Mon Aug 16, 2010 12:46 pm

Obviously.
Thanks a lot :D
iamrich
 
Posts: 10
Joined: Tue Aug 03, 2010 9:33 am


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 11 guests