Topics
13 May 2023, 06:02
 876
 6
03 May 2023, 00:03
 1366
 11
23 Feb 2023, 15:57
 782
 2
29 Jul 2022, 10:44
 831
 2
20 Jun 2022, 19:02
 1153
 5
19 Jun 2022, 21:47
 1331
 10
16 Jun 2022, 18:59
 923
 3
10 Nov 2021, 11:27
 0
 2078
 9
30 Oct 2021, 09:05
 1359
 2
Replies

m4trader4
20 Jun 2022, 17:07

RE:

Dear Ahmad

Let me rephrase

I have 2 screens 1 and 2

in Screen 1 CTrader Main window is running

In Screen 2, 5 different symbols(A,B,C,D,E) running on child windows of CTrader with cBot running with a pop up of form (Yes/No) topmost=true through a button click,  subscribed to Form's public event.

on symbol (A) i click button FORM pops up, then i click on Symbol (B), the FORM of symbol A vanishes, till i click on Main CTrader window to get it back as TOPMOST.

I suppose the FORM is running on the Main CTrader window thread not on the Symbol A or Symbol B thread.

The same was working perfectly fine in 4.1

 


@m4trader4

m4trader4
17 Jun 2022, 08:45

RE:

By adding null its working, dint understand why?

if (psn != null && psn.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal) && psn.TradeType == TradeType.Sell && psn.Comment.Contains("AO") && !string.IsNullOrEmpty(psn.Comment))


@m4trader4

m4trader4
04 Jun 2022, 04:19

After the i got update to 4.2.8.5759 its working

 


@m4trader4

m4trader4
01 Jun 2022, 20:36

RE: RE: RE:

After closing trades through command line (Nats Client) then stopping the cBot get error "aborted by timeout". It doesnt even print the statement of execution.

There is no timeout error if cBot is closed without closing/or placing trades.

 

 protected override void OnStop()
        {
            Print("on stop executed");

            GlobalBroadCastConnection.Close();
            Print("Connection Closed =" + GlobalBroadCastConnection.IsClosed());
            // Handle cBot stop here
        }

 


@m4trader4

m4trader4
01 Jun 2022, 19:42

RE: RE:

Why dint the usdjpy trade got close?


@m4trader4

m4trader4
01 Jun 2022, 19:41

RE:

Ahmad

am on version 4.2.5.5087

I executed your code. It worls only when only one instance of cBot is running on a symbol. 

 

1. Run the cBot on all symbols

2. place trade in combination of manual and cbot 

Not all the trades are closed

Regards

 

 


@m4trader4

m4trader4
01 Jun 2022, 11:35

RE:

Nats Server is not running. First start the Nats server with default options then start the cBot.

To check whether server is running use

cmd window1> Nats-subs.exe Test 

Listening on [Test]

 

cmdwindow2>Nats-pub.exe Test msg1

 

On the cmdwindow1 you should get the following message

