Topics
13 May 2023, 06:02
 754
 6
03 May 2023, 00:03
 1183
 11
23 Feb 2023, 15:57
 644
 2
29 Jul 2022, 10:44
 691
 2
20 Jun 2022, 19:02
 1006
 5
19 Jun 2022, 21:47
 1121
 10
16 Jun 2022, 18:59
 791
 3
10 Nov 2021, 11:27
 0
 1776
 9
30 Oct 2021, 09:05
 1138
 2
Replies

m4trader4
14 Feb 2022, 11:29

RE: RE: RE: RE:

@Firemyst

if (psnCBS.StopLoss.GetValueOrDefault() != 0) doesnt work, CBot crashes

@ cAlgoBuddy

psnCBS.StopLoss.HasValue is working CBot is not crashing. 

 

Have to check when there is high volatility/Event

 

 

 

 

 


@m4trader4

m4trader4
14 Feb 2022, 11:19

RE: RE: RE:

cAIgoBuddy, Yesterday i could not find your reply, have ammended code according to Firemyst suggestions, i had to repost my reply second time

@Firemyst, Bars.BarOpened += Bars_BarOpened_StopLossMove; does excatly the same as you said moves the stoploss according to symbol as the parameters are different for each symbol

Positions.Find("", Symbol.Name); //return only the positions under the current symbol the bot instance is running under

Only issue is checking the public double CheckSLPositions() of all the positions before placing new orders, when there is high volatility/Event, as bars print very fast.

As you said lock does not seems to be a good solution, not for it

 

 

 

 

 

 

 


@m4trader4

m4trader4
13 Feb 2022, 18:52

RE:

This is the second time i am writing as the first one after posting dint appear

Hi Firemyst

Thanks for pointers, will amend the code.

The issue i think is when there is high volatility CheckSLPositions() is unable to lock the postions list. The CBot running on other symbols is doing the same opening new trades/moving stoploss/checking Stoploss.

Its about the thread safe

Regards

Ahmed


@m4trader4

m4trader4
19 Dec 2021, 15:29

Hi mohsabry.ms,

You cannot start/stop CBot through program.

The way out is use scheduler (Quartz) -> Message Queue (Nats) -> CBot

a. Configure CBot to be Nats Client

b. Have a counter in the CBot -> StartStop

c. Before placing order Check Counter StartStop

d. Through Quartz Scheduler (Nats Client) send message to Start or Stop

e. CBot (Nats client) receives the message set the counter StartStop accordingly

 

I found Nats to be easy to configure and fast, which has C# client not much of effort configure client. You can use other open source kafka etc

 

 

Ahmed

 

 

 


@m4trader4

m4trader4
19 Dec 2021, 15:09

RE: RE:

Tried using concurrent collections given up...


@m4trader4

m4trader4
19 Dec 2021, 15:06

RE:

Ahmad

Sure will do that.

