Darvas Box

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

Darvas Box

Postby Alexander.Gettinger » Mon Sep 27, 2010 2:43 am

For what is Darvas Box please see:
http://www.investopedia.com/terms/d/darvasboxtheory.asp

Darvas_Box.png


Code: Select all
function Init()
    indicator:name("Darvas Box");
    indicator:description("Darvas Box");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    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));
end

local first;
local source = nil;
local BuffUP=nil;
local BuffDN=nil;
local box_top=0.;
local box_bottom=0.;
local state=1;
local i;

function Prepare()
    source = instance.source;
    first = source:first()+2;
    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    BuffUP = instance:addStream("BuffUP", core.Line, name .. ".UP", "UP", instance.parameters.clrUP, first);
    BuffDN = instance:addStream("BuffDN", core.Line, name .. ".DN", "DN", instance.parameters.clrDN, first);
end

function Update(period, mode)
  if (period>first) then
   box_top=0.;
   box_bottom=0.;
   state=1;
   for i=first,period,1 do
    if state==1 then
     box_top=source.high[i];
    elseif state==2 then
     if box_top<=source.high[i] then
      box_top=source.high[i];
     end
    elseif state==3 then
     if box_top>source.high[i] then
      box_bottom=source.low[i];
     else
      box_top=source.high[i];
     end
    elseif state==4 then
     if box_top>source.high[i] then
      if box_bottom>=source.low[i] then
       box_bottom=source.low[i];
      end
     else
      box_top=source.high[i];
     end
    elseif state==5 then
     if box_top>source.high[i] then
      if box_bottom>=source.low[i] then
       box_bottom=source.low[i];
      end
     else
      box_top=source.high[i];
     end
     state=0;
    end
    BuffUP[i]=box_top;
    BuffDN[i]=box_bottom;
    state=state+1;
   end
  end
end
Attachments
Darvas_Box.lua
(1.86 KiB) Downloaded 1002 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2893
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Darvas Box

Postby armandvon » Mon Sep 27, 2010 4:02 am

Thank you!
armandvon
 
Posts: 6
Joined: Tue Sep 21, 2010 4:02 pm

Re: Darvas Box

Postby Robwin » Mon Dec 12, 2016 5:44 pm

Hello,
Please possible modify for have the true darvas indicator (3 bars) as this ? :
Attachments
True Darvas.png
Robwin
 
Posts: 1
Joined: Mon Dec 12, 2016 5:34 pm

Re: Darvas Box

Postby Apprentice » Fri Dec 16, 2016 5:02 am

Your request is added to the development list, Under Id Number 3696
If someone is interested to do this task, please contact me.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 17357
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Darvas Box

Postby Alexander.Gettinger » Mon Nov 06, 2017 1:28 pm

Robwin wrote:Hello,
Please possible modify for have the true darvas indicator (3 bars) as this ? :


Please, try this version of the indicator.

darvas_box2.PNG


Download:
Darvas_Box2.lua
(4.32 KiB) Downloaded 17 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2893
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk


Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot] and 13 guests