Replies

Delta_Gamma
24 Mar 2020, 11:13

RE:

PanagiotisCharalampous said:

Hi Delta_Gamma,

We will add these timeframes in a future update of cTrader Web.

Best Regards,

Panagiotis 

Join us on Telegram

That is excellent news. Thanks very much. 


@Delta_Gamma

Delta_Gamma
13 Feb 2014, 13:17

Hi sorry to post again but I forgot about this..

I am also trying to get parameters for the Linear Regression Channel indicator. I appreciate that these indicators have been posted but my problem is I cannot use them in my robot because they have no parameters, I have checked the documentation but I am still unsure what to do. For example, this is the code from the Linear Regression Channel

 protected override void Initialize()
        {
            // Parse color from string, e.g. "Yellow", "Green", "Red". string must start with large letter, "Red" is valid, "red" - not.
            if (!Enum.TryParse(Color, out color))
                color = Colors.Yellow;
        }

        public override void Calculate(int index)
        {
            if (IsLastBar)
                LinearRegression(MarketSeries.Close);
        }

        private void LinearRegression(DataSeries series)
        {
            // Linear regresion

            double sum_x = 0, sum_x2 = 0, sum_y = 0, sum_xy = 0;

            int start = series.Count - Bars;
            int end = series.Count - 1;

            for (int i = start; i <= end; i++)
            {
                sum_x += 1.0 * i;
                sum_x2 += 1.0 * i * i;
                sum_y += series[i];
                sum_xy += series[i] * i;
            }

            double a = (Bars * sum_xy - sum_x * sum_y) / (Bars * sum_x2 - sum_x * sum_x);
            double b = (sum_y - a * sum_x) / Bars;


            // Calculate maximum and standard devaitions

            double maxDeviation = 0;
            double sumDevation = 0;

            for (int i = start; i <= end; i++)
            {
                double price = a * i + b;
                maxDeviation = Math.Max(Math.Abs(series[i] - price), maxDeviation);
                sumDevation += Math.Pow(series[i] - price, 2.0);
            }

            double stdDeviation = Math.Sqrt(sumDevation / Bars);

            // draw in future
            end += 20;

            double pr1 = a * start + b;
            double pr2 = a * end + b;

            if (ShowCenter)
            {
                ChartObjects.DrawLine("center", start, pr1, end, pr2, color, LineThickness, LineStyle.Lines);
            }

            if (ShowChannel)
            {
                ChartObjects.DrawLine("top", start, pr1 + maxDeviation, end, pr2 + maxDeviation, color, LineThickness, LineStyle.Solid);
                ChartObjects.DrawLine("bottom", start, pr1 - maxDeviation, end, pr2 - maxDeviation, color, LineThickness, LineStyle.Solid);
            }

            if (ShowDeviantion)
            {
                ChartObjects.DrawLine("dev-top", start, pr1 + stdDeviation, end, pr2 + stdDeviation, color, LineThickness, LineStyle.DotsVeryRare);
                ChartObjects.DrawLine("dev-bottom", start, pr1 - stdDeviation, end, pr2 - stdDeviation, color, LineThickness, LineStyle.DotsVeryRare);
            }
        }

    }

All I want to be able to do is make it so my cbot buys when the price is under the bottom parallel line and sells when the price is above the top parallel line. I'm not sure how to convert the ChartObject into a parameter.

Thanks.


@Delta_Gamma

Delta_Gamma
13 Feb 2014, 13:10

Hi, thanks for the reply.

Can you please help me or direct me to where I can find out how to modify the indicator in that way? I am afraid I have no idea where to begin.

Perhaps you could provide some code?

Thanks again!


@Delta_Gamma

Delta_Gamma
12 Feb 2014, 08:08

Any chance of a reply?

It's been a week.


@Delta_Gamma

Delta_Gamma
17 Jan 2014, 17:58

RE: Delta

Hey Jeex,

I like that approach, that's actually what I wanted to do. I rely on my trading abilities but what I have found is I focus way too much on the charts and that tends to make me do stupid things. Letting the bot automate the trades while relying on a human decision is definitely the best method in my opinion because I don't believe any indicators will ever be consistently successful since they are mostly lagging, even a moving average isn't a substitute for the human eye, that is why my indicator I designed actually just simulates trend-lines.

Regarding your second point, I think that's a good way to do things because even with a heiken ashi the bot is still liable to make losses because of pull-backs etc. I think I'm going to take after your lead and do that too.