Listening on [Test]
[#1] Received on [Test]: 'msg1'

 

 

 

 


@m4trader4

m4trader4
31 May 2022, 13:54

RE:

Let me know what is required from my end to reproduce the issue? all the cBots are not working in 4.2 this has been a show stopper for me

 


@m4trader4

m4trader4
31 May 2022, 13:48

RE:

Ahmad

Close trade works only once , second time it doesnt work. Were you able to reproduce the issue?

 

 

 

   // Alternatively, create an asynchronous subscriber on subject foo,
            // assign a message handler, then start the subscriber.   When
            // multicasting delegates, this allows all message handlers
            // to be setup before messages start arriving.
            IAsyncSubscription sAsync = c.SubscribeAsync("foo");
            sAsync.MessageHandler += h;
            sAsync.Start();

 

 

 


@m4trader4

m4trader4
30 May 2022, 17:40

Check the thread, you need change some of the trade operations parameters in bot, it should work

 


@m4trader4

m4trader4
30 May 2022, 17:34

RE: RE:

Using the same concept there are lot interactions happening between other bots for sharing parameters or trades


@m4trader4

m4trader4
30 May 2022, 17:32

RE:

Code is huge and would refrain from sharing. Could you please let me how to debug or what the message indicates

 


@m4trader4

m4trader4
30 May 2022, 17:29

RE:

Ahmad

Attached code

You need install NATS www.nats.io, 

1. Start Nats server from command pompt nats-server.exe

2. download Nats Cli Client https://github.com/nats-io/natscli/releases/download/v0.0.33/nats-0.0.33-windows-amd64.zip

3. Start cBot

4. Manually or through cBot place trades

5. Go to Nats client directory cmd> nats-pub.exe BroadCast<AccountNumber>Renk0 Renko0,CloseTrade,<All>

6. Go to Nats client directory cmd> nats-pub.exe BroadCast<AccountNumber>Renk0 Renko0,CloseTrade,<symbolname>

7. Repeat steps 4-6

 

There are other trade operations and change of parameters performed using NATS message that will be invoked using BeginInvokeOnMainThread()

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;
using NATS.Client;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class NatsTestV1 : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        private string GlobalSymbolName;
        #region nats
        public IAsyncSubscription GlobalSchedulersub;
        public IAsyncSubscription GlobalBroadCastsub;
        public IConnection GlobalNormalConnection;
        public IConnection GlobalBroadCastConnection;
        public static string GlobalScheduleSubscribeMsg;
        public static string GlobalSubscribeBroadcastMsg;
        public static string GlobalPublishAlertSubject;
        public static string GlobalSchedulerMessageWriteFile;


        #endregion
        public void ReadBroadCastmsg(string subjj)
        {

            Options opts = ConnectionFactory.GetDefaultOptions();
            Options.ReconnectForever = 1;
            opts.Url = Defaults.Url;
            opts.Verbose = true;
            opts.AllowReconnect = true;
            GlobalBroadCastConnection = new ConnectionFactory().CreateConnection(opts);

            GlobalBroadCastsub = GlobalBroadCastConnection.SubscribeAsync(subjj);
            GlobalBroadCastsub.MessageHandler += BroadCastsub_MessageHandler;
            GlobalBroadCastsub.Start();
            Print(Symbol.Name + "::" + DateTime.UtcNow.ToString("HH:mm:ss.ffff") + "::" + subjj);

        }



        private void BroadCastsub_MessageHandler(object sender, MsgHandlerEventArgs e)
        {

            var msg = Encoding.UTF8.GetString(e.Message.Data);

            Print("NatsMessage : " + DateTime.UtcNow.ToString("HH:mm:ss:fff") + ":" + e.Message.Subject + ":" + msg);
            //var SchedulerMessage = msg.Split(',');

            var SchedulerMessage = msg.Split(new char[]
            {
                ','
            });



            if (SchedulerMessage[0].Equals("Renko0", StringComparison.CurrentCultureIgnoreCase) && SchedulerMessage[1].Equals("CloseTrade", StringComparison.CurrentCultureIgnoreCase) && (SchedulerMessage[2].Equals("All", StringComparison.CurrentCultureIgnoreCase) || SchedulerMessage[2].Equals(GlobalSymbolName, StringComparison.CurrentCultureIgnoreCase)))
            {
                Print("StringCompare CLoseTrade");
                // BeginInvokeOnMainThread(() =>

                try
                {
                    ReadBroadCastCloseTrade(GlobalSchedulerMessageWriteFile, SchedulerMessage);

                }
                catch (Exception ex)
                {

                    Print("exep close trade=" + ex.Message);
                }


                //);
            }


          


        }

        public void ReadBroadCastCloseTrade(string SchMsgFile, string[] SchedulerMessage)
        {
            //String SchedulerMessageStatusWrite = "";
            //string SchedulerMessageStatusDisplay = "";
            //SchedulerMessageStatusDisplay = DateTime.UtcNow.ToString("HH:mm:ss") + ":" + SchedulerMessage[0] + ":" + SchedulerMessage[1];
            //SchedulerMessageStatusWrite += SchedulerMessageStatusDisplay;
            Print("ReadBroadCastCloseTrade executed..");

            try
            {

                BeginInvokeOnMainThread(() =>
                {

                    var positionsCBS = Positions.ToArray();


                    Print("Yes message processed");
                    foreach (var psnCBS in positionsCBS)
                    {

                        Print("BuySell Positon= " + psnCBS.SymbolName);
                        if (psnCBS.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal))
                        {

                            ClosePositionAsync(psnCBS, CallBackClosePositionAsync);
                        }


                    }


                });



            }
            catch (Exception ex)
            {
                Print("beginInvokeclose=" + ex.Message);

            }








            //var positionsCBS = Positions.FindAll("", Symbol.Name);


            //File.WriteAllText(GlobalSchedulerMessageWriteFile + Symbol.Name + SchedulerMessage[0] + SchedulerMessage[1] + DateTime.UtcNow.ToString("ddMMyyyyHHmmssfff") + ".csv", Symbol.Name + SchedulerMessageStatusWrite);
        }

        private void CallBackClosePositionAsync(TradeResult tradeResult)
        {


            if (!tradeResult.IsSuccessful)
            {
                ClosePositionAsync(tradeResult.Position, CallBackClosePositionAsync);
            }

        }

        protected override void OnStart()
        {
            GlobalSymbolName = Symbol.Name;
            var SubscribeBroadcastMsg = "BroadCast" + Account.Number + "Renko0";
            ReadBroadCastmsg(SubscribeBroadcastMsg);
        }

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

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

 


