Replies

2bnnp
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;
                }
            }

 


@2bnnp

2bnnp
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


@2bnnp

2bnnp
13 Apr 2019, 20:54

if (_wma.Result.LastValue.HasCrossedAbove(close,0))

is wrong, it needs to be

if (_wma.Result.HasCrossedAbove(close,0))

 


@2bnnp

2bnnp
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);
            }
        }

 


@2bnnp

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

 


@2bnnp

2bnnp
28 Mar 2019, 11:12

https://ctrader.com/algos/cbots/show/1872
@2bnnp

2bnnp
24 Mar 2019, 09:40 ( Updated at: 21 Dec 2023, 09:21 )

Sorry missed the part with the custom indicator.

First you need to add a reference for the custom indicator to call it in your bot.

 

Then you can call it with Indicators.GetIndicator<CustomIndicatorHere>(Param1, Param2, Param3)


@2bnnp

2bnnp
24 Mar 2019, 09:34

        [Parameter("Timeframe #1", DefaultValue = "Minute15")]
        public TimeFrame Tf1 { get; set; }

        private StochasticOscillator _stochCTF { get; set; }
        private StochasticOscillator _stochMTF { get; set; }

        protected override void OnStart()
        {
            var timeFrameOne = MarketData.GetSeries(Tf1);

            _stochCTF = Indicators.StochasticOscillator(KPeriods, KSlowing, DPeriods, MovingAverageType.Simple);
            _stochMTF = Indicators.StochasticOscillator(timeFrameOne, KPeriods, KSlowing, DPeriods, MovingAverageType.Simple);

        }

 


@2bnnp