2 timeframes in one indicator
Created at 03 Mar 2016, 00:28
2 timeframes in one indicator
03 Mar 2016, 00:28
Hi,
I want to have indicator based on daily and intraday bars. For example...if daily bar (T-1) is larger in range than bar before (T-2) and has lower High and lower Low than bar before, then on Intraday bars day (T+0) after bar which met condition on each timeframe I choose I should see markings. But those markings appear seems randomly...it should appear on each intraday bar after daily condition is met, but that is not the case.
using System; using cAlgo.API; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true, AccessRights = AccessRights.None)] public class promises : Indicator { public override void Calculate(int index) { var daily = MarketData.GetSeries(TimeFrame.Daily); double daily_range1 = Math.Abs(daily.High[index - 1] - daily.Low[index - 1]); double daily_range2 = Math.Abs(daily.High[index - 2] - daily.Low[index - 2]); { if (daily_range1 > daily_range2 && daily.High[index - 1] < daily.High[index - 2] && daily.Low[index - 1] < daily.Low[index - 2]) ChartObjects.DrawText(index.ToString(), "X", index - 1, MarketSeries.High[index], VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Red); } } } }
Replies
cyfer
04 Mar 2016, 16:41
public override void Calculate(int index) { var daily = MarketData.GetSeries(TimeFrame.Daily); var indexDaily = daily.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue); double daily_range1 = Math.Abs(daily.High[index - 1] - daily.Low[index - 1]); double daily_range2 = Math.Abs(daily.High[index - 2] - daily.Low[index - 2]); if (daily_range1 > daily_range2 && daily.High[indexDaily - 1] < daily.High[indexDaily - 2] && daily.Low[indexDaily - 1] < daily.Low[indexDaily - 2]) ChartObjects.DrawText(index.ToString(), "X", index - 1, MarketSeries.High[index], VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Red); }
- Get the Daily Series in Initialize not Calculate
- I also see no good reason to Get the Ranges At Calculate Method, eventually you're comparing the Past 2 days ranges .. so they should be done once
- Index in Calculate method is the Index of the Time Frame you're working on ., so currently you're using the index of that time frame "Just like you use in the draw Method"
@cyfer
Spotware
04 Mar 2016, 12:04
Dear Trader,
We would like to inform you that we do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You can contact one of our Partners or post a job in Development Jobs section for further coding assistance.
@Spotware