2bnnp's avatar
2bnnp
2bnnp's avatar

Info

Username:2bnnp
Name:2bnnp
Member since: 12 Feb 2019

About

None

Signature

None

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();
            }
        }

@Sort open charts alphabetical:  12 Apr 2019, 15:52


Option/Button to sort open charts alphabetical.

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
by 2bnnp
free  09 Jun 2020
original code https://ctrader.com/algos/indicators/show/45 fixed the weekly pivots not working. can now choose between auto pivot timeframe and fixed pivot timeframe.   Pivot Point is a technical indicator used in technical analysis derived by calculating the numerical average of a particular stock's (or any other financial asset like forex pair or any future contract) high, low and closing prices. On the following day, if the market price trades above the pivot point it is usually considered as a bullish sentiment, whereas if it trades below the pivot point is seen as bearish A pivot point and the associated support and resistance levels are often turning points for the direction of price movement in a market. In an up-trending market, the pivot point and the resistance levels may represent a ceiling level in price above which the uptrend is no longer sustainable and a reversal may occur. In a declining market, a pivot point and the support levels may represent a low price level of stability or a resistance to further decline.It is customary to calculate additional levels of support and resistance, below and above the pivot point, respectively, by subtracting or adding price differentials calculated from previous trading ranges of the market.  
Symbol Exposure
  0
  0
  1354
by 2bnnp
free  30 Apr 2019
Shows: total gain/dd, todays gain/dd, amount at risk, locked profits (SL in Profit), floating pnl, net short/long(0.02 long + 0.02 short = net no position, good when hedging).
Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.
by 2bnnp
paid  02 Dec 2019
This cbot will amend your SL for manually created positions if the comment of the positions matches with the comment parameter with a bot. To not move the SL to early to break even, it will set the SL to the ATR value only after 1) close and open are below the ATR and the ATR Value is below entry price. Managing many positions was never that easy. If there is a demand for a PSAR one i can create one too. This little helper is not free and can be purchased at Gumroad (25€ one time payment). ATR Indicator can be found here: https://ctrader.com/algos/indicators/show/349