Replies

ryanoia@gmail.com
17 Nov 2019, 14:06

Seems like the post here solves it - https://ctrader.com/forum/cbot-support/16300


@ryanoia@gmail.com

ryanoia@gmail.com
17 Nov 2019, 14:04 ( Updated at: 21 Dec 2023, 09:21 )

Technical Error on JPY pairs - Relative stop loss has invalid precision

Ok, I checked the journal and saw this:

Says here that the order was rejected with error "Relative stop loss has invalid precision."

What's the solution to this?


@ryanoia@gmail.com

ryanoia@gmail.com
22 Sep 2019, 16:41

Thanks for the response. I know how to do that too but did not consider this because it doesn't prevent the bot from opening positions in the first place.


@ryanoia@gmail.com

ryanoia@gmail.com
31 Jul 2019, 16:17

I can, but can't do this right away. In the meantime, I was able to implement a workaround by adding a condition whereby if position.pips == 0, do not execute.


@ryanoia@gmail.com

ryanoia@gmail.com
31 Jul 2019, 16:15

I tried incorporating the above in one of my cbots and an error occurred showing this:

 

Error CS0649: Field 'cAlgo.Robots.BlueMethDemoExpiration._conditionMet' is never assigned to, and will always have its default value false

 

I guess the part where you wrote" _conditionMet = ..." means something and needs to be applied to the condition. However, I am not certain how. Assistance with a more specific sample would be highly appreciated.


@ryanoia@gmail.com

ryanoia@gmail.com
27 Jul 2019, 15:34

Any luck resolving this?


@ryanoia@gmail.com

ryanoia@gmail.com
21 Jul 2019, 09:41 ( Updated at: 21 Dec 2023, 09:21 )

RE:

ClickAlgo said:

You can use this assembly which encapsulates (hides) all the complex code and allows you to write to a file with a single line of code.

Its free and there is also a video demo on the product page.

https://clickalgo.com/ctrader-cbot-indicator-data-logger

EXAMPLE USAGE

Paul Hayes
Sales & Marketing
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com

 

The link posted doesn't work anymore. Is this still being offered? 


@ryanoia@gmail.com

ryanoia@gmail.com
19 Jul 2019, 11:32 ( Updated at: 21 Dec 2023, 09:21 )

Received a telegram message just 7 minutes ago:

GBPCHF Buy not even close to 0 pips or higher than -6 pips:

Feel free to look at GBPCHF now. 


@ryanoia@gmail.com

