BB_Bands stop Signals [Upd: Jun 06]

The custom signals are published in this forum.

Moderator: admin

Re: BB_Bands stop Signals [Upd: Jun 06]

Postby Alexander.Gettinger » Sun Jun 20, 2010 9:43 pm

Update signal:
Code: Select all
function Init()
    strategy:name("BBands_Stop signal");
    strategy:description("");

    strategy.parameters:addGroup("Parameters");

    strategy.parameters:addInteger("Length", "Length", "Bollinger Bands Period for BBands_Stop", 20);
    strategy.parameters:addDouble("Deviation", "Deviation", "Deviation for BBands_Stop", 2);
    strategy.parameters:addDouble("MoneyRisk", "MoneyRisk", "Offset Factor for BBands_Stop", 1);

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

    strategy.parameters:addGroup("Signals");
    strategy.parameters:addBoolean("ShowAlert", "Show Alert", "", true);
    strategy.parameters:addBoolean("PlaySound", "Play Sound", "", false);
    strategy.parameters:addFile("SoundFile", "Sound File", "", "");
end

local SoundFile;
local gSourceBid = nil;
local gSourceAsk = nil;
local first;

local BidFinished = false;
local AskFinished = false;
local LastBidCandle = nil;

local EMA50;

function Prepare()
    local FastN, SlowN;

    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");
    assert(instance.parameters.Period ~= "t1", "Signal cannot be applied on ticks");

    ExtSetupSignal("BBands_Stop signal:", ShowAlert);

    gSourceBid = core.host:execute("getHistory", 1, instance.bid:instrument(), instance.parameters.Period, 0, 0, true);
    gSourceAsk = core.host:execute("getHistory", 2, instance.bid:instrument(), instance.parameters.Period, 0, 0, false);

    BBands = core.indicators:create("BBANDS_STOP", gSourceBid, instance.parameters.Length,instance.parameters.Deviation,instance.parameters.MoneyRisk,1,1);

    first = BBands.DATA:first() + 2;

    local name = profile:id() .. "(" .. instance.bid:instrument() .. "(" .. instance.parameters.Period  .. "," .. instance.parameters.Length ..  "," .. instance.parameters.Deviation ..  "," .. instance.parameters.MoneyRisk .. ")";
    instance:name(name);
end

local LastDirection=nil;

-- when tick source is updated
function Update()
    if not(BidFinished) or not(AskFinished) then
        return ;
    end

    local period;

    -- update moving average
    BBands:update(core.UpdateLast);

    -- calculate enter logic
    if LastBidCandle == nil or LastBidCandle ~= gSourceBid:serial(gSourceBid:size() - 1) then
        LastBidCandle = gSourceBid:serial(gSourceBid:size() - 1);

        period = gSourceBid:size() - 2;
        if period > first then
         if BBands.UP_B[period-1]==-1 and BBands.DN_B[period]==-1 and LastDirection~=1 then
                ExtSignal(gSourceAsk, period, "Buy", SoundFile);
                LastDirection=1;
         elseif BBands.DN_B[period-1]==-1 and BBands.UP_B[period]==-1 and LastDirection~=-1 then
                ExtSignal(gSourceBid, period, "Sell", SoundFile);
                LastDirection=-1;
         end   

        end
    end
end

function AsyncOperationFinished(cookie)
    if cookie == 1 then
        BidFinished = true;
    elseif cookie == 2 then
        AskFinished = true;
    end
end

local gSignalBase = "";     -- the base part of the signal message
local gShowAlert = false;   -- the flag indicating whether the text alert must be shown

-- ---------------------------------------------------------
-- Sets the base message for the signal
-- @param base      The base message of the signals
-- ---------------------------------------------------------
function ExtSetupSignal(base, showAlert)
    gSignalBase = base;
    gShowAlert = showAlert;
    return ;
end

-- ---------------------------------------------------------
-- Signals the message
-- @param message   The rest of the message to be added to the signal
-- @param period    The number of the period
-- @param sound     The sound or nil to silent signal
-- ---------------------------------------------------------
function ExtSignal(source, period, message, soundFile)
    if source:isBar() then
        source = source.close;
    end
    if gShowAlert then
        terminal:alertMessage(source:instrument(), source[period], gSignalBase .. message, source:date(period));
    end
    if soundFile ~= nil then
        terminal:alertSound(soundFile, false);
    end
end


Download:
BBands_Stop_Signal.lua
(4.48 KiB) Downloaded 866 times


Please, do not forget to download and install the indicator BBANDS_STOP from here:
viewtopic.php?f=17&t=757
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: BB_Bands stop Signals [Upd: Jun 06]

Postby thejesters1 » Thu Jun 24, 2010 8:06 am

umm can someone enlighten me on how to add a sound alert for this one? cant seem to get it working, btw the signal is working fine. just needed a sound alert.

thanks!
thejesters1
 
Posts: 17
Joined: Thu Jun 17, 2010 12:49 am

Re: BB_Bands stop Signals [Upd: Jun 06]

Postby bchami » Thu Jun 24, 2010 9:19 pm

For some strange reason, i get the error message: [string "BBands_Stop_Signal.lua"]:49: The indicator with the requested id is not found. This happens when i try to apply the signal to a currency pair. Any suggestions as how to fix this problem?
Cheers
bill
bchami
 
Posts: 1
Joined: Thu Jun 24, 2010 9:15 pm

Re: BB_Bands stop Signals [Upd: Jun 06]

Postby Nikolay.Gekht » Fri Jun 25, 2010 11:28 am

Did you install BBANDS_STOP indicator?
viewtopic.php?f=17&t=757
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: BB_Bands stop Signals [Upd: Jun 06]

Postby Nikolay.Gekht » Fri Jun 25, 2010 11:41 am

thejesters1 wrote:umm can someone enlighten me on how to add a sound alert for this one? cant seem to get it working, btw the signal is working fine. just needed a sound alert.
thanks!

Have you tried to switch "Play Sound" parameter to "Yes" and then choose the sound file (any wav file, the default Trading Station set is located here: "C:\Program Files\Candleworks\FXTS2\Sounds\")?
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: BB_Bands stop Signals [Upd: Jun 06]

Postby Merchantprince » Sun Aug 29, 2010 6:09 pm

Is it possible to update this signal to employ the new email alert feature in the latest TS II update?

Thanks!
Merchantprince
 
Posts: 14
Joined: Wed Jul 28, 2010 3:24 pm



Re: BB_Bands stop Signals [Upd: Jun 06]

Postby 4xtr8r » Thu Jun 09, 2011 11:54 am

Strategy has been added to cue?

Do you know how long it will take?

rules:

Enter buy/sell when initial signal is given (long or short).

sell half at +10 (hopefully you can set it up where you can change the amount)...

second half out when signal reverses.

Thank you!
4xtr8r
 
Posts: 29
Joined: Fri Sep 03, 2010 2:19 pm

Re: BB_Bands stop Signals [Upd: Jun 06]

Postby Apprentice » Thu Jun 09, 2011 12:32 pm

To Merchantprince

I wrote a Strategy which is identical to the signal.
It has email functionality.
You can find it here.
viewtopic.php?f=31&t=4672
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 28461
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Previous

Return to Custom Signals

Who is online

Users browsing this forum: No registered users and 3 guests