Topics
03 Jan 2024, 18:24
 368
 4
11 Mar 2021, 11:23
 972
 2
12 Jul 2020, 17:21
 1154
 4
27 Jun 2020, 18:58
 1121
 2
04 Jun 2020, 17:42
 1009
 2
11 May 2020, 00:58
 1071
 6
23 Jul 2019, 16:05
 1019
 7
17 Jul 2019, 21:32
 1340
 2
Replies

eliezer_barros
24 May 2019, 13:41

Hi Panagiotis

 

I think this is easier to change in program, because is only to considerate the how long days the position is open and to include the swap and other costs.

This will be much more real information that we have today and very import.

I now that spread is a average, not problem, anyway is more acurate that today

 

Tks

Eliézer


@eliezer_barros

eliezer_barros
25 Feb 2019, 14:47 ( Updated at: 21 Dec 2023, 09:21 )

RE:

lec0456 said:

I am not sure I understnd you but, it sounds like you just want to create a slope indicator, that will subtract the current 14 prd moving average from the previous one.  Then you feed that indicator into a cBot and make a trade when the last 3 prds are positive or negative. Here is an example of a slope indicator.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = false)]
    public class myMASlope : Indicator
    {
        [Parameter(DefaultValue = 60)]
        public int paramPeriods { get; set; }
        [Parameter(DefaultValue = 1.9)]
        public double paramLimit { get; set; }

        [Output("MA Slope", PlotType = PlotType.Histogram, Thickness = 2, Color = Colors.Purple)]
        public IndicatorDataSeries Result { get; set; }
        [Output("SlopeMA", LineStyle = LineStyle.Lines, Color = Colors.Red)]
        public IndicatorDataSeries SlopeMA { get; set; }

        [Output("UpperLimit", PlotType = PlotType.Line, LineStyle = LineStyle.DotsRare, Thickness = 1, Color = Colors.Red)]
        public IndicatorDataSeries UpperLimit { get; set; }
        [Output("LowerLimit", PlotType = PlotType.Line, LineStyle = LineStyle.DotsRare, Thickness = 1, Color = Colors.Red)]
        public IndicatorDataSeries LowerLimit { get; set; }
        [Output("Center", LineStyle = LineStyle.DotsRare, Color = Colors.White)]
        public IndicatorDataSeries CenterLine { get; set; }

        private SimpleMovingAverage sma;
        private MovingAverage slopema;
        private SimpleMovingAverage slopema2;

        protected override void Initialize()
        {
            sma = Indicators.SimpleMovingAverage(MarketSeries.Close, paramPeriods);
            slopema = Indicators.MovingAverage(Result, 2, MovingAverageType.Exponential);
            slopema2 = Indicators.SimpleMovingAverage(slopema.Result, 2);
        }

        public override void Calculate(int index)
        {
            int t0 = index;
            int t1 = t0 - 1;
            int t2 = t1 - 1;

            if (t1 < 0)  return;

            if (double.IsNaN(sma.Result[t1])) return;
          
            Result[index] = Math.Round((sma.Result[t0] - sma.Result[t1]) / (Symbol.PointSize), 2);
            SlopeMA[index] = slopema2.Result[index];
            //Result[index]= Math.Round((sma.Result[t0]-sma.Result[t2])/(Symbol.PointSize*2),2);
            UpperLimit[index] = paramLimit;
            LowerLimit[index] = -paramLimit;
            CenterLine[index] = 0;
        }
    }
}

 

Hi, thank for your suggestions, yes I want to use the curve with 14 prd and use only the last 3 or 4 hours to open the position according with direction. If I use the curve with 3 or 4 periods, in really the curve is other and the directions can be wrong.

I am do not a specialist in this kind of program and I went to do a test in system and found some errors that I will print here, if you can modify I will thanks to you again.


@eliezer_barros

eliezer_barros
22 Feb 2019, 18:53

RE:

Panagiotis Charalampous said:

Hi Eliezer,

My understanding is that you want a trade to open when the 14 period MA is rising for the last 3 bars. Is that correct?

Best Regards,

Panagiotis

hi...

 

Yes, you are correct.


@eliezer_barros

eliezer_barros
05 Feb 2019, 14:55