I am trying to get the guppys ema's check using parallel/concurency using concurrent collections, appreciate if you could have a look at the code provide pointers for faster calculations.





   public string GuppyCheck(int bI, int Period, double CandleHigh, double CandleLow)
        {
            string RetGuppyCheck = "False";

            var GuppyResult = Indicators.ExponentialMovingAverage(Bars.ClosePrices, Period).Result.Last(Bars.Count - bI - 1);
            if ((GuppyResult <= CandleHigh && GuppyResult >= CandleLow))
            {
               RetGuppyCheck = "True";
            }
            else
                RetGuppyCheck = "False";

            return RetGuppyCheck;
        }

        public string ChartRG(int bI, double CandleHigh, double CandleLow)
        {
            // Print("BarIndex=" + bI + "=BarCount=" + Bars.Count);

            string ChartRGResult = "nEVT";

            var TempShortList = new List<string>();
            var TempLongList = new List<string>();

            TempShortList.Add(GuppyCheck(bI, 3, CandleHigh, CandleLow));
            TempShortList.Add(GuppyCheck(bI, 5, CandleHigh, CandleLow));
            TempShortList.Add(GuppyCheck(bI, 8, CandleHigh, CandleLow));
            TempShortList.Add(GuppyCheck(bI, 10, CandleHigh, CandleLow));
            TempShortList.Add(GuppyCheck(bI, 12, CandleHigh, CandleLow));
            TempShortList.Add(GuppyCheck(bI, 15, CandleHigh, CandleLow));

            TempLongList.Add(GuppyCheck(bI, 30, CandleHigh, CandleLow));
            TempLongList.Add(GuppyCheck(bI, 35, CandleHigh, CandleLow));
            TempLongList.Add(GuppyCheck(bI, 40, CandleHigh, CandleLow));
            TempLongList.Add(GuppyCheck(bI, 45, CandleHigh, CandleLow));
            TempLongList.Add(GuppyCheck(bI, 50, CandleHigh, CandleLow));
            TempLongList.Add(GuppyCheck(bI, 60, CandleHigh, CandleLow));

            var CountTempShortTrue = TempShortList.Count(item => item.Contains("True"));
            var CountTempLongTrue = TempLongList.Count(item => item.Contains("True"));

            //Print("CountTempShortTrue=" + CountTempShortTrue + "CountTempLongTrue" + CountTempLongTrue);




            if (CountTempShortTrue == 6)
            {
                //   Print("All 6 In");
                ChartRGResult = "EVT";
            }


            if (CountTempShortTrue == 6 && CountTempLongTrue == 6)
            {
                // Print("All B6 In R6 In");
                ChartRGResult = "EVT";
            }

            if (CountTempShortTrue == 6 && CountTempLongTrue >= 1 && CountTempLongTrue < 6)
            {
                //Print("All B6 In R6 In");
                ChartRGResult = "nEVT";
            }


            return ChartRGResult;
        }

 


@m4trader4

m4trader4
16 Dec 2021, 20:32

RE:

Ahmad

Thanks for the response, appreciate it.

I was doing trial and error to avoid the race condition, so there is a mix of task run and generous use of parallel. To extent was successfull, but was not confident to run  24/5.

Have rewritten the block after you comment about API is not thread safe. Is there any thoughts to make the API thread safe?

Regards

Ahmed


@m4trader4

m4trader4
14 Dec 2021, 21:52

This happens when the

1. The Market is volatile or at events

2. When the new bar formed is with gap

3. At time of opening or closing

You can check this for gold (13:00 GMT) for a range bar/renko brick size of 10 pips, Dow (14:30 GMT) range bar/renko brick size of 10 pips and Nasdaq (14:30 GMT) for range bar/renko brick size of 10 pips 


@m4trader4

m4trader4
12 Nov 2021, 08:52 ( Updated at: 21 Dec 2023, 09:22 )

RE: RE:

Dear Panagiotis

I found this info from your website 

Does the info of server hosting in Equinix LD5 is current?

 

 


@m4trader4

m4trader4
10 Nov 2021, 12:52

RE:

Dear Panagiotis,

Appreciate your quick response, got confused with your last reply

My current latency

Proxy = London-8

Proxy Latency = 11ms

Server Latency = 17ms

CtraderClient --11ms--> Proxy ---tunnel 6ms ---> Server 

So  in totality its 17ms latency for the Ctrader Client.

CtraderClient --17ms--> Server

So how do i choose a VPS provider if the proxy latency is 2ms but the tunnel to server is 10 ms.

While querying Autonomous system number (ASN)  Proxy is in DigitalOcean AS14061, so is it safe assumption that the server is also with DigitalOcean AS14061

Regards

Ahmed

 

 

 

 

 


@m4trader4

m4trader4
10 Nov 2021, 12:22

RE:

Dear Panagiotis,

Why there is latency difference between proxy and server? What i have understood from the forum threads, CTrader client is connected to server for the actual trades to execute, matching the bid and ask. Proxy is price display (ask and bid), historical data

Regards

Ahmed

 


@m4trader4

m4trader4
10 Nov 2021, 12:03

RE:

Thanks for the reply Panagiotis,

As written in the earlier thread, Have been using the FIX api hostname to check the connectivity, but server hostname is not visible to check the same. There is latency difference between proxy and server latency,


@m4trader4

m4trader4
10 Nov 2021, 11:47