I'm curious how your bot decides on TP and SL, do you mind sharing? My bot only determines TP at the moment but SL I have found to be troubling.

I'd be interested to see some backtests too if you're willing.

jeex said:

Same aproach, different solution...

I use three bots for that.

  1. The first bot monitors all relevant pairs on specific criteria (like strong trend or strong reversal). This is where my TFV comes in handy.
  2. This is my job: making the right decision.
  3. A second bot calculates the volume and SL & TP and openes a trade.
  4. A third bot trails the trade, partially closes it, if relevant, all by modifying the SL and TP.
  5. The server closes the trade on the SL or TP. So no harm done if internet fails or the computer goes down.

This way psycho-actions :-) are mostly avoided. I do not have to stare in screens all day; only when my alert tells me to.

Finally it's my personal skills that decide on opening a trade. So no need of martingale calculations as my winning percentage is almost at 80 of the trades (and going up), where as my TP is always higher than my SL. The software does all the tedious work, i only surf the waves of the charts.

 


@Delta_Gamma

Delta_Gamma
17 Jan 2014, 09:38

Hey Jeex,

Thanks for that indicator, it's perfect for the purposes of my bot.

The martingale-type function is definitely risky I agree, however I have found that given a strong trend it tends to work quite well, that is why I am so focused on determining trend directions. Also my function does not trade in the opposite direction of a losing trade, nor does it double positions like the martingale does, what it does, is it adds to profitable positions while the trend matures.

Basically what I want the finished product to do is determine the overall trend, trade in that direction and stop or email me once it reaches a certain profit, that way I can re-evaluate the market before I start the bot again. The idea behind this is that it takes away all the emotion and greed/fear of trading but still uses my trend trading strategies that have been successful in the past.

Anyway, thanks again for the help. Things are progressing again thanks to your help.

See ya!


@Delta_Gamma

Delta_Gamma
16 Jan 2014, 11:57 ( Updated at: 21 Dec 2023, 09:20 )

Hey jeex!

 

Thanks for much for the help, I just have one question.