ryanoia@gmail.com
19 Jul 2019, 11:14

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.FullAccess)]
    public class Velocity : Robot
    {
        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("Limit Range", DefaultValue = 3)]
        public double LimitRange { get; set; }

        [Parameter("Take Profit In Pips", DefaultValue = 20)]
        public double TakeProfitInPips { get; set; }

        [Parameter("Stop Loss In Pips", DefaultValue = 100)]
        public double StopLossInPips { get; set; }

        [Parameter("Email Message", DefaultValue = "Message")]
        public string EmailMessage { get; set; }

        [Parameter("Sender Email Address", DefaultValue = "sender@gmail.com")]
        public string SenderEmailAddress { get; set; }
        
        [Parameter("Recipient Email Address", DefaultValue = "recipient@gmail.com")]
        public string RecipientEmailAddress { get; set; }

        protected override void OnStart()
        {
        }

        protected override void OnBar()
        {
        }

        protected override void OnTick()
        {
            if ((Positions.Find("Wave 0", SymbolName, TradeType.Buy) == null) && (Positions.Find("Wave 0", SymbolName, TradeType.Sell) == null) && (Symbol.Spread / Symbol.PipSize < LimitRange) && (Server.Time.Hour != 4) && (Server.Time.Hour != 5) && (Server.Time.Hour != 6))
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange);
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange);
                Notifications.SendEmail(SenderEmailAddress, RecipientEmailAddress, SymbolName, EmailMessage);
            }
            
            //refresh buy side
            if ((Positions.Find("Wave 0", SymbolName, TradeType.Buy) == null) && (Symbol.Spread / Symbol.PipSize < LimitRange))
            {
                foreach (var position in Positions)
                {
                    if ((position.Pips * -1 <= LimitRange * 2) && (position.SymbolName == Symbol.Name) && (position.TradeType == TradeType.Sell))
                    {
                        Notifications.SendEmail(SenderEmailAddress, RecipientEmailAddress, SymbolName, "Buy Side Refresh One Side " + " Negative Pips Converted to Positive = " + position.Pips * -1 + " Limit Range * 2 = " + LimitRange * 2);
                        ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange);
                    }
                }
            }
            //end of refresh buy side

            //refresh sell side
            if ((Positions.Find("Wave 0", SymbolName, TradeType.Sell) == null) && (Symbol.Spread / Symbol.PipSize < LimitRange))
            {
                foreach (var position in Positions)
                {
                    if ((position.Pips * -1 <= LimitRange * 2) && (position.SymbolName == Symbol.Name) && (position.TradeType == TradeType.Buy))
                    {
                        Notifications.SendEmail(SenderEmailAddress, RecipientEmailAddress, SymbolName, "Sell Side Refresh One Side " + " Negative Pips Converted to Positive = " + position.Pips * -1 + " Limit Range * 2 = " + LimitRange * 2);
                        ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Wave 0", StopLossInPips, TakeProfitInPips, LimitRange);
                    }
                }
            }
            //end of refresh sell side
    }
}

 


@ryanoia@gmail.com

ryanoia@gmail.com
27 Jun 2019, 18:39

The moment I read it, I knew this would work, and it did. 

Thanks. You're the best mate!


@ryanoia@gmail.com

ryanoia@gmail.com
26 Jun 2019, 19:58

One solution that I think would work is that the bot just runs the functions just once and then waits about 1 minute before running it again, by which time the server has probably already processed the order and so bot would not have to send new market orders since the symbol would have positions by that time. However, I have no idea how to code that. If you can, please advise.

On the other hand, if you have a solution different from the one above but would work as well, please feel free to share it.  


@ryanoia@gmail.com

ryanoia@gmail.com
14 Jun 2019, 12:58

Is there a way to calculate the average daily gain/loss in absolute terms over a N number of daily candles?
@ryanoia@gmail.com

ryanoia@gmail.com
22 Apr 2019, 10:51

I mean, pivot point support and resistance levels


@ryanoia@gmail.com

ryanoia@gmail.com
22 Apr 2019, 10:50

Ok. So are you saying that with the second indicator, it is possible, it's just that I have to add functionality in the pivot point cBot code for the cBot to access the support and resistance levels in the indicator? 


@ryanoia@gmail.com

ryanoia@gmail.com
22 Apr 2019, 03:10

How about making reference to this pivot point indicator:

 

using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
 
namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
    public class AllPivots : Indicator
    {
        private DateTime _previousPeriodStartTime;
        private int _previousPeriodStartIndex;
        private TimeFrame PivotTimeFrame;
        private VerticalAlignment vAlignment = VerticalAlignment.Top;
        private HorizontalAlignment hAlignment = HorizontalAlignment.Right;
 
        public string PP;
 
        Colors pivotColor = Colors.Magenta;
        Colors supportColor = Colors.Red;
        Colors resistanceColor = Colors.DodgerBlue;
        Colors pmedioColor = Colors.Green;
 
        [Parameter("Show Labels", DefaultValue = true)]
        public bool ShowLabels { get; set; }
 
        [Parameter("Pivot Color", DefaultValue = "Magenta")]
        public string PivotColor { get; set; }
        [Parameter("Support Color", DefaultValue = "Red")]
        public string SupportColor { get; set; }
        [Parameter("Resistance Color", DefaultValue = "DodgerBlue")]
        public string ResistanceColor { get; set; }
        [Parameter("PMedio Color", DefaultValue = "Green")]
        public string PmedioColor { get; set; }
 
        [Parameter("Espessura Pivot", DefaultValue = 1)]
        public int Espessura { get; set; }
 
        [Parameter("Espessura Pivot Medio", DefaultValue = 1)]
        public int Espessura2 { get; set; }
 
 
        protected override void Initialize()
        {
 
            PivotTimeFrame = TimeFrame.Daily;
            PP = "P Daily";
 
                        /*            if (TimeFrame < TimeFrame.Hour4)
            {
                PivotTimeFrame = TimeFrame.Daily;
                PP = "P Daily";
            }
 
 
            if ((TimeFrame >= TimeFrame.Hour4) && (TimeFrame < TimeFrame.Weekly))
            {
                PivotTimeFrame = TimeFrame.Weekly;
                PP = "P Weekly";
            }
 
 
            if (TimeFrame >= TimeFrame.Weekly)
            {
                PivotTimeFrame = TimeFrame.Monthly;
                PP = "P Monthly";
            }
*/
Enum.TryParse(PivotColor, out pivotColor);
            Enum.TryParse(SupportColor, out supportColor);
            Enum.TryParse(ResistanceColor, out resistanceColor);
            Enum.TryParse(PmedioColor, out pmedioColor);
 
        }
 
        private DateTime GetStartOfPeriod(DateTime dateTime)
        {
            return CutToOpenByNewYork(dateTime, PivotTimeFrame);
        }
 
        private DateTime GetEndOfPeriod(DateTime dateTime)
        {
            if (PivotTimeFrame == TimeFrame.Monthly)
            {
                return new DateTime(dateTime.Year, dateTime.Month, 1).AddMonths(1);
            }
 
            return AddPeriod(CutToOpenByNewYork(dateTime, PivotTimeFrame), PivotTimeFrame);
        }
 
        public override void Calculate(int index)
        {
            var currentPeriodStartTime = GetStartOfPeriod(MarketSeries.OpenTime[index]);
            if (currentPeriodStartTime == _previousPeriodStartTime)
                return;
 
            if (index > 0)
                CalculatePivots(_previousPeriodStartTime, _previousPeriodStartIndex, currentPeriodStartTime, index);
 
            _previousPeriodStartTime = currentPeriodStartTime;
            _previousPeriodStartIndex = index;
        }
 
        private void CalculatePivots(DateTime startTime, int startIndex, DateTime startTimeOfNextPeriod, int index)
        {
            var high = MarketSeries.High[startIndex];
            var low = MarketSeries.Low[startIndex];
            var close = MarketSeries.Close[startIndex];
            var i = startIndex + 1;
 
            while (GetStartOfPeriod(MarketSeries.OpenTime[i]) == startTime && i < MarketSeries.Close.Count)
            {
                high = Math.Max(high, MarketSeries.High[i]);
                low = Math.Min(low, MarketSeries.Low[i]);
                close = MarketSeries.Close[i];
 
                i++;
            }
 
            var pivotStartTime = startTimeOfNextPeriod;
            var pivotEndTime = GetEndOfPeriod(startTimeOfNextPeriod);
 
            var pivot = (high + low + close) / 3;
 
            var r1 = 2 * pivot - low;
            var s1 = 2 * pivot - high;
 
            var r2 = pivot + high - low;
            var s2 = pivot - high + low;
 
            var r3 = high + 2 * (pivot - low);
            var s3 = low - 2 * (high - pivot);
 
            var r4 = r3 + pivot - low;
            var s4 = s3 + pivot - high;
 
 
            var m0 = (s4 + s3) / 2;
            var m1 = (s3 + s2) / 2;
            var m2 = (s2 + s1) / 2;
            var m3 = (s1 + pivot) / 2;
            var m4 = (pivot + r1) / 2;
            var m5 = (r1 + r2) / 2;
            var m6 = (r2 + r3) / 2;
            var m7 = (r3 + r4) / 2;
 
 
            ChartObjects.DrawLine("pivot " + startIndex, pivotStartTime, pivot, pivotEndTime, pivot, pivotColor, Espessura, LineStyle.Solid);
            ChartObjects.DrawLine("r1 " + startIndex, pivotStartTime, r1, pivotEndTime, r1, resistanceColor, Espessura, LineStyle.Solid);
            ChartObjects.DrawLine("r2 " + startIndex, pivotStartTime, r2, pivotEndTime, r2, resistanceColor, Espessura, LineStyle.Solid);
            ChartObjects.DrawLine("r3 " + startIndex, pivotStartTime, r3, pivotEndTime, r3, Colors.Aqua, Espessura, LineStyle.Solid);
            ChartObjects.DrawLine("r4 " + startIndex, pivotStartTime, r4, pivotEndTime, r4, Colors.SlateBlue, Espessura, LineStyle.Solid);
 
            ChartObjects.DrawLine("s1 " + startIndex, pivotStartTime, s1, pivotEndTime, s1, supportColor, Espessura, LineStyle.Solid);
            ChartObjects.DrawLine("s2 " + startIndex, pivotStartTime, s2, pivotEndTime, s2, supportColor, Espessura, LineStyle.Solid);
            ChartObjects.DrawLine("s3 " + startIndex, pivotStartTime, s3, pivotEndTime, s3, Colors.Yellow, Espessura, LineStyle.Solid);
            ChartObjects.DrawLine("s4 " + startIndex, pivotStartTime, s4, pivotEndTime, s4, Colors.Orange, Espessura, LineStyle.Solid);
 
 
            ChartObjects.DrawLine("m0 " + startIndex, pivotStartTime, m0, pivotEndTime, m0, pmedioColor, Espessura2, LineStyle.DotsRare);
            ChartObjects.DrawLine("m1 " + startIndex, pivotStartTime, m1, pivotEndTime, m1, pmedioColor, Espessura2, LineStyle.DotsRare);
            ChartObjects.DrawLine("m2 " + startIndex, pivotStartTime, m2, pivotEndTime, m2, pmedioColor, Espessura2, LineStyle.DotsRare);
            ChartObjects.DrawLine("m3 " + startIndex, pivotStartTime, m3, pivotEndTime, m3, pmedioColor, Espessura2, LineStyle.DotsRare);
 
            ChartObjects.DrawLine("m4 " + startIndex, pivotStartTime, m4, pivotEndTime, m4, pmedioColor, Espessura2, LineStyle.DotsRare);
            ChartObjects.DrawLine("m5 " + startIndex, pivotStartTime, m5, pivotEndTime, m5, pmedioColor, Espessura2, LineStyle.DotsRare);
            ChartObjects.DrawLine("m6 " + startIndex, pivotStartTime, m6, pivotEndTime, m6, pmedioColor, Espessura2, LineStyle.DotsRare);
            ChartObjects.DrawLine("m7 " + startIndex, pivotStartTime, m7, pivotEndTime, m7, pmedioColor, Espessura2, LineStyle.DotsRare);
 
            if (!ShowLabels)
                return;
 
            ChartObjects.DrawText("Lpivot " + startIndex, PP + "=" + pivot.ToString("0.00000"), index, pivot, vAlignment, hAlignment, Colors.White);
            ChartObjects.DrawText("Lr1 " + startIndex, "R1=" + r1.ToString("0.00000"), index, r1, vAlignment, hAlignment, resistanceColor);
            ChartObjects.DrawText("Lr2 " + startIndex, "R2=" + r2.ToString("0.00000"), index, r2, vAlignment, hAlignment, resistanceColor);
            ChartObjects.DrawText("Lr3 " + startIndex, "R3=" + r3.ToString("0.00000"), index, r3, vAlignment, hAlignment, Colors.Aqua);
            ChartObjects.DrawText("Lr4 " + startIndex, "R4=" + r4.ToString("0.00000"), index, r4, vAlignment, hAlignment, Colors.SlateBlue);
 
            ChartObjects.DrawText("Ls1 " + startIndex, "S1=" + s1.ToString("0.00000"), index, s1, vAlignment, hAlignment, supportColor);
            ChartObjects.DrawText("Ls2 " + startIndex, "S2=" + s2.ToString("0.00000"), index, s2, vAlignment, hAlignment, supportColor);
            ChartObjects.DrawText("Ls3 " + startIndex, "S3=" + s3.ToString("0.00000"), index, s3, vAlignment, hAlignment, Colors.Yellow);
            ChartObjects.DrawText("Ls4 " + startIndex, "S4=" + s4.ToString("0.00000"), index, s4, vAlignment, hAlignment, Colors.Orange);
 
 
        }
 
 
        private static DateTime CutToOpenByNewYork(DateTime date, TimeFrame timeFrame)
        {
            if (timeFrame == TimeFrame.Daily)
            {
                var hourShift = (date.Hour + 24 - 17) % 24;
                return new DateTime(date.Year, date.Month, date.Day, date.Hour, 0, 0, DateTimeKind.Unspecified).AddHours(-hourShift);
            }
 
            if (timeFrame == TimeFrame.Weekly)
                return GetStartOfTheWeek(date);
 
            if (timeFrame == TimeFrame.Monthly)
            {
                return new DateTime(date.Year, date.Month, 1, 0, 0, 0, DateTimeKind.Unspecified);
            }
 
            throw new ArgumentException(string.Format("Unknown timeframe: {0}", timeFrame), "timeFrame");
        }
 
        private static DateTime GetStartOfTheWeek(DateTime dateTime)
        {
            return dateTime.Date.AddDays((double)DayOfWeek.Sunday - (double)dateTime.Date.DayOfWeek).AddHours(-7);
        }
 
 
        public DateTime AddPeriod(DateTime dateTime, TimeFrame timeFrame)
        {
            if (timeFrame == TimeFrame.Daily)
            {
                return dateTime.AddDays(1);
            }
            if (timeFrame == TimeFrame.Weekly)
            {
                return dateTime.AddDays(7);
            }
            if (timeFrame == TimeFrame.Monthly)
                return dateTime.AddMonths(1);
 
            throw new ArgumentException(string.Format("Unknown timeframe: {0}", timeFrame), "timeFrame");
        }
 
    }
 
}

 


