Get trade wins and losses

Created at 03 Dec 2023, 01:13
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 trade wins and losses
03 Dec 2023, 01:13


I want to calculate the number of lots for the next trade by getting the win/loss information from the previous trade, but I don't know the code to get the win/loss information. thank you.


@kei.3434.get
Replies

firemyst
03 Dec 2023, 10:18 ( Updated at: 04 Dec 2023, 08:32 )

Use the HIstoricalTrade object

You could look at the example Spotware provided:

https://help.ctrader.com/ctrader-automate/references/Trading/History/HistoricalTrade/#examples

 

private void Positions_Closed(PositionClosedEventArgs args)
{
	//Only run this method if it's this instance that closed.
	Position p1 = args.Position;

	if  (p1.SymbolName == Symbol.Name && p1.Label == _positionLabel)
	{
		HistoricalTrade ht = History.FindLast(p1.Label, p1.SymbolName, p1.TradeType);
		if (ht != null)
		{
			//DO whatever if there's historical information
    			double cp = ht.ClosingPrice;
			Print("CLosing Price: {0}", cp);
		}
	}

}

@firemyst

kei.3434.get
05 Dec 2023, 12:18 ( Updated at: 06 Dec 2023, 06:16 )

RE: Use the HIstoricalTrade object

firemyst said: 

You could look at the example Spotware provided:

https://help.ctrader.com/ctrader-automate/references/Trading/History/HistoricalTrade/#examples

 

thank you.

 


@kei.3434.get