Replies

Alwin123
10 Dec 2022, 12:33 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: RE: i have c trader 4.2.22 from de page i.c markets and c trader from the page c trader the versie 4.5.1

Alwin123 said:

it seems that the outstanding item is not included in the version 4.2.22

Alwin123 said:

Alwin123 said:

the number of trades taken etc are the same

how is dit possible?

 

 

 

 

 

 

 

 

 


@Alwin123

Alwin123
10 Dec 2022, 12:30 ( Updated at: 21 Dec 2023, 09:23 )

RE: RE: i have c trader 4.2.22 from de page i.c markets and c trader from the page c trader the versie 4.5.1

Alwin123 said:

Alwin123 said:

the number of trades taken etc are the same

how is dit possible?

 

 

 

 

 

 

 

 


@Alwin123

Alwin123
10 Dec 2022, 12:16 ( Updated at: 21 Dec 2023, 09:23 )

RE: i have c trader 4.2.22 from de page i.c markets and c trader from the page c trader the versie 4.5.1

Alwin123 said:

the number of trades taken etc are the same

how is dit possible?

 

 

 

 

 

 

 


@Alwin123

Alwin123
08 Dec 2022, 17:58

RE: good day, have you already found an answer to your question? I am also looking for the solution for this.

DelFonseca said:

Hi

When he starts the martingale, he doesnt check the strategy. Hitting the stoploss he open a new order without check if strategy = true.

How do I check the strategy again and if there is true, open martingale order?

thank you

 


@Alwin123

Alwin123
26 Nov 2022, 16:32

i found it following my

 if (MACDLine > 0 && PrevMACDLine < 0)
                { 
                     if( MACDLine_2 > 0 && PrevMACDLine_2 < 0)

 


@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

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, 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
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

Alwin123
06 Nov 2022, 23:16

RE:

firemyst said:

Hi there,

Looks like you've made good progress!

This is correct - well done!

_marketSeries2 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);
_marketSeries1 = MarketData.GetBars(TimeFrame.Minute15, Symbol.Name);
macd_1 = Indicators.MacdCrossOver(_marketSeries1.ClosePrices, LongPeriod1, ShortPeriod1, SignalPeriod1);
macd_2 = Indicators.MacdCrossOver(_marketSeries2.ClosePrices, LongPeriod2, ShortPeriod2, SignalPeriod2);

 

If you're unsure that you're getting the values you are expecting, then put Print statements in your code to print out the values and you can compare against having MACD indicators on your charts.

Example Print statement:

Print("MACD1 Value {0}, MACD1 Prev {1}", MACDLine1, PrevMACDLine1);

Hi firemyst can you check this both macd? 

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, RSI, MACD");
                        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

Alwin123
03 Nov 2022, 23:08

I don't have a solution for that Sorry
I don't have a solution for that 

@Alwin123

Alwin123
03 Nov 2022, 23:04 ( Updated at: 21 Dec 2023, 09:23 )

is there anyone who can check both macd?? I want to have a buy position when the macdline is above the signal line and above the zero line


@Alwin123

Alwin123
03 Nov 2022, 22:16 ( Updated at: 03 Nov 2022, 22:17 )

RE: https://ctrader.com/forum/calgo-support/39249 have a look here

v.fiodorov83 said: 

Hello!

I want cBot to trade on the m1 timeframe, but make calculations based on the MacdHistogram indicator with the ability to select a timeframe, for example h1


        private MacdHistogram mcd;
     
        private Bars source;



        protected override void OnStart()

        {
            
            source = MarketData.GetBars(TimeFrame.Hour, SymbolName);

            mcd = Indicators.MacdHistogram(source.ClosePrices,shortCycle, longCycle, signalPeriod);
            
        }

I did it. OK. But then, when trying to use the MASD () data in the OnBar and OnTick methods, he doesn't care, he counts by closing the bar of the current timeframe/tick. Seems I need to create some kind of "dancing with a tambourine" so that he, like, waits until 12 M5 bars are collected, for example, in order to calculate the closing price of an hourly bar?

 


@Alwin123

Alwin123
03 Nov 2022, 13:01

RE: thanks for your feedback

firemyst said:

Hi there,

Looks like you've made good progress!

This is correct - well done!

_marketSeries2 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);
_marketSeries1 = MarketData.GetBars(TimeFrame.Minute15, Symbol.Name);
macd_1 = Indicators.MacdCrossOver(_marketSeries1.ClosePrices, LongPeriod1, ShortPeriod1, SignalPeriod1);
macd_2 = Indicators.MacdCrossOver(_marketSeries2.ClosePrices, LongPeriod2, ShortPeriod2, SignalPeriod2);

 

If you're unsure that you're getting the values you are expecting, then put Print statements in your code to print out the values and you can compare against having MACD indicators on your charts.

