FXCM Forex Trading

Fx Sniper's Ergodic CCI Trigger indicator and signal

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

Fx Sniper's Ergodic CCI Trigger indicator and signal

Postby Alexander.Gettinger » Mon Jun 21, 2010 2:05 am

viewtopic.php?f=27&t=1248&p=2370#p2370

Fx_Sniper's_Ergodic_CCI_Trigger.png


Indicator:
Code: Select all
function Init()
    indicator:name("Fx Sniper's Ergodic CCI Trigger");
    indicator:description("Fx Sniper's Ergodic CCI Trigger");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Oscillator);
   
    indicator.parameters:addInteger("pq", "pq", "pq", 4);
    indicator.parameters:addInteger("pr", "pr", "pr", 8);
    indicator.parameters:addInteger("ps", "ps", "ps", 5);
    indicator.parameters:addInteger("trigger", "trigger", "trigger", 4);
    indicator.parameters:addString("MA_Method", "Method of MA", "", "MVA");
    indicator.parameters:addStringAlternative("MA_Method", "EMA", "", "EMA");
    indicator.parameters:addStringAlternative("MA_Method", "KAMA", "", "KAMA");
    indicator.parameters:addStringAlternative("MA_Method", "LWMA", "", "LWMA");
    indicator.parameters:addStringAlternative("MA_Method", "MVA", "", "MVA");
    indicator.parameters:addStringAlternative("MA_Method", "TMA", "", "TMA");
   

    indicator.parameters:addColor("clr1", "Color of Egodic CCI", "Color of Egodic CCI", core.rgb(0, 255, 0));
    indicator.parameters:addColor("clr2", "Color of Trigger Line", "Color of Trigger Line", core.rgb(255, 0, 0));
end

local first;
local source = nil;
local pq;
local pr;
local ps;
local trigger;
local MA_Method;
local var1;
local var2;
local var2a;
local var2b;
local var2c;
local var3;
local var4;
local buff1;
local buff2;

function Prepare()
    source = instance.source;
    pq=instance.parameters.pq;
    pr=instance.parameters.pr;
    ps=instance.parameters.ps;
    trigger=instance.parameters.trigger;
    MA_Method=instance.parameters.MA_Method;
   
    mtm = instance:addInternalStream(0, 0);
    absmtm = instance:addInternalStream(0, 0);
    var1 = core.indicators:create(MA_Method, mtm, pq);
    var2 = core.indicators:create(MA_Method, var1.DATA, pr);
    var2a = core.indicators:create(MA_Method, absmtm, pq);
    var2b = core.indicators:create(MA_Method, var2a.DATA, pr);
    var2c = core.indicators:create(MA_Method, var2.DATA, ps);
    var3 = core.indicators:create(MA_Method, var2b.DATA, ps);
    first = source:first()+2;
    local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.pq .. ", " .. instance.parameters.pr .. ", " .. instance.parameters.ps .. ", " .. instance.parameters.trigger .. ", " .. instance.parameters.MA_Method .. ")";
    instance:name(name);
    buff1 = instance:addStream("buff1", core.Line, name .. ".Egodic CCI", "Egodic CCI", instance.parameters.clr1, first);
    var4 = core.indicators:create(MA_Method, buff1, trigger);
    buff2 = instance:addStream("buff2", core.Line, name .. ".Trigger Line", "Trigger Line", instance.parameters.clr2, first);
end

function Update(period, mode)
    mtm[period]=source.close[period]-source.close[period-1];
    absmtm[period]=math.abs(mtm[period]);
    var1:update(mode);
    var2:update(mode);
    var2a:update(mode);
    var2b:update(mode);
    var2c:update(mode);
    var3:update(mode);
    if (period>first) then
     if var3.DATA[period]~=0 then
      buff1[period]=(500.*var2c.DATA[period])/var3.DATA[period];
      var4:update(mode);
      buff2[period]=var4.DATA[period];
     end
    end
end


Signal oh chart:
Code: Select all
function Init()
    indicator:name("Fx Sniper's Ergodic CCI Trigger on chart");
    indicator:description("Fx Sniper's Ergodic CCI Trigger on chart");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);
   
    indicator.parameters:addInteger("pq", "pq", "pq", 4);
    indicator.parameters:addInteger("pr", "pr", "pr", 8);
    indicator.parameters:addInteger("ps", "ps", "ps", 5);
    indicator.parameters:addInteger("trigger", "trigger", "trigger", 4);
    indicator.parameters:addString("MA_Method", "Method of MA", "", "MVA");
    indicator.parameters:addStringAlternative("MA_Method", "EMA", "", "EMA");
    indicator.parameters:addStringAlternative("MA_Method", "KAMA", "", "KAMA");
    indicator.parameters:addStringAlternative("MA_Method", "LWMA", "", "LWMA");
    indicator.parameters:addStringAlternative("MA_Method", "MVA", "", "MVA");
    indicator.parameters:addStringAlternative("MA_Method", "TMA", "", "TMA");
   

    indicator.parameters:addColor("clr1", "Color of UP", "Color of UP", core.rgb(0, 255, 0));
    indicator.parameters:addColor("clr2", "Color of DN", "Color of DN", core.rgb(255, 0, 0));
end

local first;
local source = nil;
local pq;
local pr;
local ps;
local trigger;
local MA_Method;
local Ind;
local UP;
local DN;

