cBot Errors onTick

Created at 30 May 2014, 16:44
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
breakermind's avatar

breakermind

Joined 17.07.2013

cBot Errors onTick
30 May 2014, 16:44


Hi,

why this code generate this error:

30/05/2014 13:39:55.054 | System.InvalidOperationException: Obiekt dopuszczający wartość pustą musi mieć wartość.    w System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)    w cAlgo.BreakermindCopyTrader.sendPositions(String Username, String Password)    w cAlgo.BreakermindCopyTrader.OnTick()

 

        protected override void OnTick()
        {
            // Put your core logic here
            try
            {
                // send all positions
                sendPositions(Username, Password);
                if (Positions.Count >= MaxPositions || Positions.Count == 0)
                {
                    Print("Waiting for You Trader....");
                }
                else
                {

                }

            } catch (Exception e)
            {
                var he = e;
                Print("Waiting for You Trader " + e);
            }

        }




       protected void sendPositions(string Username, string Password)
        {
            // log file path
            string desktopFolder = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string logPath = Path.Combine(desktopFolder, "MasterLog.db");

            // open position
            var AllPositions = Positions;
            openPositionsString = "[GO]";
            openPips = "|";

            foreach (var position in AllPositions)
            {

                // close with wrong volume
                if (position.Volume < MinVolume)
                {
                    Print("cBot Position: " + position.Id + " Wrong Min Volume (" + MinVolume + ") ");
                    if (position.Volume < MinVolume)
                        ClosePosition(position);
                    Print("cBot Closed Position " + position.Id);
                }

                if (position.StopLoss == null)
                {
                    Print("Position {1} SL price is {0}", position.StopLoss, position.Id);
                }

                if (position.TakeProfit == null)
                {
                    Print("Position {1} TP price is {0}", position.StopLoss, position.Id);
                }

                if (position.StopLoss == null && position.TakeProfit == null)
                {
                    Print("Modifying {0}", position.Id);
                    ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), GetAbsoluteTakeProfit(position, TakeProfitInPips));

                }

                if (position.StopLoss == null)
                {
                    Print("Modifying {0}", position.Id);
                    //ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), GetAbsoluteTakeProfit(position, TakeProfitInPips));
                    ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), position.TakeProfit);
                }

                if (position.TakeProfit == null)
                {
                    Print("Modifying {0}", position.Id);
                    //ModifyPosition(position, GetAbsoluteStopLoss(position, StopLossInPips), GetAbsoluteTakeProfit(position, TakeProfitInPips));
                    ModifyPosition(position, position.StopLoss, GetAbsoluteTakeProfit(position, TakeProfitInPips));
                }

                // BUY positions
                if (position.TradeType == TradeType.Buy && position.Volume >= MinVolume)
                {
                    openPositionsString += position.Id + ";" + position.SymbolCode + ";" + "BUY" + ";" + position.Volume + ";" + position.EntryPrice + ";" + position.StopLoss + ";" + position.TakeProfit + ";" + DateTimeToUnixTimestamp(position.EntryTime) + "|";
                    openPips += position.Pips + "|";
                }

                // SELL positions
                if (position.TradeType == TradeType.Sell && position.Volume >= MinVolume)
                {
                    openPositionsString += position.Id + ";" + position.SymbolCode + ";" + "SELL" + ";" + position.Volume + ";" + position.EntryPrice + ";" + position.StopLoss + ";" + position.TakeProfit + ";" + DateTimeToUnixTimestamp(position.EntryTime) + "|";
                    openPips += position.Pips + "|";
                }

            }
            openPositionsString += "[OG]";
            //================================================================================
            //                                                                    Send request
            //================================================================================

            if (responseFromServer == openPositionsString)
            {
                Print("Same strings ... wait for new Positions !");
                Print("RESPONSE: " + responseFromServer);
                Print("OPEN POS: " + openPositionsString);


            }

            if (responseFromServer != openPositionsString)
            {
                foreach (HistoricalTrade tr in History)
                {
                    // this month closed positions
                    if (DateTime.Now.Month == tr.EntryTime.Month)
                    {
                        //Print("Curr month history positions: " + tr.PositionId + " open time " + tr.EntryTime.Month);
                        closeHistoryPosition += tr.PositionId + "|" + tr.TradeType + "|" + tr.SymbolCode + "|" + tr.Volume + "|" + tr.EntryTime + "|" + tr.EntryPrice + "|" + tr.ClosingTime + "|" + tr.ClosingPrice + "|" + tr.Balance + "###";
                    }
                }
                Print("Position history : " + closeHistoryPosition);
            }


            if (responseFromServer != openPositionsString)
            {

                Print("Send positions...");

                // Account parametrs ============================================
                account = Math.Round(Account.Equity, 2) + "|" + Math.Round(Account.Balance, 2) + "|" + Math.Round(Account.FreeMargin, 2) + "|" + Math.Round(Account.Margin, 2) + "|" + Math.Round((decimal)Account.MarginLevel, 2) + "|" + Account.Currency + "|" + Account.IsLive + "|" + Account.Leverage;


                try
                {
                    using (StreamWriter w = File.AppendText(logPath))
                    {
                        // log request
                        w.WriteLine("REQUEST: " + DateTimeToUnixTimestamp(DateTime.UtcNow) + " : " + openPositionsString);
                        w.Flush();
                        w.Close();
                    }

                    //================================================================================
                    //                   FORCE CERTYFICATE SSL VALIDATION for self signed(openssl) ssl
                    //================================================================================
                    ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);

                    //================================================================================
                    //                                                                      HTTPS POST
                    //================================================================================
                    WebRequest request = WebRequest.Create("https://breakermind.com/set.php");
                    Print("====================================================================================");
                    Print("==>> " + openPositionsString);
                    Print("====================================================================================");
                    byte[] postBytes = Encoding.ASCII.GetBytes("line=" + openPositionsString + "&linepips=" + openPips + "&account=" + account + "&history=" + closeHistoryPosition + "&login=" + Username + "&pass=" + Password);
                    //request.Credentials = CredentialCache.DefaultCredentials;
                    request.Proxy = null;
                    request.Method = "POST";
                    request.ContentType = "application/x-www-form-urlencoded";
                    request.ContentLength = postBytes.Length;
                    Stream requestStream = request.GetRequestStream();
                    requestStream.Write(postBytes, 0, postBytes.Length);
                    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                    Stream dataStream = response.GetResponseStream();
                    StreamReader reader = new StreamReader(dataStream);
                    responseFromServer = "";
                    responseFromServer = reader.ReadToEnd();

                    openPositionsString = "";

                } catch (Exception e)
                {

                    Print("====================================================================================");
                    Print("Notice: " + e);
                    Print("====================================================================================");
                    using (StreamWriter w = File.AppendText(logPath))
                    {
                        // log response
                        w.WriteLine("ERROR: " + DateTimeToUnixTimestamp(DateTime.UtcNow) + " : " + e);
                        w.Flush();
                        w.Close();
                    }
                }
                Print("====================================================================================");
                Print("<<== " + responseFromServer);
                Print("====================================================================================");

                using (StreamWriter w = File.AppendText(logPath))
                {
                    // log response
                    w.WriteLine("RESPONSE: " + DateTimeToUnixTimestamp(DateTime.UtcNow) + " : " + responseFromServer);
                    w.Flush();
                    w.Close();
                }
            }

        }