Attached is code snippet from my code. There are lot of other parameters.

 

 
 
  protected override void OnStart()
        {
           Bars.BarOpened += Bars_BarOpened;
        }
 
 
 
 
 
 private void Bars_BarOpened(BarOpenedEventArgs obj)
        {
		
			 var bars = obj.Bars;
			 
			  double AOC1O = bars.OpenPrices.Last(1);
              double AOC1H = bars.HighPrices.Last(1);
              double AOC1L = bars.LowPrices.Last(1);
              double AOC1C = bars.ClosePrices.Last(1);
			  
					double AOC1O = bars.OpenPrices.Last(1);
                    double AOC1H = bars.HighPrices.Last(1);
                    double AOC1L = bars.LowPrices.Last(1);
                    double AOC1C = bars.ClosePrices.Last(1);

                    double AOC2O = Bars.OpenPrices[Bars.Count - 3];
                    double AOC2H = Bars.HighPrices[Bars.Count - 3];
                    double AOC2L = Bars.LowPrices[Bars.Count - 3];
                    double AOC2C = Bars.ClosePrices[Bars.Count - 3];


                    double AOC3O = Bars.OpenPrices[Bars.Count - 4];
                    double AOC3H = Bars.HighPrices[Bars.Count - 4];
                    double AOC3L = Bars.LowPrices[Bars.Count - 4];
                    double AOC3C = Bars.ClosePrices[Bars.Count - 4];
			  
			  
			
			  
			  if (AOC2L > AOC1L )
                    {
						//Place Sell Orders
					}
		
			if (AOC1H > AOC2H)
                    {
					
					//Place Buy Order
					}
		
		
		}


 


@m4trader4

m4trader4
12 Oct 2021, 17:56

Ahmad,

Thanks for the replies. Appreciate your support.

Is there any thoughts to provide detailed usage statistics. Its very usefull for optimization, capacity management for hosting in VPS.

On a different note, what is the hostname/ipaddress to check the proxy latency and server latency from the VPS service provider before signing up. 

In FIX Api there is a host h50.p.ctrader.com is this the proxy hostname?

Thanks

Ahmed


@m4trader4

m4trader4
11 Oct 2021, 16:16

RE:

Hi

Its deleting, due to logic in OnStop() its not deleting, my mistake


@m4trader4

m4trader4
09 Oct 2021, 12:07

RE:

Hi Ahmad

if it is only 1-3 charts with CBot running the OnStop() is executed. If there more than 15 charts with Bot running OnStop() doesnt get executed, when CTrader is closed.

Regards

Ahmed

 


@m4trader4

m4trader4
09 Oct 2021, 12:01

RE:

Hi Ahmad

Market range order is either filled or not filled, there is no partial fill so PendingOrders_Filled will not help. I am looking at intermediate state : 

Order Executed - Status Cancelled

Order Not Executed - Status Cancelled


@m4trader4

m4trader4
03 Oct 2021, 11:05

RE: RE:

v.fiodorov83 said:

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

I have cut and pasted my code Use the function and place the orders accordingly.

private int CheckPositions(TradeType TTtype)
        {
            var positionsCBO = Positions.FindAll("", Symbol.Name, TTtype);
            return (positionsCBO.Length);
        }


=============================================================

 if (CheckPositions(TradeType.Sell) == 0)
                        {
                           // Place order
                        }

 if (CheckPositions(TradeType.Buy) == 0)
                        {

// Place Order
                        }

 


@m4trader4

m4trader4
03 Oct 2021, 10:33

Hi

Sorry for delayed reply.

The scenario:

I place Buy Pending orders #1 with Price 10 with stop limit range 00.00 - 00.40 pips. The order is executed and not filled due to limit range (out of range). As there were no sellers to sell in the limit range ( 00.00 - 00.40), so the order status is cancelled. 

With the PendingOrderEvents cancelled event, the details of the order (Qty, SL, TP ) are captured and new marketrange order is executed. So far its good. The Buy Pending Order is executed, the order is unfilled (Cancelled), then improvised with marketrange order and executed (Filled).

 

There are pending Buy orders which are placed manually/cbot, When these orders are cancelled (Which are not executed) using "X" button in the order tab, the PendingOrderEvents is executed with a cancelled event status. Which should not happen.  

My logic or intention is the PendingOrdersEvents.Cancelled should be called only for the executed orders not for "X" button cancelled orders.

Hope i am able to explain better.

 

 

 


@m4trader4