function Prepare()
    source = instance.source;
    pq=instance.parameters.pq;
    pr=instance.parameters.pr;
    ps=instance.parameters.ps;
    trigger=instance.parameters.trigger;
    MA_Method=instance.parameters.MA_Method;
    Ind = core.indicators:create("FX_SNIPER'S_ERGODIC_CCI_TRIGGER", source, pq,pr,ps,trigger,MA_Method);
    first = Ind.DATA:first()+2;
    local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.pq .. ", " .. instance.parameters.pr .. ", " .. instance.parameters.ps .. ", " .. instance.parameters.trigger .. ", " .. instance.parameters.MA_Method .. ")";
    instance:name(name);
    UP = instance:createTextOutput ("Up", "Up", "Wingdings", 10, core.H_Center, core.V_Bottom, instance.parameters.clr1, 0);
    DN = instance:createTextOutput ("Dn", "Dn", "Wingdings", 10, core.H_Center, core.V_Top, instance.parameters.clr2, 0);
end

function Update(period, mode)
    if (period>first) then
     Ind:update(mode);
     if Ind.buff1[period]>Ind.buff2[period] and Ind.buff1[period-1]<=Ind.buff2[period-1] then
      UP:set(period, source.low[period], "\225", "UP");
     end
     if Ind.buff1[period]<Ind.buff2[period] and Ind.buff1[period-1]>=Ind.buff2[period-1] then
      DN:set(period, source.high[period], "\226", "DN");
     end
    end
end
Attachments
Fx_Sniper's_Ergodic_CCI_Trigger.lua
(3.17 KiB) Downloaded 906 times
Fx_Sniper's_Ergodic_CCI_Trigger_On_Chart.lua
(2.57 KiB) Downloaded 853 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 1999
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Fx Sniper's Ergodic CCI Trigger indicator and signal

Postby Alexander.Gettinger » Mon Jun 21, 2010 2:06 am

Signal:
Code: Select all
function Init()
    strategy:name("Fx Sniper's Ergodic CCI Trigger signal");
    strategy:description("");

    strategy.parameters:addGroup("Parameters");

    strategy.parameters:addInteger("pq", "pq", "pq", 4);
    strategy.parameters:addInteger("pr", "pr", "pr", 8);
    strategy.parameters:addInteger("ps", "ps", "ps", 5);
    strategy.parameters:addInteger("trigger", "trigger", "trigger", 4);
    strategy.parameters:addString("MA_Method", "Method of MA", "", "MVA");
    strategy.parameters:addStringAlternative("MA_Method", "EMA", "", "EMA");
    strategy.parameters:addStringAlternative("MA_Method", "KAMA", "", "KAMA");
    strategy.parameters:addStringAlternative("MA_Method", "LWMA", "", "LWMA");
    strategy.parameters:addStringAlternative("MA_Method", "MVA", "", "MVA");
    strategy.parameters:addStringAlternative("MA_Method", "TMA", "", "TMA");

    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 Ind;

function Prepare()
    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("Fx Sniper's Ergodic CCI Trigger 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);

    Ind = core.indicators:create("FX_SNIPER'S_ERGODIC_CCI_TRIGGER", gSourceBid, instance.parameters.pq,instance.parameters.pr,instance.parameters.ps,instance.parameters.trigger,instance.parameters.MA_Method);

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

    local name = profile:id() .. "(" .. instance.bid:instrument() .. "(" .. instance.parameters.Period  .. ")" .. instance.parameters.pq .. ")" .. instance.parameters.pr .. ")" .. instance.parameters.ps .. ")" .. instance.parameters.trigger .. ")" .. instance.parameters.MA_Method .. ")";
    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
    Ind: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() - 1;
        if period > first then
         if Ind.buff1[period]>Ind.buff2[period] and Ind.buff1[period-1]<=Ind.buff2[period-1] and LastDirection~=1 then
                ExtSignal(gSourceAsk, period, "Buy", SoundFile);
                LastDirection=1;
         elseif Ind.buff1[period]<Ind.buff2[period] and Ind.buff1[period-1]>=Ind.buff2[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
Attachments
Fx_Sniper's_Ergodic_CCI_Trigger_Signal.lua
(5 KiB) Downloaded 662 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 1999
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Fx Sniper's Ergodic CCI Trigger indicator and signal

Postby oritzbaba » Fri May 20, 2011 10:12 am

Hi Alexander Gettinger and all the other geniuses out there like Apprentice, Sunshine, Nikolay and others. You are doing a good job helping newbies and novice programmers like me to hopefully succeed.

I have had most of my best trades with Fx Sniper's Ergodic CCI Trigger combined with other indicators. Please to make the FX Sniper strategy work more efficiently, can you add all the other very helpful features like set stop/limit, allowed trading, allowed side etc as contained in the MACROSS_CONF_DIST_STRATEGY.

Please help out, God bless you all.

Thanks.
oritzbaba
 
Posts: 10
Joined: Tue May 10, 2011 3:55 am

Re: Fx Sniper's Ergodic CCI Trigger indicator and signal

Postby Apprentice » Fri May 20, 2011 4:45 pm

Your request has been added to developmental cue.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 8963
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Fx Sniper's Ergodic CCI Trigger indicator and signal

Postby oritzbaba » Sat May 21, 2011 6:50 pm

Thanks Apprentice,

I tried to backtest this strategy and I have some observations; 1. It does not trade all crosses either buy/sell as shown by the signal alert arrows on the chart. 2, It enters a trade order sometimes before the signal alert arrow on the chart and at other times after. 3, In my demo trade, it is yet to take any trade even where there had been different crossing opportunities for the strategy to trade.

Please note both the signal alert on the chart and the strategy settings are the same. please help out, what am I doing wrong? One more thing, does the the strategy remain active on FXCM server when my computer laptop is shot down? I know trailing stop does but is strategy on it?
oritzbaba
 
Posts: 10
Joined: Tue May 10, 2011 3:55 am


Return to Custom Indicators

Who is online

Users browsing this forum: Google [Bot], Jeffreyvnlk and 8 guests