Regards


@breakermind
Replies

breakermind
30 May 2014, 16:49

RE:

if i have open position error gone!

if not a see this above

 


@breakermind

Invalid
30 May 2014, 17:06

RE: RE:

Which line gives you this exception?

breakermind said:

if i have open position error gone!

if not a see this above

 

 


@Invalid

Invalid
30 May 2014, 17:08

Some of your fields are initialized only in specific scenarios. Initialize the field in declaration or change the usage code


@Invalid

breakermind
30 May 2014, 17:33

RE: RE: RE:

I see this in logs when start cbot when i have no open positions.

I look for it later...or write again from the beginning.

 

 

Invalid said:

Which line gives you this exception?

breakermind said:

if i have open position error gone!

if not a see this above

 

 

 


@breakermind

Invalid
30 May 2014, 17:36

RE: RE: RE: RE:

Try to debug in VS - it will be much faster

breakermind said:

I see this in logs when start cbot when i have no open positions.

I look for it later...or write again from the beginning.

 

 

Invalid said:

Which line gives you this exception?

breakermind said:

if i have open position error gone!

if not a see this above

 

 

 

 


@Invalid

breakermind
30 May 2014, 17:58

RE: RE: RE: RE: RE:

New VS does not install on my 32 bit awesome machine :] , and do not want to pull back and look for the older version I see tomorrow on another machine.