Example Print statement:

Print("MACD1 Value {0}, MACD1 Prev {1}", MACDLine1, PrevMACDLine1);

 


@Alwin123

Alwin123
02 Nov 2022, 22:22

is this correct the adjustment in the MACD?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;


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

        [Parameter("Sentiment: Buy", Group = "Sentiment", DefaultValue = true)]
        public bool Buy { get; set; }

        [Parameter("Sentiment: Sell", Group = "Sentiment", DefaultValue = true)]
        public bool Sell { get; set; }

        //[Parameter("First MACD ", Group = "First MACD", DefaultValue = "Minute15")]
       // public TimeFrame macd1 { get; set; }

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

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

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

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

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

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

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

        [Parameter("MME Slow", Group = "MA Type", DefaultValue = 50, MinValue = 45, MaxValue = 220, Step = 1)]
        public int mmeSlow { get; set; }

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

        [Parameter("MME Fast", Group = "MA Type", DefaultValue = 8, MinValue = 4, MaxValue = 20, Step = 1)]
        public int mmeFast { get; set; }
       
       
       [Parameter("Source", Group = "RSI")]
        public DataSeries SourceRSI { get; set; }

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

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

        [Parameter("Stop Loss ", Group = "Risk Managment", DefaultValue = 100)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", Group = "Risk Managment", DefaultValue = 100)]
        public int TakeProfit { get; set; }


        public MovingAverage i_MA_slow;
        public MovingAverage i_MA_standart;
        public MovingAverage i_MA_fast;
        private RelativeStrengthIndex rsi;
        private double volumeInUnits;
        private Position position;
        private Bars _marketSeries2;
        private Bars _marketSeries1;
        private MacdCrossOver macd_1;
        private MacdCrossOver macd_2;


        protected override void OnStart()

        {
           
            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(SourceRSI, PeriodsRSI);
            volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
            Positions.Opened += OnPositionsOpened;
            Positions.Closed += OnPositionsClosed;
            _marketSeries2 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);
            _marketSeries1 = MarketData.GetBars(TimeFrame.Minute15, Symbol.Name);
            macd_1 = Indicators.MacdCrossOver(_marketSeries1.ClosePrices, LongPeriod1, ShortPeriod1, SignalPeriod1);
            macd_2 = Indicators.MacdCrossOver(_marketSeries2.ClosePrices, LongPeriod2, ShortPeriod2, SignalPeriod2);
        }

        void OnPositionsClosed(PositionClosedEventArgs obj)
        {
            position = null;
        }

        void OnPositionsOpened(PositionOpenedEventArgs obj)
        {
            position = obj.Position;
        }
                    
                                  
        [Obsolete]
        protected override void OnBar()
        {
            //First MACD
         
            var MACDLine1  = macd_1.MACD.Last(1);
            var PrevMACDLine1 = macd_1.MACD.Last(2);
            var Signal1  = macd_1.Signal.Last(1);
            var PrevSignal1 = macd_1.Signal.Last(2);

            // both macd must be above the zero line for an entry buy or sell
            // Second MACD
          
            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);

            if (position != null)
                return;
            {
                if (rsi.Result.LastValue > 25 && rsi.Result.LastValue < 70)
                {
                    
                        int index = MarketSeries.Close.Count;

                    if   (MACDLine1 > Signal1 & PrevMACDLine1 <PrevSignal1 & default==Sell 
                        & MACDLine_2 > Signal_2 & PrevMACDLine_2 < PrevSignal_2 & default == Sell
                        & i_MA_fast.Result[index - 2] > MarketSeries.Close[index - 2] 
                        & i_MA_fast.Result[index - 1] < MarketSeries.Close[index - 1])
                     //   & i_MA_fast.Result.LastValue < i_MA_standart.Result.LastValue
                     //   & i_MA_fast.Result.LastValue < i_MA_slow.Result.LastValue
                     //   & i_MA_standart.Result.LastValue < i_MA_slow.Result.LastValue)
               {         
                        
                      ExecuteMarketOrder( TradeType.Buy, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                  }
                        
                        else if (MACDLine1 < Signal1 & PrevMACDLine1 >PrevSignal1 & default== Buy
                        & MACDLine_2 > Signal_2 & PrevMACDLine_2 < PrevSignal_2 & default == Buy
                        & i_MA_fast.Result[index - 2] < MarketSeries.Close[index - 2] 
                        & i_MA_fast.Result[index - 1] > MarketSeries.Close[index - 1])
                      //  & i_MA_fast.Result.LastValue > i_MA_standart.Result.LastValue
                      //  & i_MA_fast.Result.LastValue > i_MA_slow.Result.LastValue
                       // & i_MA_standart.Result.LastValue > i_MA_slow.Result.LastValue)

                        {
                                        
                     ExecuteMarketOrder( TradeType.Sell, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                  
                            }
                }
               

                } 
           
         }
                   
       
           protected override void OnStop()
        {
        }
                  
        }
    }
     


        
   
    
    

 


