MarketSeries.Close.LastValue versus MarketSeries.Close.Last(0)
MarketSeries.Close.LastValue versus MarketSeries.Close.Last(0)
12 May 2018, 15:55
Dear Panagiotis,
I'm a bit confused. Could you please tell what exactly the difference is between
MarketSeries.Close.LastValue
and
MarketSeries.Close.Last(0) ?
Regards,
Sasha
Replies
alexander.n.fedorov
14 May 2018, 09:03
Dear Panagiotiis:
This is the piece of code:
protected override void OnStart()
{
Instance = defaultInstance + ", " + Symbol.Code + ", " + Account.BrokerName + ", " + Account.Number.ToString();
BB = Indicators.BollingerBands(Source, periods, deviations, MovingAverageType.Simple);
atr = Indicators.AverageTrueRange(14, MovingAverageType.Simple);
ma = Indicators.MovingAverage(Source, maPeriods, MovingAverageType.Simple);
equity = Account.Equity;
minQuantity = 0.01;
Quantity = minQuantity * Math.Floor(Risk);
volume = Symbol.QuantityToVolumeInUnits(Quantity);
Print("Quantity = {0}, math.floor(Risk)= {1}, volume = {2}", minQuantity, Math.Floor(Risk), volume);
Print("close last bar on start {0} ", MarketSeries.Close.LastValue);
Print("open last bar on start {0} ", MarketSeries.Open.LastValue);
}
protected override void OnBar()
{
tradeManagement();
var position = Positions.Find(Instance);
if (position != null)
{
if (position.TradeType == TradeType.Buy)
{
if (BB.Main.IsFalling())
ClosePosition(position);
}
if (position.TradeType == TradeType.Sell)
{
if (BB.Main.IsRising())
ClosePosition(position);
}
}
if (position == null)
{
Print("Close = {0}, Open = {1}", MarketSeries.Close.Last(0), MarketSeries.Open.Last(0));
Print("close last bar {0} ", MarketSeries.Close.LastValue);
Print("open last bar {0} ", MarketSeries.Open.LastValue);
and this is the backtesting printout:
16/04/2018 00:01:00.000 Backtesting started
16/04/2018 00:01:00.000 Quantity = 0.01, math.floor(Risk)= 1, volume = 1000
16/04/2018 00:01:00.000 close last bar on start 1.23292
16/04/2018 00:01:00.000 open last bar on start 1.23307
16/04/2018 01:00:00.000 Quantity = 0.02, volume = 2000, equity = 3000
16/04/2018 01:00:00.000 Close = 1.2329, Open = 1.2329
16/04/2018 01:00:00.000 close last bar 1.2329
16/04/2018 01:00:00.000 open last bar 1.2329
My question is why OnStart ()
MarketSeries.Open.Last(0)
and
MarketSeries.close.Last(0)
show different values, but OnBar() - the same?
@alexander.n.fedorov
PanagiotisCharalampous
14 May 2018, 10:00
Hi Sasha,
MarketSeries.Open.Last(0) and MarketSeries.Close.Last(0) show the values of the current bar. When on OnBar() both values will be identical since the bar has just opened. If you want the previous bar's value, use MarketSeries.Open.Last(1) and MarketSeries.Close.Last(1).
Best Regards,
Panagiotis
@PanagiotisCharalampous
alexander.n.fedorov
14 May 2018, 10:02
Thank you Panagiotis, Clear enough as always
Sasha
@alexander.n.fedorov
alexander.n.fedorov
13 May 2018, 12:37
another question is:
I tried to print and what I recevied that
MarketSeries.Close.LastValue=MarketSeries.Open.LastValue.
That is really strange. How then would I know if the last bar is boolish or bearish?
@alexander.n.fedorov