although I suspect that it will not do anything.

Thanks for help.

 

Invalid said:

Try to debug in VS - it will be much faster

breakermind said:

I see this in logs when start cbot when i have no open positions.

I look for it later...or write again from the beginning.

 

 

Invalid said:

Which line gives you this exception?

breakermind said:

if i have open position error gone!

if not a see this above

 

 

 

 

 


@breakermind

breakermind
30 May 2014, 20:13

RE: RE: RE: RE: RE: RE:

This code generate exception onTick:

account = Math.Round(Account.Equity, 2) + "|" + Math.Round(Account.Balance, 2) + "|" + Math.Round(Account.FreeMargin, 2) + "|" + Math.Round(Account.Margin, 2) + "|" + Math.Round((decimal)Account.MarginLevel, 2) + "|" + Account.Currency + "|" + Account.IsLive + "|" + Account.Leverage;

this:

30/05/2014 17:12:25.502 | System.InvalidOperationException: Obiekt dopuszczający wartość pustą musi mieć wartość.    w System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)    w cAlgo.BreakermindCopyTrader.sendPositions(String Username, String Password)    w cAlgo.BreakermindCopyTrader.OnTick()

why support ???


@breakermind

Spotware
02 Jun 2014, 09:24

RE: RE: RE: RE: RE: RE: RE:

breakermind said:

This code generate exception onTick:

account = Math.Round(Account.Equity, 2) + "|" + Math.Round(Account.Balance, 2) + "|" + Math.Round(Account.FreeMargin, 2) + "|" + Math.Round(Account.Margin, 2) + "|" + Math.Round((decimal)Account.MarginLevel, 2) + "|" + Account.Currency + "|" + Account.IsLive + "|" + Account.Leverage;

this:

30/05/2014 17:12:25.502 | System.InvalidOperationException: Obiekt dopuszczający wartość pustą musi mieć wartość.    w System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)    w cAlgo.BreakermindCopyTrader.sendPositions(String Username, String Password)    w cAlgo.BreakermindCopyTrader.OnTick()

why support ???

Account.MarginLevel is null if you don't have opened positions


@Spotware

breakermind
05 Jun 2014, 13:08

Trade and Copy ...

Hello,

if you want to test it to copy items between platforms cAlgo / cTrader I invite you to page:

https://breakermind.com


It's only a test version and may need some improvements but even if it does not work please do not worry and write where is bug..

During the nick is registered email address, you can specify how you want like: asdsa@sdds.ddd
database and so will be removed and the system does not send e-mails with activation.

cTrader demo account you set up yourself:


Start deposit $ 1,000 with 1:200 leverage microlots (spotware demo account is ok)

For Trader account need an upgrade in setting after login.
For trader account leverage 1:100 min - max 1:200

For user (copy positions) min leverage 1:200 and microlots (1000 volume) if you want
copy signals from $ 100 deposit

Regards

 

Ps

Dear support when I can get Account ID and Broker name from cBot ???

 

 


@breakermind