is there anyone who can check both macd?? I want to use 2 macd 15 and 60 min.

Created at 06 Nov 2022, 23:11
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AL

Alwin123

Joined 28.10.2022

is there anyone who can check both macd?? I want to use 2 macd 15 and 60 min.
06 Nov 2022, 23:11


using System;
using System.Security.Cryptography;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class PullbackStrategy : Robot
    {

        [Parameter("Stop Loss ", Group = "Protect", DefaultValue = 100, MaxValue = 100, MinValue = 5, Step = 0.01)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", Group = "Protect", DefaultValue = 100, MaxValue = 100, MinValue = 3, Step = 0.01)]
        public int TakeProfit { get; set; }

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

        [Parameter("Long Cycle", Group = "First MACD", DefaultValue = 26, MaxValue = 26, MinValue = 26, Step = 1)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", Group = "First MACD", DefaultValue = 12, MaxValue = 12, MinValue = 12, Step = 1)]
        public int ShortCycle { get; set; }

        [Parameter("Signal-line crossover true:if Signal-line crossover false: Zero crossover", Group = "First MACD", DefaultValue = true)]
        public bool IsSignalLineCrossover { get; set; }

        [Parameter("TimeFrame", Group = "Second MACD", DefaultValue = "Hour")]
        public TimeFrame _TimeFrame { get; set; }

        [Parameter("MACD Period", Group = "Second MACD", DefaultValue = 9, MaxValue = 9, MinValue = 9, Step = 1)]
        public int SignalPeriod2 { get; set; }

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

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

        [Parameter("Signal-line crossover true:if Signal-line crossover false: Zero crossover", Group = "Second MACD", DefaultValue = true)]
        public bool IsSignalLineCrossover_2 { get; set; }

        [Parameter("MME Slow", Group = "MA", DefaultValue = 50, MaxValue = 50, MinValue = 50, Step = 0.01)]
        public int MmeSlow { get; set; }

        [Parameter("MME Standart", Group = "MA", DefaultValue = 20, MinValue = 20, MaxValue = 20, Step = 1)]
        public int MmeStandart { get; set; }

        [Parameter("MME Fast", Group = "MA", DefaultValue = 8, MaxValue = 8, MinValue = 8, Step = 1)]
        public int MmeFast { get; set; }

        [Parameter("Source", Group = "RSI")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", Group = "RSI", DefaultValue = 14, MaxValue = 20, MinValue = 12, Step = 1)]
        public int Periods { get; set; }

        [Parameter("Overbold", Group = "RSI", DefaultValue = 70, MaxValue = 90, MinValue = 70, Step = 5)]
        public int Overbold { get; set; }

        [Parameter("Oversold", Group = "RSI", DefaultValue = 30, MaxValue = 30, MinValue = 10, Step = 5)]
        public int Oversold { get; set; }

        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("BackStep", Group = "Pullback", DefaultValue = 5, MinValue = 1, MaxValue = 5, Step = 1)]
        public int Backstep { get; set; }


        public MovingAverage i_MA_slow, i_MA_standart, i_MA_fast;
        public double volumeInUnits;
        public RelativeStrengthIndex rsi;
        public Bars _marketSeries2;
        public MacdCrossOver macd, macd_2;


        protected override void OnStart()

        {
            volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
            i_MA_slow = Indicators.MovingAverage(Bars.ClosePrices, MmeSlow, MovingAverageType.Exponential);
            i_MA_standart = Indicators.MovingAverage(Bars.ClosePrices, MmeStandart, MovingAverageType.Exponential);
            i_MA_fast = Indicators.MovingAverage(Bars.ClosePrices, MmeFast, MovingAverageType.Exponential);
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            _marketSeries2 = MarketData.GetBars(_TimeFrame, Symbol.Name);
            macd = Indicators.MacdCrossOver(LongCycle, ShortCycle, Period);
            macd_2 = Indicators.MacdCrossOver(_marketSeries2.ClosePrices, LongPeriod2, ShortPeriod2, SignalPeriod2);

        }

        protected override void OnBar()
        {

            var MACDLine_2 = macd_2.MACD.Last(1);
            var PrevMACDLine_2 = macd_2.MACD.Last(2);
            var Signal_2 = macd_2.Signal.Last(1);
            var PrevSignal_2 = macd_2.Signal.Last(2);

            var MACDLine = macd.MACD.Last(1);
            var PrevMACDLine = macd.MACD.Last(2);
            var Signal = macd.Signal.Last(1);
            var PrevSignal = macd.Signal.Last(2);


           if (rsi.Result.LastValue > Oversold && rsi.Result.LastValue < Overbold)


            {

                if (IsSignalLineCrossover && IsSignalLineCrossover_2)
                {


                    if (PrevMACDLine < PrevSignal && MACDLine > Signal && PrevMACDLine_2 < PrevSignal_2 && MACDLine_2 > Signal_2)
                    {
                        var position = Positions.Find("PullbackStrategy, RSI, MACD");
                        if (position != null && position.TradeType == TradeType.Sell)
                        {
                            position.Close();
                        }
                  

                        ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                    }

                    if (PrevMACDLine > PrevSignal && MACDLine < Signal && PrevMACDLine_2 > PrevSignal_2 && MACDLine_2 < Signal_2)
                    {
                        var position = Positions.Find("PullbackStrategy");
                        if (position != null && position.TradeType == TradeType.Buy)
                        {
                            position.Close();
                        }
                       
                        ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                    }
                }
                //Zero cross over
                else
                {
                    if (MACDLine > 0 && PrevMACDLine < 0 && MACDLine_2 > 0 && PrevMACDLine_2 < 0)
                    {
                        //up
                        ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                    }
                    else if (MACDLine < 0 && PrevMACDLine > 0 && MACDLine_2 < 0 && PrevMACDLine_2 > 0)
                    {
                        //Down
                        ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                    }
                }
            }
        }

    }
        
    }


        


 


@Alwin123
Replies

PanagiotisChar
07 Nov 2022, 12:38

Hi there,

Can you make your question more specific? What are you trying to do and what is your cBot doing instead? What kind of help do you need exactly?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar

Alwin123
07 Nov 2022, 18:15 ( Updated at: 07 Nov 2022, 18:27 )

RE:

PanagiotisChar said:

Hi there,

Can you make your question more specific? What are you trying to do and what is your cBot doing instead? What kind of help do you need exactly?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 

what i tried to make is that i can use 2 macd to open a position. (this is part of the strategy rules) both macd 1 on the chart 15min and 1 at 1 o'clock and both above the zero line as confirmation.

I got the same result on the backtest twice and I don't think that's possible

 

I think the 2nd macd will not be included in the way I want it

if (IsSignalLineCrossover && IsSignalLineCrossover_2) ?? is dis correct? 

 


@Alwin123

PanagiotisChar
08 Nov 2022, 09:32

Hi there,

I got the same result on the backtest twice and I don't think that's possible

Can you explain what does this mean? What backtests did you run and what did you expect to see?

if (IsSignalLineCrossover && IsSignalLineCrossover_2)

What is this line supposed to do?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us


@PanagiotisChar

Alwin123
08 Nov 2022, 10:52

RE:
I want to use both Macd.
both of which generate above a buy or sell signal.
but in the test they do it separately from each other. but do not work together.
i think either c trader can't handle both macd or i made a mistake in the rule. that I show

PanagiotisChar said:

Hi there,

I got the same result on the backtest twice and I don't think that's possible

Can you explain what does this mean? What backtests did you run and what did you expect to see?

if (IsSignalLineCrossover && IsSignalLineCrossover_2)

What is this line supposed to do?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@Alwin123

Alwin123
08 Nov 2022, 10:52

RE:
I want to use both Macd.
both of which generate above a buy or sell signal.
but in the test they do it separately from each other. but do not work together.
i think either c trader can't handle both macd or i made a mistake in the rule. that I show

PanagiotisChar said:

Hi there,

I got the same result on the backtest twice and I don't think that's possible

Can you explain what does this mean? What backtests did you run and what did you expect to see?

if (IsSignalLineCrossover && IsSignalLineCrossover_2)

What is this line supposed to do?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@Alwin123

Alwin123
08 Nov 2022, 17:43 ( Updated at: 21 Dec 2023, 09:23 )

in trading view i made this. both macd in the same direction above or below the zero line
colors the background. And with it also a buy or sell signal


@Alwin123

Alwin123
08 Nov 2022, 19:54

RE: RE:

Alwin123 said:

 

 

is this the right thing (==) to let both macd make the decision to open a position together

if (IsSignalLineCrossover == IsSignalLineCrossover_2) 

 

I want to use both Macd.
both of which generate above a buy or sell signal.
but in the test they do it separately from each other. but do not work together.
i think either c trader can't handle both macd or i made a mistake in the rule. that I show

PanagiotisChar said:

Hi there,

I got the same result on the backtest twice and I don't think that's possible

Can you explain what does this mean? What backtests did you run and what did you expect to see?

if (IsSignalLineCrossover && IsSignalLineCrossover_2)

What is this line supposed to do?

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 


@Alwin123