Two Moving Average CROS Overlay

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

Two Moving Average CROS Overlay

Postby Apprentice » Tue Oct 12, 2010 11:55 am

TWO_MA_ CROS_Overlay.png


When the shorter moving average is above the long, Candles are Green
And vice versa.
TWO_MA_ CROS_Overlay.lua
(6.28 KiB) Downloaded 1225 times


The indicator was revised and updated
MT4/MQ4 version
viewtopic.php?f=38&t=66150
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 25342
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Two Moving Average CROS Overlay

Postby Jigit Jigit » Sat Feb 04, 2012 5:20 pm

Could you possibly add VAMA to this indicator, please?
Jigit Jigit
 
Posts: 54
Joined: Tue Aug 31, 2010 1:04 pm


Re: Two Moving Average CROS Overlay

Postby Jigit Jigit » Sun Feb 05, 2012 5:35 am

Thanks a million Apprentice. I'll be much obliged.

Also, while you'll be at it, perhaps you could add VAMA option to the existing MA cross signal?

Code: Select all
function Init()
    strategy:name(resources:get("R_Name"));
    strategy:description(resources:get("R_Description"));
    strategy:setTag("group", "Moving Averages");
    strategy:setTag("NonOptimizableParameters", "Email,SendEmail,SoundFile,RecurrentSound,PlaySound,ShowAlert");
    strategy:type(core.Signal);

    strategy.parameters:addGroup(resources:get("R_ParamGroup"));

    strategy.parameters:addInteger("FastN", resources:get("R_FastN"), "", 5);
    strategy.parameters:addInteger("SlowN", resources:get("R_SlowN"), "", 20);

    strategy.parameters:addString("Method", resources:get("R_Smooth"), "", "MVA");
    strategy.parameters:addStringAlternative("Method", "MVA", "", "MVA");
    strategy.parameters:addStringAlternative("Method", "EMA", "", "EMA");
    strategy.parameters:addStringAlternative("Method", "LWMA", "", "LWMA");

    strategy.parameters:addString("Type", resources:get("R_PriceType"), "", "Bid");
    strategy.parameters:addStringAlternative("Type", resources:get("R_Bid"), "", "Bid");
    strategy.parameters:addStringAlternative("Type", resources:get("R_Ask"), "", "Ask");

    strategy.parameters:addString("Period", resources:get("R_PeriodType"), "", "t1");
    strategy.parameters:setFlag("Period", core.FLAG_PERIODS);

    strategy.parameters:addGroup(resources:get("R_SignalGroup"));

    strategy.parameters:addBoolean("ShowAlert", resources:get("R_ShowAlert"), "", true);
    strategy.parameters:addBoolean("PlaySound", resources:get("R_PlaySound"), "", false);
    strategy.parameters:addBoolean("RecurrentSound", resources:get("R_RecurrentSound"), "", false);
    strategy.parameters:addFile("SoundFile", resources:get("R_SoundFile"), "", "");
    strategy.parameters:setFlag("SoundFile", core.FLAG_SOUND);
    strategy.parameters:addBoolean("SendEmail", resources:get("R_SENDEMAIL"), "", false);
    strategy.parameters:addString("Email", resources:get("R_EMAILADDRESS"), resources:get("R_EMAILADDRESSDESCR"), "");
    strategy.parameters:setFlag("Email", core.FLAG_EMAIL);
end

local SoundFile;
local RecurrentSound;
local FastMA, SlowMA;
local BUY, SELL;
local gSource = nil;        -- the source stream
local SendEmail, Email;

