CT
ctid+customer-395444
7 follower(s) 0 following 845 subscription(s)
Topics
Replies

ctid+customer-395444
25 Jun 2022, 17:34

RE: RE: RE: RE:

ctid2032775 said:

amusleh said:

genappsforex said:

ctid2032775 said:

 A little bit strange is that as soon as I switch to .NET 6, run any bot and close the cTrader application the cTrader process is not terminated, as well.

I noticed that too, This behaviour eats Memory and CPU . Think they're forgetting to clean up/Close old threads.

Hi,

We can only help you if we were able to reproduce the issues you are facing, if we can't then there is no way for us to know what's going wrong.

 

Hi,

after quite a frustrating time I stopped development in ctrader and migrated the project to MetaTrader 5. The trading part is written in MQL, the machine learning part was developed as an external library in C# and there everything is working as expected (on the same environment (!)).

As this part is now finished I got curious and did some further investigation...

What I found out is that it's working in any Windows 10 Home environment (both on an Acer gaming notebook and in a virtual environment (VirtualBox)) but I never got it to work on Windows 10 Professional or Enterprise (both x64 clean installations)!

The problem is that the bot needs to run on a Minix Neo with Windows 10 Pro installed where it's not possible to "downgrade" to home edition (and even if it would be possible I wouldn't do this...).

Accordingly, I kindly ask you to verify possible reasons and keep me updated about the solution.

Many thanks and regards,
Christian

I think what would help the @Spotware crew is if you can record your desktop (or whatever) while reproducing the cTrader issue. This way, their team can see it actually happening.


@ctid+customer-395444

ctid+customer-395444
25 Jun 2022, 17:31

Yes.

Example:

System.Media.SystemSounds.Exclamation.Play();

 


@ctid+customer-395444

ctid+customer-395444
24 Jun 2022, 05:40 ( Updated at: 21 Dec 2023, 09:22 )

RE:

gennimatas said:

Following code is not playing on my win10 system after introduction of cTrader 4.2

Paths and files do exist.

Please advise.

Regards

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace testSound
{
    [Indicator(IsOverlay = false, AccessRights = AccessRights.FileSystem)]

    public class testSound : Indicator
    {

        [Parameter(DefaultValue = "tada")]
        public string wav { get; set; }

        protected override void Initialize()
        {
            IndicatorArea.MouseDown += IndicatorArea_MouseDown;
        }

        private void IndicatorArea_MouseDown(ChartMouseEventArgs obj)
        {
            var windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
            var path = System.IO.Path.Combine(windowsFolder, "Media", wav + ".wav");
            Print(path);
            // C:\WINDOWS\Media\tada.wav
            Notifications.PlaySound(path);
            // Notification: PlaySound of 'C:\WINDOWS\Media\tada.wav' failed. Exception message: 'Invalid URI: The URI is empty.'

            path = @"C:\Windows\Media\Ring01.wav";
            Print(path);
            // C:\Windows\Media\Ring01.wav
            Notifications.PlaySound(path);
            // Notification: PlaySound of 'C:\Windows\Media\Ring01.wav' failed. Exception message: 'Invalid URI: The URI is empty.'
        }

        protected override void OnDestroy()
        {
        }

        public override void Calculate(int index)
        {
        }

    }
}

 

If it helps, I use this instead:

System.Media.SystemSounds.Exclamation.Play();

and in Windows itself I assign the sound I want to the "Exclamation" sound from the Control Panel as follows:


@ctid+customer-395444

ctid+customer-395444
24 Jun 2022, 05:35

RE: RE:

Marin0ss said:

So another solution which would work for me is a snippet of code that stops the robot after the last 5 trades closed negative.

 

Here's a snippet to help you get started.

This assumes you've created an event method when a position is closed called "Positions_Closed":

 

private void Positions_Closed(PositionClosedEventArgs args)
{
	Position p1 = args.Position;
//in case there are multiple, you can narrow it down by symbol name and label
	if (p1.SymbolName == Symbol.Name && p1.Label == _positionLabel)
	{
		//Consecutive Losing Trades
		if (p1.NetProfit < 0)
			_numberOfConsecutiveLosingTrades += 1;
		else
			_numberOfConsecutiveLosingTrades = 0;
	}
//
// blah blah blah with other stuff you may need to do
//
// then stop the bot if it's greater than your threshold
    if (_numberOfConsecutiveLosingTrades >= 5)
        Stop();
}

 


@ctid+customer-395444

ctid+customer-395444
21 Jun 2022, 11:48 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

amusleh said:

Hi,

The cTrader Pips column shows the different in Pips between position entry price and current price.

If you add new volume to the position then the entry price of position will change, and for Pips it will use the new entry price.

That's how it's calculated on cTrader, so for:

What I mean by overall pips is if my positions are:

