
2bnnp

Info
Username: | 2bnnp |
Name: | 2bnnp |
Member since: | 12 Feb 2019 |
About
Signature
Last Algorithm Comments
@ATR Trailing Stop for Manual Traders: 24 Oct 2020, 21:29
Closes on touch, it adjusts the stop.
@Pivot Points: 09 Jun 2020, 16:30
https://ctrader.com/algos/indicators/show/2245 fixed the weekly pivots
Last Forum Posts
@MTF indicator only showing correct value in matching timeframe: 11 May 2020, 11:46
yes thanks. just after thinking about it like you explained it actually does make more sense. heres the code i changed for anyone else wondering:
var index5 = SeriesTimeFrameOne.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
if (index5 != -1)
{
if (_hullFastTimeFrameOne.Result[index5] < _hullFastTimeFrameOne.Result[index5 - 1])
{
FastTimeFrameOneDown[index - 1] = 5;
FastTimeFrameOneDown[index] = 5;
FastTimeFrameOneUp[index] = double.NaN;
}
else if (_hullFastTimeFrameOne.Result[index5] > _hullFastTimeFrameOne.Result[index5 - 1])
{
FastTimeFrameOneUp[index - 1] = 5;
FastTimeFrameOneUp[index] = 5;
FastTimeFrameOneDown[index] = double.NaN;
}
}
@MTF indicator only showing correct value in matching timeframe: 10 May 2020, 17:07
I am trying to create an indicator which will check for other the hull slope of other timeframes and print them like on the screenshot below. The output is correct if the chart timeframe matches with the selected timeframe in the indicator.
If i choose another timeframe, it either shows nothing or just a green line.
here is the code i am currently working on:
using System;
using System.Configuration;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Indicators
{
[Indicator(AccessRights = AccessRights.None)]
public class HullTrendMtf : Indicator
{
[Parameter("Timeframe #1", DefaultValue = "Hour")]
public TimeFrame TimeFrameOne { get; set; }
[Parameter("Timeframe #2", DefaultValue = "Hour4")]
public TimeFrame TimeFrameTwo { get; set; }
[Parameter("Timeframe #3", DefaultValue = "Daily")]
public TimeFrame TimeFrameThree { get; set; }
[Parameter("HULL #1 Period", DefaultValue = 21)]
public int HullPeriodFast { get; set; }
[Parameter("HULL #2 Period", DefaultValue = 55)]
public int HullPeriodSlow { get; set; }
#region outputs
//outputs up
[Output("Hull #1 Tf #1 Up", Color = Colors.Lime, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullOneTfOneUp { get; set; }
[Output("Hull #1 Tf #2 Up", Color = Colors.Lime, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullOneTfTwoUp { get; set; }
[Output("Hull #1 Tf #3 Up", Color = Colors.Lime, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullOneTfThreeUp { get; set; }
[Output("Hull #2 Tf #1 Up", Color = Colors.Lime, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullTwoTfOneUp { get; set; }
[Output("Hull #2 Tf #2 Up", Color = Colors.Lime, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullTwoTfTwoUp { get; set; }
[Output("Hull #2 Tf #3 Up", Color = Colors.Lime, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullTwoTfThreeUp { get; set; }
//outputs down
[Output("Hull #1 Tf #1 Down", Color = Colors.Red, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullOneTfOneDown { get; set; }
[Output("Hull #1 Tf #2 Down", Color = Colors.Red, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullOneTfTwoDown { get; set; }
[Output("Hull #1 Tf #3 Down", Color = Colors.Red, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullOneTfThreeDown { get; set; }
[Output("Hull #2 Tf #1 Down", Color = Colors.Red, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullTwoTfOneDown { get; set; }
[Output("Hull #2 Tf #2 Down", Color = Colors.Red, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullTwoTfTwoDown { get; set; }
[Output("Hull #2 Tf #3 Down", Color = Colors.Red, Thickness = 5, PlotType = PlotType.DiscontinuousLine)]
public IndicatorDataSeries HullTwoTfThreeDown { get; set; }
#endregion outputs
private HullMovingAverage _hullFastTimeFrameOne;
private HullMovingAverage _hullFastTimeFrameTwo;
private HullMovingAverage _hullFastTimeFrameThree;
private HullMovingAverage _hullSlowTimeFrameOne;
private HullMovingAverage _hullSlowTimeFrameTwo;
private HullMovingAverage _hullSlowTimeFrameThree;
private Bars SeriesTimeFrameOne;
private Bars SeriesTimeFrameTwo;
private Bars SeriesTimeFrameThree;
private IndicatorDataSeries series5;
protected override void Initialize()
{
series5 = CreateDataSeries();
SeriesTimeFrameOne = MarketData.GetBars(TimeFrameOne);
SeriesTimeFrameTwo = MarketData.GetBars(TimeFrameTwo);
SeriesTimeFrameThree = MarketData.GetBars(TimeFrameThree);
_hullFastTimeFrameOne = Indicators.GetIndicator<HullMovingAverage>(SeriesTimeFrameOne.ClosePrices, HullPeriodFast);
_hullFastTimeFrameTwo = Indicators.GetIndicator<HullMovingAverage>(SeriesTimeFrameTwo.ClosePrices, HullPeriodFast);
_hullFastTimeFrameThree = Indicators.GetIndicator<HullMovingAverage>(SeriesTimeFrameThree.ClosePrices, HullPeriodFast);
_hullSlowTimeFrameOne = Indicators.GetIndicator<HullMovingAverage>(SeriesTimeFrameOne.ClosePrices, HullPeriodSlow);
_hullSlowTimeFrameTwo = Indicators.GetIndicator<HullMovingAverage>(SeriesTimeFrameTwo.ClosePrices, HullPeriodSlow);
_hullSlowTimeFrameThree = Indicators.GetIndicator<HullMovingAverage>(SeriesTimeFrameThree.ClosePrices, HullPeriodSlow);
}
public override void Calculate(int index)
{
var index5 = GetIndexByDate(SeriesTimeFrameOne, Bars.OpenTimes[index]);
if (index5 != -1)
{
series5[index] = 5;
if (_hullFastTimeFrameOne.Result.IsFalling())
{
HullOneTfOneDown[index - 1] = series5[index5];
HullOneTfOneDown[index] = series5[index5];
HullOneTfOneUp[index] = double.NaN;
}
else if (_hullFastTimeFrameOne.Result.IsRising())
{
HullOneTfOneUp[index - 1] = series5[index5];
HullOneTfOneUp[index] = series5[index5];
HullOneTfOneDown[index] = double.NaN;
}
}
}
private int GetIndexByDate(Bars series, DateTime time)
{
for (int i = series.ClosePrices.Count - 1; i > 0; i--)
{
if (time == series.OpenTimes[i])
return i;
}
return -1;
}
}
}
@Pivot slow loading: 16 Apr 2019, 20:22
Most people wont be able to help you because 1.) its almost 4000 lines of code, 2.) its converted from mql, which in most cases is not a good solution
@Troubleshooting a cBot for trading the WMA price Crosses: 13 Apr 2019, 20:54
if (_wma.Result.LastValue.HasCrossedAbove(close,0))
is wrong, it needs to be
if (_wma.Result.HasCrossedAbove(close,0))
@Troubleshooting a cBot for trading the WMA price Crosses: 13 Apr 2019, 13:49
Line 49:
private WeightedMovingAverage wma { get; set; }
I would recommend using a underscore as prefix for private variables (_wma)
Theres also a typo in line 61/25 and 143.
And well line 109/121, you need to tell the wma what variable it should check for if it crossed above, in your case the close.
private void ManagePositions() { double close = MarketSeries.Close.LastValue; if (wma.Result.HasCrossedAbove(close,0)) { // if there is no buy position open, open one and close any sell position that is open if (!IsPositionOpenByType(TradeType.Buy)) { OpenPosition(TradeType.Buy); } ClosePosition(TradeType.Sell); } // if a sell position is already open and signal is buy do nothing if (wma.Result.HasCrossedBelow(close,0)) { // if there is no sell position open, open one and close any buy position that is open if (!IsPositionOpenByType(TradeType.Sell)) { OpenPosition(TradeType.Sell); } ClosePosition(TradeType.Buy); } }
@Defining Maximum Spread: 12 Apr 2019, 19:43
[Parameter("Max. spread in Pip", DefaultValue = 2, MinValue = 0, Step = 0.1)] public double MaxSpread { get; set; } #region spread logic /// <summary> /// returns true if spread is smaller than max spread /// </summary> /// <returns></returns> bool Spread() { double spread = Symbol.Spread; double size = Symbol.PipSize; double maxSpreadPip = MaxSpread * size; if (spread < maxSpreadPip) { return true; } else { return false; } } #endregion
add this in the main class, you can then use it like so:
protected override void OnBar() { if (TimeWindow() && Spread()) { ManagePositions(); } }