@m4trader4

m4trader4
29 May 2022, 20:13

RE:

Even with the following its the same

 

 public void CLoseTrade(string SchMsgFile, string[] SchedulerMessage)
        {
            
            Print("ReadBroadCastCloseTrade executed..");

            try
            {
                
                BeginInvokeOnMainThread(() =>
                {

                    var positionsCBS = Positions.ToArray();


                    Print("Yes message processed");
                    foreach (var psnCBS in positionsCBS)
                    {

                        Print("BuySell Positon= " + psnCBS.SymbolName);
                        if (psnCBS.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal))
                        {

                            ClosePositionAsync(psnCBS, CallBackClosePositionAsync);
                        }


                    }


                }) ;



            }
            catch (Exception ex)
            {
                Print ("beginInvokeclose=" + ex.Message);

            }

           
        }

 


@m4trader4

m4trader4
28 May 2022, 05:28

RE:

Dear Ahmad

When is the resolution expected

 

 


@m4trader4

m4trader4
25 May 2022, 16:44

RE:

m4trader4 said:

Dear Ahmad

Could you please provide a Button example with button += subscribe and Chart.MouseDown += Chart_MouseDown;

I have onclick (Chart.MouseDown += Chart_MouseDown) to get the OHLC of bar and on button click place order (PlaceStopOrderAsync) buy on High or sell on low.

The same cBot is running on 2 or same timeframe, when a trade operation (Buy/Sell) is performed through Button Buy or Button Sell, trade performing cBot freezes after placing order.

Thanks

Ahmed

 

Chart.MouseDown += Chart_MouseDown -> get the bar index  

private void Chart_MouseDown(ChartMouseEventArgs obj)
        {

            if (obj.BarIndex < Bars.Count && GlobalLock == false)
            {
                Print("On Chart Price: " + obj.YValue + "=BarIndex=" + obj.BarIndex + "=TimeValue=" + obj.TimeValue);

                GlobalbI = Convert.ToInt32(obj.BarIndex);

                GlobalC1O = Bars.OpenPrices[GlobalbI];
                GlobalC1H = Bars.HighPrices[GlobalbI];
                GlobalC1L = Bars.LowPrices[GlobalbI];
                GlobalC1C = Bars.ClosePrices[GlobalbI];
                GlobalC1V = Bars.TickVolumes[GlobalbI];

                CandleCalc(GlobalbI, GlobalC1O, GlobalC1H, GlobalC1L, GlobalC1C);

            }



        }

 


