Replies

PanagiotisCharalampous
21 Aug 2024, 14:50

RE: RE: Bars can only fetch latest 200 bars

raypang said: 

PanagiotisCharalampous said: 

Hi there,

You can use Bars.LoadMoreHistory() method to load more bars.

Best regards,

Panagiotis

protected override void OnStart()

{

    Print(Bars.Count); //200

    Bars.LoadMoreHistory();

    Print(Bars.Count); //200

}

it seems not work

Can you tell us the broker and the symbol?


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 14:45

RE: RE: I need help to close the reverse position after the reset

dr.erick.rd said: 

PanagiotisCharalampous said: 

Hi there,

Please share the complete cBot code since it is not possible understand everything you are doing just from a snippet.

Best regards,

Panagiotis

Hello. The only thing I really want is for my cTrader account to only allow operations in one direction and when I open an operation, the ones in the opposite direction are closed. I used to have that type of account but now they all allow hedging.

Hi there,

Here is an example

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class CloseOpposite : Robot
    {

        protected override void OnStart()
        {
            Positions.Closed += Positions_Closed;
        }

        private void Positions_Closed(PositionClosedEventArgs obj)
        {
            foreach (var position in Positions.Where(p => p.TradeType != obj.Position.TradeType))
            {
                position.Close();
            }
        }

        protected override void OnTick()
        {
            // Handle price updates here
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 14:40

Hi eynt,

There is no such feature unfortunately.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 06:45

RE: RE: cBot stopped on it's own

nickythedegen said: 

PanagiotisCharalampous said: 

Hi there,

Can you please also share the cBot's log?

Best regards,

Panagiotis

Hi there,

This message appears when the cBot calls the OnStop() method. Please check if you call this method in your code.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 06:44

RE: cTrader Desktop 5.0.28 Release Notes

ncel01 said: 

Given the absence of any clarifications, I will assume that the following has been announced by mistake:

The following issues were addressed

  • Wrong Account.BrokerName and Account.Number for a bot with cloud instance

Hi ncel01,

Sorry for the delay, I had to do some research for this, it seems this has not been delivered yet. It's fixed on the cAlgo side but the server team needs to do some work as well.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 06:12

Hi there,

You can use Bars.LoadMoreHistory() method to load more bars.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 05:16

RE: RE: RE: RE: RE: Account.Margin not correct : Unacceptable

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

PanagiotisCharalampous said: 

ncel01 said: 

?

This issue has been fixed, it's been a while. I cannot reproduce it. Make sure you download historical data when you backtest.

 

Hi Panagiotis,

The values I get for the account margin are still not matching while backtesting the code above.
Are you backtesting an index? Probably not.

I selected the historical data, as suggested.
However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

I checked this with both Varianse and Pepperstone (using historial data).
Below is the backtest output with Varianse.

Hi ncel01,

Yes I do

 

However, the account and symbol currency is the same (USD) and still I am getting different results when selecting/unselecting this option. Why?

The functionality should work correctly when the option is checked. We are checking why it is not working when unselected and the quote currency matches the account currency. In the meanwhile, keep it checked.

 

Panagiotis,

The functionality should work correctly when the option is checked.

How come, when my screenshot clearly shows that Account.Margin is returning 0 even with an open position?
Did you check this with some other accounts/brokers (apart from Spotware)? If not, can you please double-check this?

Thanks.

Hi ncel01,

It works fine on Variance as well. 

Please send a full screenshot like the above, so that we can understand what you are doing


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 05:04

Hi there,

Have a look at the sample below, you might find it helpful.

https://github.com/spotware/OpenApiPy

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
21 Aug 2024, 05:01

Hi there,

Please share the complete cBot code since it is not possible understand everything you are doing just from a snippet.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 07:33

RE: RE: It seems Bars.LoadMoreHistory() has been recently broken and doesn't work

Waxy said: 

firemyst said: 

Have you considered that there might not be any more history to be loaded, especially if you're not scrolling to the left on the charts? 

See this thread:

https://ctrader.com/forum/cbot-support/38020/

 

Hello Firemyst,

Thanks for your reply.

This function obviously has changed its behavior, because I had an indicator and source control of it and it had working fine for a long time, debugging it led me to find this problem. Regardless of the broker or pair it returns zero and another user had this issue too but check more on this.

See video attached, first it counts bars without using the function on AUDNZD, then I run it again using the function, it turns into a locked refresh loop (doesn't even print the bars until after it loads the data, doesn't even print the initial bar count), at the end it does increase the number of bars but the function still returns zero.

Before this problem, we were able to control how many bars to load in a simple while loop synchronously without issues.

(9+) cTrader - 2024-08-19_23-47-08 - TechSmith Screencast

Regards,
 

Hi Waxy,

The behavior is as expected on an indicator. As soon as more bars are loaded the indicator needs to be reinitialized and recalculated. Therefore this leads to a loop until all bars are loaded. Probably you are comparing this with the way it behaves in a cBot which is a different behavior.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 05:01

RE: Spread v2

YesOrNot2 said: 

Better This :

using System;using System.Collections.Generic;using System.Linq;using System.Text;using cAlgo.API;using cAlgo.API.Collections;using cAlgo.API.Indicators;using cAlgo.API.Internals;namespace cAlgo{    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]    public class SpreadPressure : Indicator    {        [Output("SpredResult", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "White", Thickness = 1)]        public IndicatorDataSeries SpredResult { get; set; }        private Ticks tick;        private Bars barstick;        protected override void Initialize()        {            tick = MarketData.GetTicks();            barstick = MarketData.GetBars(TimeFrame.Tick);            while (barstick.OpenTimes[0] > Bars.OpenTimes[0])                barstick.LoadMoreHistory();        }        public override void Calculate(int index)        {            var indexTf = GetIndexByDate(Bars.OpenTimes.Last(0));            SpredResult[index] = (tick[indexTf].Ask - tick[indexTf].Bid) / Symbol.PipSize;        }        private int GetIndexByDate(DateTime date)        {            var bars = MarketData.GetBars(TimeFrame.Tick);            for (var i = bars.OpenTimes.Count - 1; i >= 0; i--)            {                if (bars.OpenTimes[i] <= date)                {                    return i;                }            }            return -1;        }    }}

You can also use Symbol.Spread


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 05:01

RE: Spread V2

YesOrNot2 said: 

Better this : 
 

using System;using System.Collections.Generic;using System.Linq;using System.Text;using cAlgo.API;using cAlgo.API.Collections;using cAlgo.API.Indicators;using cAlgo.API.Internals;namespace cAlgo{    [Indicator(IsOverlay = false, AccessRights = AccessRights.None)]    public class SpreadPressure : Indicator    {        [Output("SpredResult", PlotType = PlotType.Line, LineStyle = LineStyle.LinesDots, LineColor = "White", Thickness = 1)]        public IndicatorDataSeries SpredResult { get; set; }        private Ticks tick;        private Bars barstick;        protected override void Initialize()        {            tick = MarketData.GetTicks();            barstick = MarketData.GetBars(TimeFrame.Tick);            while (barstick.OpenTimes[0] > Bars.OpenTimes[0])                barstick.LoadMoreHistory();        }        public override void Calculate(int index)        {            var indexTf = GetIndexByDate(Bars.OpenTimes.Last(0));            SpredResult[index] = (tick[indexTf].Ask - tick[indexTf].Bid) / Symbol.PipSize;        }        private int GetIndexByDate(DateTime date)        {            var bars = MarketData.GetBars(TimeFrame.Tick);            for (var i = bars.OpenTimes.Count - 1; i >= 0; i--)            {                if (bars.OpenTimes[i] <= date)                {                    return i;                }            }            return -1;        }    }}

You can also use Symbol.Spread


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:56

Hi Waxy,

Can you please also share symbol and timeframe?

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:52

Hi there,

Can you please also share the cBot's log?

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:51

Hi there,

I don't think anybody will write the strategy for you for free. If you need professional assistance, feel free to contact a consultant

https://ctrader.com/consultants/

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:46

Hi there,

This happens because you are using the current open bar value in your conditions. The value of the current open bar can change by the time the bar closes, leading to several false signals. Try checking closed bars only e.g.

  if ((_fastTimeSeriesMovingAverage.Result.Last(2) < _slowTimeSeriesMovingAverage.Result.Last(2) && _fastTimeSeriesMovingAverage.Result.Last(1) > _slowTimeSeriesMovingAverage.Result.Last(1))

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:43

Hi there,

Can you please share more information? Why do you think you have sufficient funds? What is the volume you are trying to trade, what is your leverage and what is your balance?

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:39

Hi there,

Unfortunately the source code for these methods is not available.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:38

Hi there,

It would be better to contact the tool's developer regarding such questions.

Best regards,

Panagiotis


@PanagiotisCharalampous

PanagiotisCharalampous
20 Aug 2024, 04:36

RE: RE: How to find a specific pending market order?

rick2010 said: 

PanagiotisCharalampous said: 

Hi there, 

Pending orders are only limit, stop and stop limit orders. A market order is not a pending order.

Best regards,

Panagiotis

MetaTrader has a way to find orders before they actually become an open position. I need to do the same with cTrader. If I put on several async market orders all at once I need to be able to check if they've been filled otherwise I get duplicates. I don't want to use callbacks. I need to be able to look them up by their custom label. Something like my example:

            foreach(Order order in SomeListOfUnfilledOrders) {           

               if(order.Label == “order123”)
                   return true;        
 

Then you need to store this information on your side e.g. add market orders in a collection and remove them only after you have received an execution response from the server.


@PanagiotisCharalampous