@ryanoia@gmail.com

ryanoia@gmail.com
22 Apr 2019, 03:08

Considerable changes - does that mean almost changing the code from scratch or a major overhaul? Would appreciate your assessment on this. Thanks.


@ryanoia@gmail.com

ryanoia@gmail.com
18 Apr 2019, 10:33

Possible?

I just need to know if this is possible or not so that I know if I am wasting time trying to do this or not. The code is simple, instead of take profit or stop loss in the executemarketorder, I want to change it to the price levels indicated in the price S/R indicator. 


@ryanoia@gmail.com

ryanoia@gmail.com
15 Apr 2019, 19:59

buying at support and selling on resistance

Hello Mr. Lime,

I noticed that your code is similar to what I want to achieve, except I'll get the support/resistance levels from this indicator - https://ctrader.com/algos/indicators/show/1467

Would you know how to code the bot so that it references those levels in that indicator?

Your assistance  would be great appreciated.

Thanks much.


@ryanoia@gmail.com

ryanoia@gmail.com
20 Aug 2018, 10:42

Yes that "" worked. I was testing it wrong so I thought it didn't work. 

Thanks for the response. 


@ryanoia@gmail.com

ryanoia@gmail.com
20 Aug 2018, 10:41

Already did. The first version of this was not async, just modifyposition, as may be observed in the first post above which is lengthy so I understand if nobody read that.

I wouldn't even read that myself again. hehe


@ryanoia@gmail.com