IsLastBar of Indicator A not return correct value when called by indicator B
IsLastBar of Indicator A not return correct value when called by indicator B
03 Mar 2016, 19:07
Dear cAlgo,
I have a simple Indicator IsLastBar_Ind, in which I check the IsLastBar and then assign a value to Result.
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class IsLastBar_Ind : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } protected override void Initialize() { // Initialize and create nested indicators } public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... if (IsLastBar) { Result[index] = 1; } else { Result[index] = 0; } } } }
When this indicator is called within another Indicator, the Result value is not what I expected. I got nothing printed in the Indicator log.
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; using cAlgo.Indicators; namespace cAlgo { [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class CheckIsLastBar : Indicator { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } [Output("Main")] public IndicatorDataSeries Result { get; set; } private IsLastBar_Ind lastbar; protected override void Initialize() { // Initialize and create nested indicators lastbar = Indicators.GetIndicator<IsLastBar_Ind>(10); } public override void Calculate(int index) { // Calculate value at specified index // Result[index] = ... if (lastbar.Result.Last(0) == 1) { Print("IsLastBar is true"); } } } }
When I use cBot to check IsLastBar_Ind, I got "IsLastBar is true" printed in the cBot log.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Test_IsLastBar : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } private IsLastBar_Ind lastbar; protected override void OnStart() { // Put your initialization logic here lastbar = Indicators.GetIndicator<IsLastBar_Ind>(10); } protected override void OnTick() { // Put your core logic here if (lastbar.Result.Last(0) == 1) { Print("IsLastBar is true"); } } protected override void OnStop() { // Put your deinitialization logic here } } }
Could you let me know why the result is different?
And I have some questions regarding the IsLastBar.
1> Do we have different IsLastBar on different Indicators? Or just one IsLastBar for all Indicators.
2> Do we have Different IsLastBar on different TimeFrame? Or just one IsLastBar for all TimeFrame
Thanks & Regards,
jonny
Spotware
04 Mar 2016, 11:49
Dear Trader,
The IsLastBar method returns true, if Calculate is invoked for the last bar.
In addition, we invite you to have a look at the API Reference section of cTDN.
@Spotware