1) 10000 units of EURCAD @ 1.3547

2) 1000 units of EURCAD @ 1.3562

3) 1000 units of EURCAD @ 1.36701

and price is currently at 1.35835

cTrader will use 1.36701 as entry price and 1.35835 as current price, the difference will be position Pips, it doesn't take into account the previous entry prices.

That can't be totally accurate, because if you look at this capture:

by your last reply, the last entry price is 1.01315, but the position closed closed negative from the last entry, yet it says the overall trade was up 13.5 pips.

So I'm confused because it obviously does take into account the previous price points.

????


@ctid+customer-395444

ctid+customer-395444
20 Jun 2022, 12:09

RE:

amusleh said:

Hi,

So you are trying to calculate the Pips for positions that are partially closed or added?

If that's what you are looking to do then you can't, because the API doesn't give you the data for partially closed / added positions.

When you close part of a position or add more volume to it the history is not updated until you close the whole position, nor the positions closed / opened events are triggered.

 

 

 

But there's obviously some mathematical formula that's used because cTrader does it.

As I mentioned in my original post, I keep track of each position's volume and entry price that are added (eg, I have my own history), so I should be able to do it before the position is closed just like cTrader.

So, can't you look at cTrader's source code and tell me what formula it's using to do its live calculation? :-)

Thank you.

 


@ctid+customer-395444

ctid+customer-395444
20 Jun 2022, 11:37 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE: RE:

amusleh said:

firemyst said:

amusleh said:

Hi,

Can you tell me which column you are talking about? I can't find any overall Pips column in cTrader.

The "Pips" column as per the "Positions" and "History" tabs:

Thank you.

Hi,

The method I posted will give you the same value that you see on Pips columns with some fraction error due to rounding or delay.

There is no overall Pips, each position Pips is separate and it's not related to other positions.

 

I don't want the Position's pip value. That's the point I think you're missing or I'm not explaining well.

I want to know how that calculation is done because I want to have an indicator draw other lines at various on the chart with the correct amount of pips written on the line.

The only way I can currently do that is to drag the stop loss line and it will show me the number of pips depending on the price at the location.

Using p.pips only tells me the pips at the current closing price, not at other price levels on the chart, when I have a position with multiple scaled in positions.

Example:

 

 


@ctid+customer-395444

ctid+customer-395444
20 Jun 2022, 10:31

RE:

amusleh said:

Hi,

Can you tell me which column you are talking about? I can't find any overall Pips column in cTrader.

The "Pips" column as per the "Positions" and "History" tabs:

Thank you.


@ctid+customer-395444

ctid+customer-395444
18 Jun 2022, 15:39

If you close each position synchronously, it waits until one position is closed before it closes the next... so on and so forth.

So try closing all positions asynchronously. This way, you send all the close commands, and it's just up to the server to process them as fast as it can.

Example:

foreach (Position p in Positions)
                            {
                                ClosePositionAsync(p, (TradeResult r) =>
                                {
                                    if (r.IsSuccessful)
                                    {
                                        //... do what you have to
                                    }
                                    else if (!r.IsSuccessful)
                                    {
					//... do what you have to
                                    }
                                });
                            }

 


@ctid+customer-395444

ctid+customer-395444
17 Jun 2022, 11:25

RE:

amusleh said:

Hi,

Can you tell what do you mean by overall Pips? cTrader Pips column shows the amount of Pips for your Position which you can get via Pips property of a Position.

To calculate it programmatically you can subtract the current price from Position entry price:

        private double GetPositionPips(Position position)
        {
            var symbol = Symbols.GetSymbol(position.SymbolName);

            return Math.Round((position.TradeType == TradeType.Buy ? symbol.Bid - position.EntryPrice : position.EntryPrice - symbol.Ask) / symbol.PipSize, 1);
        }

 

What I mean by overall pips is if my positions are:

1) 10000 units of EURCAD @ 1.3547

2) 1000 units of EURCAD @ 1.3562

3) 1000 units of EURCAD @ 1.36701

and price is currently at 1.35835

I would like to know how to calculate the overall pips value that cTrader displays in the "Pips" column. cTrader shows roughly 24.9 pips profit despite being up 35.6 pips from position 1, 20.5 pips in position #2, -86 pips for position #3.

So how does it calculate 24.9 overall pips between the 3 positions?

Hope that better helps you understand what I'm looking for?

Thank you.


@ctid+customer-395444

ctid+customer-395444
29 May 2022, 13:57

If you know the symbol and gave the position a unique label, you could also look for it in the "HistoricalTrade" collection.

Example:

HistoricalTrade ht = History.FindLast(p1.Label, p1.SymbolName);


@ctid+customer-395444

ctid+customer-395444
29 May 2022, 13:55

Not sure if it can be done, but to access a chart object in a bot that's drawn from a bot, you would do something like this example if you're looking for a horizontal line:

ChartHorizontalLine obj = (ChartHorizontalLine)Chart.FindObject("the name you gave the line when you drew it");

 


@ctid+customer-395444

ctid+customer-395444
23 May 2022, 12:42 ( Updated at: 24 May 2022, 03:36 )

RE: RE: RE: RE: Discontinuous outputs

genappsforex said:

firemyst said:

Because both

((double)index)/3 == index/3

is false and

((double)index)/4 == index/4

is false.

So it always has a value in Result1 and not Result2 because Switch is always > 0:

if(Switch>0) Result1[index] = Bars[index].High;

Sorry to tell you but you're wrong.
Just run the indicator code i've posted and see for yourself.

 

Perhaps you have some Windows or .Net updates that haven't taken affect yet in cTrader? Reboot?

 


@ctid+customer-395444

ctid+customer-395444
22 May 2022, 13:36

RE: RE: Discontinuous outputs

genappsforex said:

amusleh said:

Hi,

The lines are discontinuous:

 

Discontinuous outputs can have empty or NAN values, and those NAN values will not be displayed on the chart.

Well that was my understanding also.
So Why does not my little progam above generate discontinuous Lines?

Because both

((double)index)/3 == index/3

is false and

((double)index)/4 == index/4

is false.

So it always has a value in Result1 and not Result2 because Switch is always > 0:

if(Switch>0) Result1[index] = Bars[index].High;

@ctid+customer-395444

ctid+customer-395444
30 Apr 2022, 19:47

RE:

shaahin69 said:

Hi, 

 

I am trying to implement break even when order is in profit. 

Say if I have positions open with 15 contracts, I wish to close 10 contracts only once position pips is greater than 2 and move the SL to break even. Then I want to specify a new TP for the amount of 5 pips.

I have found an example related to break even in cTrader cBot examples, however, I am still unsure how to take profit partially as well as setting a new TP.

Is following correct? 

 

var TP = 2;

if (position.Pips > TP)

{
ClosePosition(position, 10); // close 10 contracts 

var newTP = ??? // how do I set new TP for 5 pips from current price?

ModifyPosition(position, roundedBreakEvenLevel, newTP);

}

double newTP = (position.TradeType == TradeType.Buy ? Symbol.Ask + (5 * Symbol.PipSize) : Symbol.Bid - (5 * Symbol.PipSize));


@ctid+customer-395444

ctid+customer-395444
30 Apr 2022, 19:44

@Spotware?

Thank you.


@ctid+customer-395444

ctid+customer-395444
26 Apr 2022, 10:16

RE:

amusleh said:

Hi,

I did understood your point, what I was trying to explain was there is no way to accurately know when a tick will result in formation of a new bar.

Regarding your issue, you can do something like this:

 

Okay. Cool. Thanks for that and your sample code. I haven't looked at the sample code, but had another question -- with cTrader shouldn't it (or is it already) programmed up to open a new bar regardless of whether or not a tick comes through?

It it takes the timing of a tick to actually open a new bar, then hypothetically bars could open up halfway through their time period, or even not at all.

If it is set to open a new bar regardless of whether a tick or not happens, then the example I provided seems to illustrate a bug where ticks happen before the bar is actually opened.

Thank you.


@ctid+customer-395444

ctid+customer-395444
25 Apr 2022, 10:38

RE: RE:

instylereality2 said:

firemyst said:

I'm not sure your idea will work, as I believe the "OnTick" events only occur after OnStart has completed.

Obviously Spotware can confirm, but if that's the case, you'll have to redo your logic.

Yeah, I was feeling that this would be the case. A confirmation is needed on this for sure.

Any idea about how this could be achieved? Or isn't possible at all to have a live price checking mechanism in OnTick() that would be combined with OnStart() to complete a continues checking cycle??

Thank you! 

Why do you even need to wait in OnStart until something happens?

Just set a flag to false, and when it occurs in OnTick, set the flag to true.

Then check the flag in OnTick and when it's true, go through another branch of code.


@ctid+customer-395444

ctid+customer-395444
25 Apr 2022, 09:15

I'm not sure your idea will work, as I believe the "OnTick" events only occur after OnStart has completed.

Obviously Spotware can confirm, but if that's the case, you'll have to redo your logic.


@ctid+customer-395444

ctid+customer-395444
25 Apr 2022, 09:12

RE:

budda_dan2020 said:

Hi,

is the IAccount.StopoutLevel in % or just a proportion?

E.g. if my account has a stop out level as 30%, is the value of IAccountStopOutLevel 30 or 0.3?

 

kind Regards

Why not just print it out to see for yourself?

Eg:

Print("Stop out level: {0}", IAccount.StopoutLevel);

and then check the log tab to see what it says.


@ctid+customer-395444