Get the win/loss of the previous trade

Created at 30 Nov 2023, 03:34
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!
KE

kei.3434.get

Joined 30.11.2023

Get the win/loss of the previous trade
30 Nov 2023, 03:34


I don't know the code to get the win/loss of the previous trade. I've tried various things, but I can't resolve the error.
``protected override void OnTradeExecuted(TradeRecord tradeRecord)'' TradeRecord will result in an error.
If anyone knows the solution please let me know.
thank you.


@kei.3434.get
Replies

PanagiotisCharalampous
30 Nov 2023, 06:27

Reply to: Get the win/loss of the previous trade

Hi there,

Where did you get this code from? You need to share the complete cBot code in order for us to understand what the problem is.

Best regards,

Panagiotis


@PanagiotisCharalampous

kei.3434.get
30 Nov 2023, 07:04 ( Updated at: 30 Nov 2023, 12:06 )

RE: Reply to: Get the win/loss of the previous trade

PanagiotisCharalampous said: 

Hi there,

Where did you get this code from? You need to share the complete cBot code in order for us to understand what the problem is.

Best regards,

Panagiotis

I got this code from chat gpt.

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 NewcBot4 : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        protected override void OnStart()
        {
              Print(Message);
        }
                        
        protected override void OnTradeExecuted(TradeRecord tradeRecord)
       {
           TradeResult lastTradeResult = null;

           if (lastTradeResult != null)
            {
           if (lastTradeResult.NetProfit >= 0)
            {
               Print("WIN!");
            }
           else if (lastTradeResult.NetProfit < 0)
            {
               Print("LOST!");
            }
    }
}

     
               

 


@kei.3434.get

kei.3434.get
30 Nov 2023, 07:04 ( Updated at: 30 Nov 2023, 12:06 )

RE: RE: Reply to: Get the win/loss of the previous trade
kei.3434.get said:

PanagiotisCharalampous said: 

Hi there,

Where did you get this code from? You need to share the complete cBot code in order for us to understand what the problem is.

Best regards,

Panagiotis

I got this code from chat gpt.

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 NewcBot4 : Robot
    {
        [Parameter(DefaultValue = "Hello world!")]
        public string Message { get; set; }

        protected override void OnStart()
        {
              Print(Message);
        }
                        
        protected override void OnTradeExecuted(TradeRecord tradeRecord)
       {
           TradeResult lastTradeResult = null;

           if (lastTradeResult != null)
            {
           if (lastTradeResult.NetProfit >= 0)
            {
               Print("WIN!");
            }
           else if (lastTradeResult.NetProfit < 0)
            {
               Print("LOST!");
            }
    }
}

     
               

 


@kei.3434.get

PanagiotisCharalampous
30 Nov 2023, 12:08

Hi there,

ChatGPT produced code is full of bugs. There is no such thing as a OnTradeExecuted(). If you don't know how to code, better ask the assistance of a professional.

Best regards,

Panagiotis


@PanagiotisCharalampous