@m4trader4

m4trader4
25 May 2022, 06:28

RE: RE: RE:

Dear Ahmad 

The above code is working.

Could you please provide statements to use for the following as previous used statements are not working. I dont understand why?

  1. Find and Close ALL symbols with trade type BUY and trade type SELL positions whether opened by same cBot or any other cBot or Manually

ClosePositionAsync(positions BUYand SELL)

  1. Find and Close ALL symbol with trade type BUY positions whether opened by same cBot or any other cBot or Manually

ClosePositionAsync(positions BUY)

  1. Find and Close ALL symbol with trade type SELL positions whether opened by same cBot or any other cBot or Manually

ClosePositionAsync(positions SELL)

  1. Find and Close SPECIFIC symbols with trade type BUY and trade type SELL positions whether opened by same cBot or any other cBot or Manually

ClosePositionAsync(positions BUYand SELL)

  1. Find and Close SPECIFIC symbol with trade type BUY positions whether opened by same cBot or any other cBot or Manually

ClosePositionAsync(positions BUY)

  1. Find and Close SPECIFIC symbols with trade type SELL positions whether opened by same cBot or any other cBot or Manually

ClosePositionAsync(positions SELL)

  1. Find and Cancel ALL symbols with trade type BUY and trade type SELL pending orders whether opened by same cBot or any other cBot or Manually

CancelPendingOrdersAsync(positions BUYand SELL)

  1. Find and Cancel ALL symbols with trade type BUY pending orders whether opened by same cBot or any other cBot or Manually

 CancelPendingOrdersAsync(positions BUY)

  1. Find and Cancel ALL symbols with trade type SELL positions whether opened by same cBot or any other cBot or Manually

CancelPendingOrdersAsync(positions SELL)

  1. Find and Cancel SPECIFIC symbol with trade type BUY and trade type SELL pending orders whether opened by same cBot or any other cBot or Manually

CancelPendingOrdersAsync(positions BUYand SELL)

  1. Find and Cancel SPECIFIC symbols with trade type BUY pending orders whether opened by same cBot or any other cBot or Manually

 CancelPendingOrdersAsync(positions BUY)

  1. Find and Cancel SPECIFIC symbols with trade type SELL positions whether opened by same cBot or any other cBot or Manually

CancelPendingOrdersAsync(positions SELL)

 


@m4trader4

m4trader4
24 May 2022, 10:53

RE:

Ahmad,

Open 1 sell and 1 buy position manually from Gui. Start cBot check for the 1M bar completion for results. Please check gif in the telegram for the scenario.

Positions.FindAll("")

Positions.FindAll("",symbolname) all these were working and now its not working. Pasting working code

  var positionsCBS = Positions.FindAll("", Symbolname);
                    //Print(arg2 + " " + "Yes message processed");
                    foreach (var psnCBS in positionsCBS)
                    {
                        //  Print("BuySell Positon= " + psnCBS);
                        if (psnCBS.Comment == "" || psnCBS.Comment.Contains("EP:") || psnCBS.Comment.Contains("Market"))
                        {

                            ClosePositionAsync(psnCBS);
                        }

                    }

 

Regards

Ahmed


@m4trader4

m4trader4
23 May 2022, 19:53 ( Updated at: 21 Dec 2023, 09:22 )

RE:

Ahmad,

 

Findall was the statement i used earlier it was working fine. Using the above code, if there is buy and sell position only one position is getting closed. Not all the positions are getting closed.

 


@m4trader4

m4trader4
14 Feb 2022, 13:02

RE: RE: RE: RE: RE:

m4trader4 said:

@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

 

 

 

 

 

cBot crashed: Error #90580554

cBot crashed: Error #65147970


@m4trader4