My bot works with onTick to determine the trade, would this method still work? (unfortunately the onTick has to be used, onBar doesn't work with my strategy.

Also, to use the Heiken Ashi for only the daily chart but still trade on the other charts I referenced it like this, not sure if it's right?

 

  [Parameter(DefaultValue = 2)]
  public int HPeriod { get; set; }

private HeikenAshi H;

var DailyH = MarketData.GetSeries(this.Symbol, TimeFrame.Daily);
            H = Indicators.GetIndicator(DailyH, HPeriod);

Thanks for the help!

Oh and since you asked, I can share a back-test but keep in mind it is only during an uptrend and therefore isn't a long period (2 months), also it uses mini-lots.

I recognise that it requires a much longer period of time to test it properly however before I can do that I need to be able to get this Heiken Ashi working so that I can determine trend pauses and trend changes.

 

 


@Delta_Gamma

Delta_Gamma
24 Jul 2013, 21:06

RE:
cAlgo_Fanatic said:

The code of that indicator does not output the values of the trendlines into an IndiatorDataSeries but draws the lines using ChartObjects.DrawLine.
Look at the Sample Trend Robot in the platform for an example on how you could utilize a trend indicator in a Robot.

Hi,

is there any way to output that ChartObjects.DrawLine into a dataseries or at least access the maximum and minimum values (red)?

What I mean is, can that code be rewritten to use a Dataseries or is it not possible due to the dynamic nature of the trendline?

~The Sample Trend Robot unfortunately isn't specific enough as it uses a moving average cross technique and not a trendline.

Thanks for the help,


@Delta_Gamma

Delta_Gamma
09 Jul 2013, 06:16

That's great news.

Thanks for the information.


@Delta_Gamma

Delta_Gamma
27 Jun 2013, 03:44

Hi Admin,

Thanks for the reply.

I just tested it, it does work, however the programming logic was incorrect, since I wanted the timer to start only when a new position was entered and each new position gets its own instance of that timer so that after half an hour individually the positions close.

I have this code for that, which is called everytime a new position is opened. Would this work?

 public void Reset()
     {
            _timer.Stop();
             _timer.Start();
     }


@Delta_Gamma

Delta_Gamma
25 Jun 2013, 12:59

RE:

Hi,


I would appreciate a response to this urgently please.

At the moment I have the code below: (which didn't work)

I did create a Timer Bot to check if the timer worked, which it did, I made it Print something at the interval of half an hour. The problem is in my actual bot, the positions do not close like they are supposed to at the interval.

Note: I have another method which closes trades that are in profit if they cross a certain moving average, it is not based on a timer, this also uses foreach (Position position in _listPosition)

 

 

using System.Timers;

////////////

            _timer.Elapsed += OnTimedEvent; //  OnTimedEvent is called at each timer tick
            _timer.Interval = (0.5)  * 3600 * 1000; // Timer will tick every half hour (milliseconds)
            _timer.Enabled = true; // Enable the timer
            _timer.Start(); // Start the timer

 

 

        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
           foreach (Position position in _listPosition)
            {           
                                 
                if (position.GrossProfit < 0)
               
                  {
                    ClosePosition(position);
                    Print("Trade Closed due to Timer");
                }                                                
                        
            }
        }

 


@Delta_Gamma

Delta_Gamma
23 Jun 2013, 07:11

Hi,


Can you please help me with the following or provide the source code for this?

Basically what I want to do is have a timer event that checks certain conditions with an if-statement after every, say, 15 minutes and then closes a position or leaves it open based on the result.

I saw from this thread (/forum/cbot-support/357) there is this code:

using System.Timers;
//...

        private readonly Timer _timer = new Timer();

        protected override void OnStart()
        {
            _timer.Elapsed += OnTimedEvent; //  OnTimedEvent is called at each timer tick
            _timer.Interval = (Interval)  * 3600 * 1000; // Timer will tick every Interval (milliseconds)
            _timer.Enabled = true; // Enable the timer
            _timer.Start(); // Start the timer

        }

        private void OnTimedEvent(object sender, ElapsedEventArgs e)
        {
            // Your logic here
        }


would I just put a foreach statement in the OnTimedEvent to loop through open positions?

Also I see from that thread the Admin explains that backtesting does not work with the timer but that it can work if one
does the following

"make the timed event very small, i.e. one second for testing purposes."

Can you please expand on this and show me how I would do this so that I can backtest it?

Thanks for the assistance as always.

 

 

 


@Delta_Gamma

Delta_Gamma
23 Jun 2013, 07:01

Ah that worked! dunno why I didn't think of that lol.

Thanks mate.


@Delta_Gamma

Delta_Gamma
07 Jun 2013, 17:14

Ah thank you, I see the error now, I had a variable called _position being called.

 

Thanks


@Delta_Gamma

Delta_Gamma
04 Jun 2013, 17:22

Hi,

Thanks very much for the help. It's working great now.

I just have to do some refinements and it should ready.

 

Thanks again.


@Delta_Gamma

Delta_Gamma
04 Jun 2013, 12:38 ( Updated at: 21 Dec 2023, 09:20 )

Hi Admin,


Thanks for the response. By previous to last value do you mean I make it LastValue-1 like this?

I tried this in a backtest and it didn't seem to close the trade. (attached pic)


Do you have any recommendations on what I can do to achieve this? I just need the trade to close when it either touches or closes above the SMA.

The attached pic has the area circled where I need the trade to close.

Thanks again.

protected override void OnTick()
        {

                     
                Buy();
                
                 foreach (var position in Account.Positions)
            
                if (MarketSeries.Close.HasCrossedAbove(MA1.Result.LastValue-1,0))
                {
                    ClosePosition();
        
                }

 

 

 

 


@Delta_Gamma

Delta_Gamma
03 Jun 2013, 19:55 ( Updated at: 21 Dec 2023, 09:20 )

I would appreciate some feedback from the admin.


The attached pic explains what I need the program to do for clarity:

 

basically, (referring to the pic) I wanted that trade to close as soon as the price closed under the green line (which is a customised simple moving average indicator).

 

How would I code this?

 

Thanks


@Delta_Gamma

Delta_Gamma
03 Jun 2013, 10:13

Hi just noticed an error, I copied and pasted the wrong code, it should be MA1 not HG:

 

private void OpenPosition()
        {
            foreach (var position in Account.Positions)
            {
                if (MarketSeries.Close.HasCrossedAbove(MA1.Result.LastValue))
                {
                    ClosePosition();
                }
            }
        }  


@Delta_Gamma

Delta_Gamma
02 Jun 2013, 16:47

Hi,


When I tried renaming it, I get the error:

 

A reference to C:\Users\myPc\Documents\cAlgo\Sources\Indicators\AdaptiveCG.dll could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component.

 

Sorry, I'm new to C# programming.

 

Thanks for the help.


@Delta_Gamma