v.fiodorov83
v.fiodorov83's avatar

Info

Username:v.fiodorov83
Name:v.fiodorov83
Member since: 24 Jul 2019

About

None

Signature

None

Last Forum Posts

@Stop Loss trigger for cancel current PendingOrder:  14 Sep 2021, 17:38


amusleh said:

There are Filled, Modified, and Canceled events for PendingOrders you can use, and there are similar events of positions like Closed, Modified, and Opened.

Thanks. Apparently I'll have to write a counter. If the buy-stop is full, then the counter will be 1, and a new buy-stop will open if the counter is 0

@Closing order at current 4h closing:  13 Sep 2021, 13:15


amusleh said:

Hi,

You have to give the amount of time of that time frame and then you can check the amount of time passed since the bar opened:

using cAlgo.API;
using System;
using System.Globalization;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        private TimeSpan _barsTimeDiff;

        [Parameter("Bars Time Diff", DefaultValue = "04:00:00")]
        public string BarsTimeDiff { get; set; }

        protected override void OnStart()
        {
            if (!TimeSpan.TryParse(BarsTimeDiff, CultureInfo.InvariantCulture, out _barsTimeDiff))
            {
                Print("Invalid Bars Time Diff");
            }
            else
            {
                // Subtract 1 minute from your provided time amount
                _barsTimeDiff -= TimeSpan.FromMinutes(-1);

                Timer.Start(1);
            }
        }

        protected override void OnTimer()
        {
            Timer.Stop();

            foreach (var position in Positions)
            {
                var positionEntryBarIndex = Bars.OpenTimes.GetIndexByTime(position.EntryTime);

                // You can add more close conditions on this if statment if you want to by using && and ||
                if (Server.Time >= Bars.OpenTimes[positionEntryBarIndex].Add(_barsTimeDiff))
                {
                    ClosePosition(position);
                }
            }

            Timer.Start(1);
        }
    }
}

Ohh, cool!) Thank you. It woks!

Can I use a hardcoded parameter like (GetCurrentTimeFrime) instead of the user input 04:00:00? So that this timer is taken based on the currently selected timeframe on the chart.

[Parameter("Bars Time Diff", DefaultValue = "04:00:00")]
        public string BarsTimeDiff { get; set; }

@Stop Loss trigger for cancel current PendingOrder:  10 Sep 2021, 22:19


Hello good people!

Please, help!

There is a task to open buy-stop orders at the initial one price.

One pending order at a specific price has been filled in the OnTick () Method.

How to make the logic in which the 2nd buy-stop order is not placed until the first one hits the stop-loss, only after that

@Closing order at current 4h closing:  09 Sep 2021, 13:38


amusleh said:

Hi,

You can use timer and check if the position entry bar is closed or not, if a new bar is opened then you can close your position, here is an example:

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        protected override void OnStart()
        {
            Timer.Start(1);
        }

        protected override void OnTimer()
        {
            Timer.Stop();

            var index = Bars.Count - 1;

            foreach (var position in Positions)
            {
                var positionEntryBarIndex = Bars.OpenTimes.GetIndexByTime(position.EntryTime);

                if (positionEntryBarIndex < index)
                {
                    ClosePosition(position);
                }
            }

            Timer.Start(1);
        }
    }
}

It iterates over all of your open positions every second.

Great thanks!

Almost everything works, but Can I add a conditions?

1. I have the logic of closing positions at a specific price also inside the current H4 candlestick, in the OnTick () method. And now they are ignored and only closed by timer

2. How to make the position close exactly at the end of the candle at 03:59:59, and not at the beginning of the next one. The problem is that the next one can open with a gap.

@Closing order at current 4h closing:  08 Sep 2021, 19:42


Hello everybody!

I open a trade in the current 4H candle. How can I write a code that will close my position exactly in the same 4H candle at its closing?

@Placing Buy/Sell-stop orders on candle opening #2:  06 Sep 2021, 17:26


Hi everyone!

This my second attempt to post here, for some reason did not work
Can't figure it out with cTrader library, poor description for me.
Therefore, please help. The tasks are pretty simple

How can I write a code that opens 1 buy-stop order and at the same time 1 sell-stop order that will be placed at a specified distance from the user in pips at the opening of each new candle.

For example, the user set the parameter to 1 pip and the robot simultaneously opens buy-stop and sell-stop at a distance of 1 pip from the opening price of each new candle

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.

No uploaded.