Mean indicator (closed)

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

Mean indicator (closed)

Postby Alexander.Gettinger » Tue Oct 12, 2010 1:32 am

Note: new version is available here: viewtopic.php?f=17&t=2526

viewtopic.php?f=27&t=2369&p=5104#p5104

Mean.png


Mean.lua
(2.75 KiB) Downloaded 945 times

Mean Calculation.lua
(2.61 KiB) Downloaded 476 times


The indicator was revised and updated
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Mean indicator

Postby hpinvestment » Tue Oct 12, 2010 7:32 am

Hi Alexander

Can you please explain how this indicator works?
hpinvestment
 
Posts: 1
Joined: Tue Oct 12, 2010 7:27 am

Re: Mean indicator

Postby posurf » Wed Oct 13, 2010 2:35 am

Thanks

but is it possible to change the beginning of the time session, especially for the forex.
posurf
 
Posts: 5
Joined: Wed Sep 22, 2010 6:56 am

Re: Mean indicator

Postby maurosg » Fri Oct 15, 2010 2:09 pm

Hi Alexander, thanks for the indicator

Thinking in Market profile, it is possible calculate this indicator whith "the mode" instead of "the mean"?

regards
maurosg
 
Posts: 1
Joined: Fri Oct 15, 2010 1:58 pm

Re: Mean indicator

Postby virgilio » Mon Oct 18, 2010 3:13 pm

Is it possible to have a signal/strategy for this indicator?
thank you.
virgilio
 
Posts: 66
Joined: Mon Aug 23, 2010 12:16 pm

Re: Mean indicator

Postby Apprentice » Mon Oct 18, 2010 3:20 pm

Certainly, but you can specify, when, the conditions when the signal generated signals.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Mean indicator

Postby virgilio » Tue Oct 19, 2010 10:14 am

The goal is to have a strategy that generates buy/sell orders based on the same conditions as of the indicator.
virgilio
 
Posts: 66
Joined: Mon Aug 23, 2010 12:16 pm

Re: Mean indicator

Postby Alexander.Gettinger » Wed Oct 20, 2010 12:43 am

Indicator updated.
Added other time session for calculation MA.

Code: Select all
function Init()
    indicator:name("Mean indicator");
    indicator:description("Mean indicator");
    indicator:requiredSource(core.Tick);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addString("Mode", "Mode", "", "Day");
    indicator.parameters:addStringAlternative("Mode", "M1", "", "M1");
    indicator.parameters:addStringAlternative("Mode", "M5", "", "M5");
    indicator.parameters:addStringAlternative("Mode", "M15", "", "M15");
    indicator.parameters:addStringAlternative("Mode", "H1", "", "H1");
    indicator.parameters:addStringAlternative("Mode", "H2", "", "H2");
    indicator.parameters:addStringAlternative("Mode", "H3", "", "H3");
    indicator.parameters:addStringAlternative("Mode", "H4", "", "H4");
    indicator.parameters:addStringAlternative("Mode", "H6", "", "H6");
    indicator.parameters:addStringAlternative("Mode", "H8", "", "H8");
    indicator.parameters:addStringAlternative("Mode", "Day", "", "Day");
    indicator.parameters:addStringAlternative("Mode", "Month", "", "Month");

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clrUP", "UP Color", "UP Color", core.rgb(0, 255, 0));
    indicator.parameters:addColor("clrDN", "DN Color", "DN Color", core.rgb(255, 0, 0));
    indicator.parameters:addColor("clrPrev", "Prev Color", "Prev Color", core.rgb(0, 0, 255));
    indicator.parameters:addInteger("widthLinReg", "Line width", "Line width", 1, 1, 5);
    indicator.parameters:addInteger("styleLinReg", "Line style", "Line style", core.LINE_SOLID);
    indicator.parameters:setFlag("styleLinReg", core.FLAG_LINE_STYLE);
end

local first;
local source = nil;
local MeanUP=nil;
local MeanDN=nil;
local Buff=nil;
local PrevBuff=nil;
local Mode;

