Stoploss information for a historical trade - how do I access that?
Stoploss information for a historical trade - how do I access that?
18 Aug 2019, 06:45
Hello,
I would like to run a basic analysis to review my past trades. I am able to access the usual information like pips gained/lost, profit, etc. How do I get the stoploss in place for that position? I am able to access that info for each position by navigating my way to each individual Order Event ID on cTrader Desktop. Is there a way I can get that info with code? What object/method do I need to use? Any help would be greatly appreciated. Thank you.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { foreach (HistoricalTrade trade in History) { if (trade.EntryTime > (DateTime.Parse("16/08/2019 12:10:15 AM"))) Print("Symbol: {0} , PID: {1}, EntryTime: {2}, ClosingTime: {3}, Profit: {4}, Pips: {5}", trade.SymbolName, trade.PositionId, trade.EntryTime, trade.ClosingTime, trade.NetProfit, trade.Pips); //To Do: Stoploss for each position closed } Print("All done..."); this.Stop(); } protected override void OnTick() { // Put your core logic here } protected override void OnStop() { // Put your deinitialization logic here } } }
Replies
therealnakedtrader
20 Aug 2019, 17:50
RE:
FireMyst said:
I don't know if there's an API call for it, but you could always try writing the stop loss in an encoded string within the "comment" when the order is placed.
Then parse it from the historical trade info.
For instance, make your encoded string %SL:xx.x% where xx.x is the pips SL.
Then all you need do is parse the string to find it. :-)
Hey FireMyst,
That's indeed a good idea. I do use it when triggering an order. However, Comment field cannot be updated after a trade is in progress and typically, I move the SL depending on the price action after the trade has been placed. So, yeah... I was hoping for some way to access that elusive Stoploss value. Thanks for your help, mate. Very much appreciated. :)
Cheers!
@therealnakedtrader
firemyst
20 Aug 2019, 17:38
I don't know if there's an API call for it, but you could always try writing the stop loss in an encoded string within the "comment" when the order is placed.
Then parse it from the historical trade info.
For instance, make your encoded string %SL:xx.x% where xx.x is the pips SL.
Then all you need do is parse the string to find it. :-)
@firemyst