Category Trend  Published on 23/11/2020

MACD PIVOT POINT BOT

Description

Hi,

Today i share my new cbot, not yet live tested but look profitable on backtest with different periods.

Based from Pivot Point cbot found here i added MACD for filter entries.

For exemple on DAX m5 results are pretty good 

But i have a problem, it only open Buy positions....can someone help me to fix thanx guys.

 

 


using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class PivotPointMACD : Robot
    {
        [Parameter("Stop Loss", DefaultValue = 50)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", DefaultValue = 60)]
        public int TakeProfit { get; set; }

        [Parameter(DefaultValue = 1000, MinValue = 0)]
        public int Volume { get; set; }

        [Parameter("Pivot Points Periods (H/L)", DefaultValue = 1, MinValue = 1, Step = 1)]
        public int Periods { get; set; }

        [Parameter("   Resistance (R1, R2, R3, R4)", DefaultValue = 2, MinValue = 1, MaxValue = 4, Step = 1)]
        public int PivotResistance { get; set; }

        [Parameter("   Support (S1, S2, S3, S4)", DefaultValue = 2, MinValue = 1, MaxValue = 4, Step = 1)]
        public int PivotSupport { get; set; }

        [Parameter("Simple Moving Average", DefaultValue = true)]
        public bool Trend { get; set; }

        [Parameter("   SMA Periods", DefaultValue = 7, MinValue = 0, MaxValue = 10000, Step = 1)]
        public int SMAPeriods { get; set; }

        [Parameter("MACD LongCycle", DefaultValue = 26, MinValue = 1)]
        public int LongCycle { get; set; }

        [Parameter("MACD ShortCycle", DefaultValue = 12, MinValue = 1)]
        public int ShortCycle { get; set; }

        [Parameter("MACD Period", DefaultValue = 9, MinValue = 1)]
        public int MACDPeriod { get; set; }



        private const string Label = "Pivot Point";
        private MovingAverage SMATrend;
        private MacdCrossOver _MACD;

        protected override void OnStart()
        {
            Positions.Closed += OnPositionsClosed;
            SMATrend = Indicators.MovingAverage(MarketSeries.Close, SMAPeriods, MovingAverageType.Simple);
            _MACD = Indicators.MacdCrossOver(LongCycle, ShortCycle, MACDPeriod);
        }

        protected override void OnTick()
        {
            var longPosition = Positions.Find(Label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(Label, Symbol, TradeType.Sell);
            //SMA Trend
            var MA1 = SMATrend.Result.Last(1);

            //Pivot Points Levels
            var PivotPoints = MarketData.GetSeries(TimeFrame);

            var closepip = PivotPoints.Close.Last(1);
            var Pricey = (Symbol.Ask + Symbol.Bid) / 2;

            var highest = MarketSeries.High.Last(1);
            var lowest = MarketSeries.Low.Last(1);

            //Pivot Point
            var PP = (highest + lowest + closepip) / 3;

            var highestR = MarketSeries.High.Last(1);
            for (int i = 2; i <= Periods; i++)
            {
                if (MarketSeries.High.Last(i) > highestR)
                    highestR = MarketSeries.High.Last(i);
            }
            Print("highest: ", highestR);

            var lowestR = MarketSeries.Low.Last(1);
            for (int i = 2; i <= Periods; i++)
            {
                if (MarketSeries.Low.Last(i) < lowestR)
                    lowestR = MarketSeries.Low.Last(i);
            }
            Print("lowest: ", lowestR);

            //Pivot Points: Range
            var R4R = 3 * PP + (highestR - 3 * lowestR);
            var R3R = 2 * PP + (highestR - 2 * lowestR);
            var R2R = PP + (highestR - lowestR);
            var R1R = 2 * PP - lowestR;
            var S1R = 2 * PP - highestR;
            var S2R = PP - (highestR - lowestR);
            var S3R = 2 * PP - (2 * highestR - lowestR);
            var S4R = 3 * PP - (3 * highestR - lowestR);

            if ((Trend ? closepip > MA1 : true) && (Pricey < (PivotSupport == 1 ? S1R : (PivotSupport == 2 ? S2R : (PivotSupport == 3 ? S3R : S4R)))) && longPosition == null)
            {
                if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.NormalizeVolume(Volume), Label, StopLoss, TakeProfit);

                    if ((Trend ? closepip < MA1 : true) && (Pricey > (PivotResistance == 1 ? R1R : (PivotResistance == 2 ? R2R : (PivotResistance == 3 ? R3R : R4R)))) && shortPosition == null)
                    {
                        if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)
                        {
                            ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.NormalizeVolume(Volume), Label, StopLoss, TakeProfit);
                        }
                    }
                }
            }
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {

        }
    }
}



MA
makhzen

Joined on 23.11.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Pivot Point MACD.algo
  • Rating: 5
  • Installs: 3444
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
KE
kenneyy_eur · 3 years ago

Replace lines 104 -118 with the lines of code below

if ((Trend ? closepip > MA1 : true) && (Pricey < (PivotSupport == 1 ? S1R : (PivotSupport == 2 ? S2R : (PivotSupport == 3 ? S3R : S4R)))) && longPosition == null)

{

       if (_MACD.MACD.Last(1) < _MACD.Signal.Last(1) && _MACD.MACD.Last(0) > _MACD.Signal.Last(0) && _MACD.Signal.Last(0) < 0)

       {

         ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.NormalizeVolume(Volume), Label, StopLoss, TakeProfit);

        }

}

if ((Trend ? closepip < MA1 : true) && (Pricey > (PivotResistance == 1 ? R1R : (PivotResistance == 2 ? R2R : (PivotResistance == 3 ? R3R : R4R)))) && shortPosition == null)

{

      if (_MACD.MACD.Last(1) > _MACD.Signal.Last(1) && _MACD.MACD.Last(0) < _MACD.Signal.Last(0) && _MACD.Signal.Last(0) > 0)

  {

         ExecuteMarketOrder(TradeType.Sell, Symbol, Symbol.NormalizeVolume(Volume), Label, StopLoss, TakeProfit);

   }

}

diiptrade's avatar
diiptrade · 3 years ago

I can help you. Telegram: @dillidon