function Prepare()
    source = instance.source;
    Mode=instance.parameters.Mode;
    first = source:first()+2;
    Buff = instance:addInternalStream(first, 0);
    local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Mode .. ")";
    instance:name(name);
    MeanUP = instance:addStream("MeanUP", core.Line, name .. ".UP", "UP", instance.parameters.clrUP, first);
    MeanDN = instance:addStream("MeanDN", core.Line, name .. ".DN", "DN", instance.parameters.clrDN, first);
    PrevBuff = instance:createTextOutput ("Prev", "Prev", "Wingdings", 10, core.H_Center, core.V_Center, instance.parameters.clrPrev, first);
    MeanUP:setWidth(instance.parameters.widthLinReg);
    MeanUP:setStyle(instance.parameters.styleLinReg);
    MeanDN:setWidth(instance.parameters.widthLinReg);
    MeanDN:setStyle(instance.parameters.styleLinReg);
end

function Update(period, mode)
   if (period>first) then
      local d1,t1;
      d1,t1=source:date(period);
      local table1=core.dateToTable(d1);
      local CurD;
      if Mode=="M1" then
       CurD=table1.min;
      elseif Mode=="M5" then
       CurD=math.floor((table1.min)/5);
      elseif Mode=="M15" then
       CurD=math.floor((table1.min)/15);
      elseif Mode=="H1" then
       CurD=table1.hour;
      elseif Mode=="H2" then
       CurD=math.floor((table1.hour)/2);
      elseif Mode=="H3" then
       CurD=math.floor((table1.hour)/3);
      elseif Mode=="H4" then
       CurD=math.floor((table1.hour)/4);
      elseif Mode=="H6" then
       CurD=math.floor((table1.hour)/6);
      elseif Mode=="H8" then
       CurD=math.floor((table1.hour)/8);
      elseif Mode=="Day" then
       CurD=table1.day;
      elseif Mode=="Month" then
       CurD=table1.month;
      end
      local shift=period;
      local PrevD=CurD;
      while PrevD==CurD and shift>first do
       local d2,t2;
       d2,t2=source:date(shift);
       local table2=core.dateToTable(d2);
       if Mode=="M1" then
        PrevD=table2.min;
       elseif Mode=="M5" then
        PrevD=math.floor((table2.min)/5);
       elseif Mode=="M15" then
        PrevD=math.floor((table2.min)/15);
       elseif Mode=="H1" then
        PrevD=table2.hour;
       elseif Mode=="H2" then
        PrevD=math.floor((table2.hour)/2);
       elseif Mode=="H3" then
        PrevD=math.floor((table2.hour)/3);
       elseif Mode=="H4" then
        PrevD=math.floor((table2.hour)/4);
       elseif Mode=="H6" then
        PrevD=math.floor((table2.hour)/6);
       elseif Mode=="H8" then
        PrevD=math.floor((table2.hour)/8);
       elseif Mode=="Day" then
        PrevD=table2.day;
       elseif Mode=="Month" then
        PrevD=table2.month;
       end
       shift=shift-1;
      end
      shift=shift+1;
     
      if period>=shift+1 then
       Buff[period]=core.avg(source,core.range(shift+1,period));
       if Buff[period]>Buff[period-1] then
        MeanUP[period]=Buff[period];
        if Buff[period-1]<Buff[period-2] then
         MeanUP[period-1]=Buff[period-1];
        end
       else
        MeanDN[period]=Buff[period];
        if Buff[period-1]>Buff[period-2] then
         MeanDN[period-1]=Buff[period-1];
        end
       end
       if period>shift then
        PrevBuff:set(period, Buff[shift], "\159", "");
       end
      end
   
   end
end
Attachments
Mean.lua
(5.1 KiB) Downloaded 768 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Mean indicator (closed)

Postby Apprentice » Mon Jan 30, 2017 7:03 am

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

Re: Mean indicator (closed)

Postby Apprentice » Wed Jun 28, 2017 8:34 am

The strategy based on this indicator is available here.
viewtopic.php?f=31&t=64850
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Custom Indicators

Who is online

Users browsing this forum: No registered users and 37 guests