BB_Bands stop Signals [Upd: Jun 06]

The custom signals are published in this forum.

Moderator: admin

BB_Bands stop Signals [Upd: Jun 06]

Postby Alexander.Gettinger » Mon Apr 26, 2010 10:42 pm

Upd Jun 6 2010 by ng: Fixed the problem when the signal checks the incomplete candle when it only appears instead of checking the most recently completed candle. Details are here: viewtopic.php?f=29&t=852#p2376

Please, remove the old version and install the new one.

Signals based on indicator BB_Bands stop: viewtopic.php?f=17&t=757&p=1449. Please, do not forget to download and install indicator too!

BBands_Stop_Signal.jpg


Download:
BBands_Stop_Signal.lua
(4.41 KiB) Downloaded 1816 times


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() + 4;

    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
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: BB_Bands stop Signals

Postby jsi@jp » Tue Jun 01, 2010 12:12 am

Hi, I cannot load this indicator

ADX & MA Signals I can load :D
EMA50 signals I can load :D
BB_Bands stop Signals I cannot load :?:

Please help
jsi@jp
 
Posts: 23
Joined: Mon May 31, 2010 11:39 pm

Re: BB_Bands stop Signals

Postby Nikolay.Gekht » Tue Jun 01, 2010 8:39 am

This is not an indicator. This is a signal. And... Could you please provide a bit more details about "cannot load".
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: BB_Bands stop Signals

Postby jsi@jp » Tue Jun 01, 2010 10:50 pm

Jun 01,2010

I'm sorry.
I cannot speak English.

signal sound of "ADX&MA" "EMA50" rings, but signal sound of "BB_Bands" not rings.

--------------------
Jun 02,2010

I tried once again, the signal sounded.
But it sometimes sound.
It does not sound in many cases.

This may not sound in the place which must sound.

Why does not the signal to all :?:
Please look at the image file.
Attachments
FXCodeBase.png
BB Bands
jsi@jp
 
Posts: 23
Joined: Mon May 31, 2010 11:39 pm

Re: BB_Bands stop Signals

Postby Nikolay.Gekht » Wed Jun 02, 2010 9:36 am

Oh, I see. It looks like this could be Marketscope problem. I reported the problem to the developers to have it the checked carefully. Thank you for the reporting. I'll keep you informed.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: BB_Bands stop Signals

Postby jsi@jp » Thu Jun 03, 2010 6:44 am

Thank you Nikolay :D

>It looks like this could be Marketscope problem.

It is regrettable.

>I reported the problem to the developers to have it the checked carefully. Thank you for the reporting. I'll keep you informed.

Marketscope becomes better, it is good.
jsi@jp
 
Posts: 23
Joined: Mon May 31, 2010 11:39 pm

Re: BB_Bands stop Signals

Postby Nikolay.Gekht » Thu Jun 03, 2010 8:20 am

Alexander, I checked the strategy carefully. Look, the problem is in a bit incorrect implementation of the closed candle checking in the strategy.

First, you detects when another candle is closed:
Code: Select all
if LastBidCandle == nil or
   LastBidCandle ~= gSourceBid:serial(gSourceBid:size() - 1) then

So, all other code works every time when a new candle is started. But then you check a newly started candle, not a completely closed candle, i.e. this code
Code: Select all
period = gSourceBid:size() - 1;

gets index of the newly created candle, not a completed candle, which must be
Code: Select all
period = gSourceBid:size() - 2;

So, in the situation when signal happens not a the first ticks of the new candle - the signal will not happen at all.

There is two way to fix the strategy:
1) Check the completed candle.
or, if you want to provide a signal with no lag
2) Check condition on every tick and signal at the first tick at which the condition is satified.
However, in that case if the candle is closed but the condition disappears - probably we need another signal which shows that condition is not... hm... let's call it "confirmed".

Alexander, could you please fix the strategy?

jsi@jp, thank you very much for reporting the problem. I hope the fix will be provided pretty fast.
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 » Tue Jun 08, 2010 3:01 pm

Up. The signal is updated.
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 jeffjeffz » Thu Jun 10, 2010 2:47 am

Hi Nikolay
Am I doing somthing wrong?

The signal is not giving any notifiactions.

Tested it on 1min, 15mins charts.

Can you check.
jeffjeffz
 
Posts: 3
Joined: Sat May 22, 2010 3:04 pm

Re: BB_Bands stop Signals [Upd: Jun 06]

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

Could you please provide a bit more details on how you apply the signal?

Do you use Signal->Manage signal to apply the signal on the real-time data?
Don't you disable the alert window?

Please see the snapshot below to see how the applied signal should look:
signal.png
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Next

Return to Custom Signals

Who is online

Users browsing this forum: No registered users and 3 guests