I identified the problem.
I wish that the program analyse the last 4 hours and open the position, but the system is pickup a short time.


@eliezer_barros

eliezer_barros
05 Feb 2019, 14:23

RE:

Panagiotis Charalampous said:

Hi Eliezer,

This is how it should work. The function checks if the curve is rising or failing at that moment.

Best Regards,

Panagiotis

The program should get the informations of the curve the last 4 hours and to open the position according this direction. Please see again, because sometimes this is correct, but have a several errors and the position is open in wrong direction and I can't find this problem. Observe that I created a print to log to try identify this error.

tks

 

//moeda system robot
// robot para iniciar uma operacao em determinada hora usando a media exponencial
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 TesteExponentialMovingAverage : Robot
    {
        [Parameter(DefaultValue = 1)]
        public double VolumeToOpenOrders { get; set; }

        [Parameter(DefaultValue = 1000)]
        public int TakeProfitInPips { get; set; }

        [Parameter("Stop Loss", DefaultValue = 2000)]
        public int StopLoss { get; set; }

        [Parameter("MAType", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MaType { get; set; }

        protected override void OnBar()
        {
            if (MarketSeries.OpenTime.LastValue.Hour == 3)
            {
                var sma1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, 4);
                Print("Close", sma1.Result);
                var sma2 = Indicators.ExponentialMovingAverage(MarketSeries.Open, 4);
                Print("Open", sma2.Result);
                {
                    if (sma1.Result.IsRising())
                        //                   Print("UP", sma.Result);

                        ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeToOpenOrders, "", StopLoss, TakeProfitInPips);
                }
                {
                    if (sma2.Result.IsFalling())
                        //                       Print("Down", sma.Result);
                        ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeToOpenOrders, "", StopLoss, TakeProfitInPips);
                    {
                    }

                }

            }
        }
    }
}


@eliezer_barros

eliezer_barros
04 Feb 2019, 18:38

I understood that is happening.

The system is picking information of last hour and it's does not considering the tentence of curve.

Please, can you check?

Tks


@eliezer_barros

eliezer_barros
04 Feb 2019, 15:58

I sent by email because here the imagen is not good.


@eliezer_barros

eliezer_barros
04 Feb 2019, 15:38

This system is working, but sometimes it's does not open the position in correct direction.

Please, can you see this problem?

tks

____________________________________________

 

//moeda system robot
// robot para iniciar uma operacao em determinada hora usando a media exponencial
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 TesteExponentialMovingAverage : Robot
    {
        [Parameter(DefaultValue = 1)]
        public double VolumeToOpenOrders { get; set; }

        [Parameter(DefaultValue = 1000)]
        public int TakeProfitInPips { get; set; }

        [Parameter("Stop Loss", DefaultValue = 2000)]
        public int StopLoss { get; set; }

        [Parameter("MAType", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MaType { get; set; }

        protected override void OnBar()
        {
            if (MarketSeries.OpenTime.LastValue.Hour == 3)
            {
                var sma = Indicators.ExponentialMovingAverage(MarketSeries.Close, 4);
                {
                    if (sma.Result.IsRising())
                        ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeToOpenOrders, "", StopLoss, TakeProfitInPips);
                }
                {
                    if (sma.Result.IsFalling())
                        ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeToOpenOrders, "", StopLoss, TakeProfitInPips);
                    {
                    }

                }

            }
        }
    }
}


@eliezer_barros

eliezer_barros
15 Jan 2019, 15:39

RE:

Panagiotis Charalampous said:

Hi eliezer_barros,

Which broker's cTrader do you use?

Best Regards,

Panagiotis

Hi,

I use Fxpro


@eliezer_barros

eliezer_barros
28 Dec 2018, 13:36

RE:

Hi,

I installed this routine and error message appear:

'cAlgo.API.Position' does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument ....

Please, can you help me?

tks


@eliezer_barros

eliezer_barros
21 Dec 2018, 16:15

RE:

Panagiotis Charalampous said:

Hi Panagiotis

I am new in this system and I want to do a little routine comparate dates, can I send to you or this support is only to command explanation?

My email is eliezer_barros@yahoo.com.br

tks


@eliezer_barros