function Prepare(onlyName)
    local FastN, SlowN;

    -- collect parameters
    FastN = instance.parameters.FastN;
    SlowN = instance.parameters.SlowN;
   
    --set name
    local name = profile:id() .. "(" .. instance.bid:instrument()  .. "(" .. instance.parameters.Period  .. ")" .. "," .. FastN  .. "," .. SlowN .. ")";
    instance:name(name);
    if onlyName then
        return;
    end

    assert(FastN < SlowN, resources:get("R_MvaParamError"));

    ShowAlert = instance.parameters.ShowAlert;

    local PlaySound = instance.parameters.PlaySound;
    if PlaySound then
        SoundFile = instance.parameters.SoundFile;
        RecurrentSound = instance.parameters.RecurrentSound;
    else
        SoundFile = nil;
        RecurrentSound = false;
    end

    assert(not(PlaySound) or (PlaySound and SoundFile ~= ""), resources:get("R_SoundFileError"));

    SendEmail = instance.parameters.SendEmail;
    if SendEmail then
        Email = instance.parameters.Email;
    else
        Email = nil;
    end
    assert(not(SendEmail) or (SendEmail and Email ~= ""), resources:get("R_EmailAddressError"));

   
    gSource = ExtSubscribe(1, nil, instance.parameters.Period, instance.parameters.Type == "Bid", "close");

    FastMA = core.indicators:create(instance.parameters.Method, gSource, FastN);
    SlowMA = core.indicators:create(instance.parameters.Method, gSource, SlowN);

   
    --localization
    BUY = resources:get("R_BUY")
    SELL = resources:get("R_SELL")
    ExtSetupSignal(resources:get("R_Name") .. ":", ShowAlert);
    ExtSetupSignalMail(name);       
end

-- when tick source is updated
function ExtUpdate(id, source, period)
    -- update moving average
    FastMA:update(core.UpdateLast);
    SlowMA:update(core.UpdateLast);

    if period < 1 or not(SlowMA.DATA:hasData(period - 1)) then
        return ;
    end

   if core.crossesOver(FastMA.DATA, SlowMA.DATA, period) then
        ExtSignal(gSource, period, BUY, SoundFile, Email, RecurrentSound);               
   elseif core.crossesOver(SlowMA.DATA, FastMA.DATA, period) then
        ExtSignal(gSource, period, SELL, SoundFile, Email, RecurrentSound);
   end
end


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

Jigit Jigit
 
Posts: 54
Joined: Tue Aug 31, 2010 1:04 pm

Re: Two Moving Average CROS Overlay

Postby Apprentice » Sun Feb 05, 2012 12:18 pm

VAMA Average Added.

As for MA cross signal This is standard MA cross signal?
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 25342
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Two Moving Average CROS Overlay

Postby Jigit Jigit » Sun Feb 05, 2012 12:56 pm

Hi Apprentice.
Thank you once again.

As for the code I pasted above (MA cross) - I found it in the "standard" folder in you know C:ProgramFiles/FXTS2/Strategies

But I would be happy with any signal alerting me of desired VAMA crossings.

Cheers
Jigit Jigit
 
Posts: 54
Joined: Tue Aug 31, 2010 1:04 pm

Re: Two Moving Average CROS Overlay

Postby Jigit Jigit » Mon Feb 06, 2012 5:42 am

Hello
I'm sorry guys for generating so much traffic around such petty things here...
but could you please add colour selection to the Two Moving Average Cross Overlay (the one with VAMA), i.e. I would like to be able to choose the colour of the indicator overlaying the normal candles.

Thanks a million.
Jigit Jigit
 
Posts: 54
Joined: Tue Aug 31, 2010 1:04 pm


Re: Two Moving Average CROS Overlay

Postby Apprentice » Sun Mar 26, 2017 4:29 pm

Indicator was revised and updated.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 25342
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Two Moving Average CROS Overlay

Postby TrendingEddie » Mon Mar 02, 2020 10:51 am

Hi, Apprentice
I have a issue. Maybe you can help me? I tried to add indicator to the chart, but error appears.
Not sure why?
Attachments
error.JPG
Two Moving Average CROS Overlay ERROR
TrendingEddie
 
Posts: 3
Joined: Wed Sep 19, 2018 11:41 am

Next

Return to Custom Indicators

Who is online

Users browsing this forum: No registered users and 21 guests