Difference between cTrader Statement and logged trades

Created at 20 Apr 2023, 06:15
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!
JE

Jexodus

Joined 15.04.2023

Difference between cTrader Statement and logged trades
20 Apr 2023, 06:15


I have an indicator that logs all my trades to a database.  However, there are value discrepancies between the database logged values and the values in cTrader statement. The variance is consistent across the position, meaning the pip values and dollar values are in sync, they are just different between the database and inside cTrader after the trade has closed.  Values are usually out by 0.1 - 0.2 pips, which substantially effects stats accuracy over time.

has anyone else had something similar happen? Is this potentially a race condition with the event handler being finished before the position has been fully added to the cTrader statement record, taking in to account any conversions, spread calculations, etc? I haven't gone as far as letting the Position.Closed event fully complete, wait n amount of seconds and then pull the data from position history to see if the discrepancy remains.  I will if I have to, but I don't see why this should be needed. 

I don't think it is a code issue, but here it is anyway... Uses the Positions.Closed event handler to trigger the following method:

private void Positions_Closed(PositionClosedEventArgs args)
{
    Position position = args.Position;

    DataManager.AddClosedTradeToDatabase(position);

}

The method in the DataManager is as follows:

public static bool AddClosedTradeToDatabase(Position position)
{
    using (SqlConnection connection = new SqlConnection(CONNECTION_STRING))
    {
    using (SqlCommand command = connection.CreateCommand())
    {
    command.CommandText = $"INSERT INTO dbo.Trades (Symbol, Direction, EntryTime, Volume, StopLoss, TakeProfit, Pips, GrossOutcome, Swap, Commission, NetOutcome, TrailingSL) " +
        $"VALUES (" +
        $"'{position.SymbolName}', " +
        $"'{position.TradeType}', " +
        $"'{position.EntryTime.ToString()}', " +
        $"{position.VolumeInUnits}, " +
        $"{position.StopLoss}, " +
        $"{position.TakeProfit}, " +
        $"{position.Pips}, " +
        $"{position.GrossProfit}, " +
        $"{position.Swap}, " +
        $"{position.Commissions}, " +
        $"{position.NetProfit}, " +
        $"'{Convert.ToString(position.HasTrailingStop)}')";

        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();
        }
    }
    return;
}

 


@Jexodus
Replies

PanagiotisChar
20 Apr 2023, 08:18

Hi Jexodus,

It's hard for us to understand what happens if we are not able to easily reproduce. I would advise to post a sample cBot that prints these discrepancies in the log and post it here so that we can use it. Also post some screenshots of what you are looking. It is also possible that you will find the issue yourself while you are doing this.

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 


@PanagiotisChar