Candle information

Moderator: admin

Candle information

Postby pesh123 » Mon Mar 06, 2017 6:14 am

Hi,
Am attempting to build a strategy in LUA using the Open/Close/High/Low of the last 3 candles on my chart.
Could someone please provide some sample code/links on how to do this
pesh123
 
Posts: 5
Joined: Mon Mar 06, 2017 6:08 am

Re: Candle information

Postby Apprentice » Mon Mar 06, 2017 6:44 am

U will have something similar.

Current candle
Source.high[period]
Source.low[period]
Source.close[period]
Source.open[period]

Previous candle (Candle 1 periods ago)
Source.high[period-1]
Source.low[period-1]
Source.close[period-1]
Source.open[period-1]

....

Candle N periods ago
Source.high[period-N]
Source.low[period-N]
Source.close[period-N]
Source.open[period-N]
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Candle information

Postby pesh123 » Mon Mar 06, 2017 4:19 pm

Thanks
pesh123
 
Posts: 5
Joined: Mon Mar 06, 2017 6:08 am

Re: Candle information

Postby pesh123 » Mon Mar 06, 2017 6:24 pm

Thanks for the reply,
Am trying that with the below code but am getting an "Index out of range error". Below is an extract of the code
function init()
strategy.parameters:addInteger("Period", "Period", "", 2);
end

function Prepare(onlyName)

Period = instance.parameters.Period;
local Candle = ExtSubscribe(1, nil, "H4", true, "bar");
local CandleOpen=Candle.open[Period-1];
end
pesh123
 
Posts: 5
Joined: Mon Mar 06, 2017 6:08 am

Re: Candle information

Postby Apprentice » Sun Mar 12, 2017 4:41 pm

You will have something like this.

Code: Select all
function Prepare( nameOnly)
    Source = ExtSubscribe(2, nil, TF, instance.parameters.Type == "Bid", "bar"); 
end


function ExtUpdate(id, source, period)  -- The method called every time when a new bid or ask price appears.
   
   if id~= 2 then
   return;
   end   
   
   if period < Source:first() + Period
   then
        return;
       end
   
   local CandleOpenPeriodPeriodsAgo=Candle.open[period-Period+1];
   
end
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 13 guests