@Alwin123

Alwin123
02 Nov 2022, 21:24

RE: thanks for your response. I'll try to figure out how this works. your explanation will be perfect. my knowledge of C# is not that far yet.

firemyst said:

Your code isn't going to work, because you're not creating the marketseries variables correctly:

 

_marketSeries2 = MarketData.GetBars(macd2, Symbol.Name);
            _marketSeries1 = MarketData.GetBars(macd1, Symbol.Name);

 

The method is "GetBars", so why are you passing in the macd indicators? The first parameter of the GetBars method is the TIMEFRAME, not an indicator.

 

You are also not creating/initializing the MACD indicator as I showed you in my example -- the first parameter should be the data series, not the long period.

Please go back and reread my example making sure you understand it.

Spotware also has an example on their website which should help:

https://help.ctrader.com/ctrader-automate/indicator-code-samples/#multiple-timeframes

 

 


@Alwin123

Alwin123
31 Oct 2022, 21:36 ( Updated at: 31 Oct 2022, 23:09 )

i have now this can you check this? is this wrong with the both MACD

//both macd must be above the zero line for an entry buy or sell

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;


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

        [Parameter("Sentiment: Buy", Group = "Sentiment", DefaultValue = true)]
        public bool Buy { get; set; }

        [Parameter("Sentiment: Sell", Group = "Sentiment", DefaultValue = true)]
        public bool Sell { get; set; }

        [Parameter("First MACD ", Group = "First MACD", DefaultValue = "Minute15")]
        public TimeFrame macd1 { get; set; }

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

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

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

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

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

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

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

        [Parameter("MME Slow", Group = "MA Type", DefaultValue = 50, MinValue = 45, MaxValue = 220, Step = 1)]
        public int mmeSlow { get; set; }

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

        [Parameter("MME Fast", Group = "MA Type", DefaultValue = 8, MinValue = 4, MaxValue = 20, Step = 1)]
        public int mmeFast { get; set; }
       
       
       [Parameter("Source", Group = "RSI")]
        public DataSeries SourceRSI { get; set; }

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

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

        [Parameter("Stop Loss ", Group = "Risk Managment", DefaultValue = 100)]
        public int StopLoss { get; set; }

        [Parameter("Take Profit", Group = "Risk Managment", DefaultValue = 100)]
        public int TakeProfit { get; set; }


        public MovingAverage i_MA_slow;
        public MovingAverage i_MA_standart;
        public MovingAverage i_MA_fast;
        private RelativeStrengthIndex rsi;
        private MacdCrossOver macd_1;
        private MacdCrossOver macd_2;
        private double volumeInUnits;
        private Position position;
        private Bars _marketSeries2;
        private Bars _marketSeries1;


        protected override void OnStart()

        {
           
            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(SourceRSI, PeriodsRSI);
            macd_1 = Indicators.MacdCrossOver(LongPeriod1, ShortPeriod1, SignalPeriod1);
            macd_2 = Indicators.MacdCrossOver(LongPeriod2, ShortPeriod2, SignalPeriod2);
            volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
            Positions.Opened += OnPositionsOpened;
            Positions.Closed += OnPositionsClosed;
            _marketSeries2 = MarketData.GetBars(macd2, Symbol.Name);
            _marketSeries1 = MarketData.GetBars(macd1, Symbol.Name);
        }

        void OnPositionsClosed(PositionClosedEventArgs obj)
        {
            position = null;
        }

        void OnPositionsOpened(PositionOpenedEventArgs obj)
        {
            position = obj.Position;
        }
                    
                                  
        [Obsolete]
        protected override void OnBar()
        {
            //First MACD
            var _marketSeries1 = MarketData.GetBars(macd1);
            var macd_1 = Indicators.MacdCrossOver(_marketSeries1.ClosePrices, LongPeriod1, ShortPeriod1, SignalPeriod1);
            var MACDLine1  = macd_1.MACD.Last(1);
            var PrevMACDLine1 = macd_1.MACD.Last(2);
            var Signal1  = macd_1.Signal.Last(1);
            var PrevSignal1 = macd_1.Signal.Last(2);

            // both macd must be above the zero line for an entry buy or sell
            // Second MACD
            var _marketSeries2 = MarketData.GetBars(macd2);
            var macd_2 = Indicators.MacdCrossOver(_marketSeries2.ClosePrices, LongPeriod2, ShortPeriod2, SignalPeriod2);
            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);

            if (position != null)
                return;
            {
                if (rsi.Result.LastValue > 25 && rsi.Result.LastValue < 70)
                {
                    
                        int index = MarketSeries.Close.Count;

                    if   (MACDLine1 > Signal1 & PrevMACDLine1 <PrevSignal1 & default==Sell 
                        & MACDLine_2 > Signal_2 & PrevMACDLine_2 < PrevSignal_2 & default == Sell
                        & i_MA_fast.Result[index - 2] > MarketSeries.Close[index - 2] 
                        & i_MA_fast.Result[index - 1] < MarketSeries.Close[index - 1]
                        & i_MA_fast.Result.LastValue < i_MA_standart.Result.LastValue
                        & i_MA_fast.Result.LastValue < i_MA_slow.Result.LastValue
                        & i_MA_standart.Result.LastValue < i_MA_slow.Result.LastValue)
               {         
                        
                      ExecuteMarketOrder( TradeType.Buy, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                  }
                        
                        else if (MACDLine1 < Signal1 & PrevMACDLine1 >PrevSignal1 & default== Buy
                        & MACDLine_2 > Signal_2 & PrevMACDLine_2 < PrevSignal_2 & default == Buy
                        & i_MA_fast.Result[index - 2] < MarketSeries.Close[index - 2] 
                        & i_MA_fast.Result[index - 1] > MarketSeries.Close[index - 1]
                        & i_MA_fast.Result.LastValue > i_MA_standart.Result.LastValue
                        & i_MA_fast.Result.LastValue > i_MA_slow.Result.LastValue
                        & i_MA_standart.Result.LastValue > i_MA_slow.Result.LastValue)

                        {
                                        
                     ExecuteMarketOrder( TradeType.Sell, SymbolName, volumeInUnits, "PullbackStrategy, RSI, MACD", StopLoss, TakeProfit);
                  
                            }
                }
               

                } 
           
         }
                   
       
           protected override void OnStop()
        {
        }
                  
        }
    }
     


        
   
    
    

 


@Alwin123

Alwin123
31 Oct 2022, 19:45

RE: RE:
Thanks for your help.
I just can't get it without errors. maybe i'm doing it wrong. of course I haven't been working on C# for that long

 

HI @Alwin123:

Your code isn't going to work, because you have to pass in a different time frame series when you create the MACD indicator.

It'll be something like this:
 

private Bars _marketSeriesH1;
MacdCrossOver macd;

//In the OnStart method, do something like this. This will get the data for the H1 timeframe:
_marketSeriesH1 = MarketData.GetBars(TimeFrame.Hour, Symbol.Name);

//This gets the MACD with the above time frame set (eg, H1 in this case):
macd = Indicators.MacdCrossOver(_marketSeriesH1.ClosePrices, LongPeriod, ShortPeriod, SignalPeriod);


 


@Alwin123

Alwin123
30 Oct 2022, 20:05

what did i wrong i have 3 errors in this script?

using System;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Requests;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot()]
    public class ExampleRobot : Robot
    {
        [Parameter("Stop Loss", DefaultValue = 6.0)]
        public double StopLoss { get; set; }

        [Parameter("Commission in Pips", DefaultValue = 0.8)]
        public double CommissionPips { get; set; }

        [Parameter("Risk Percent", DefaultValue = 0.5, MinValue = 0.1, MaxValue = 5.0)]
        public double RiskPercent { get; set; }

        [Parameter("Reserve Funds", DefaultValue = 0)]
        public int ReserveFunds { get; set; }

        [Parameter("Max Volume", DefaultValue = 5000000)]
        public int MaxVolume { get; set; }

        private int _volume;

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnBar()
        {
            CalculateVolume();
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }

        private double CalculateVolume()
        {
            // Our total balance is our account balance plus any reserve funds. We do not always keep all our money in the trading account. 
            double totalBalance = Account.Balance + ReserveFunds;

            // Calculate the total risk allowed per trade.
            double riskPerTrade = (totalBalance * RiskPercent) / 100;

            // Add the stop loss, commission pips and spread to get the total pips used for the volume calculation.
            double totalPips = (StopLoss / Symbol.PipSize) + CommissionPips + Symbol.Spread;

            // Calculate the exact volume to be traded.
            double exactVolume = riskPerTrade / (Symbol.PipValue * totalPips);
            if (exactVolume >= Symbol.VolumeInUnitsMin)
            {
                _volume = Symbol.NormalizeVolumeInUnits(exactVolume, RoundingMode.Down);

                // Finally, check that the calculated volume is not greater than the MaxVolume parameter. If it is greater, reduce the volume to the MaxVolume value.
                if (_volume > MaxVolume)
                    _volume = MaxVolume;
                }
                else
                {
                _volume = -1;
                Print("Not enough Equity to place minimum trade, exactVolume " + exactVolume + " is not >= Symbol.VolumeInUnitsMin " + Symbol.VolumeInUnitsMin);
            }
            return _volume;
        }


@Alwin123