Code below appears to not work since upgrade to Ctrader 3.5
30 Jul 2019, 09:59
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
/*
GlobalTP+ 0.22.1
Mario Hennenberger http://www.swingfish.trade/tools
terminates ALL open Positions and delete ALL Pending Orders of the Net Profit is reached
ToDo:
- use percentages or absolute targets
- switch between ALL and the current Product/Pair
Lizense:
Creative Common - you are REQUIRED to mention me or swingfish.trade if you re-publish this.
get Updates:
- https://ctdn.com/algos/cbots/show/1664
- http://swingfish.trade/tools
Changes:
- remove cents display
- better text and display equity
- reset equity OnTick
- bug in calculating the total equity
- use net instead of Gross
- convert api names to new version
*/
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class GlobalTPPlus : Robot
{
[Parameter(DefaultValue = 0.0)]
public double CashTarget { get; set; }
protected override void OnStart()
{
// Put your initialization logic here
}
protected override void OnTick()
{
closeWhenTarget(CashTarget);
ChartObjects.DrawText("CashTarget0", "Target: " + CashTarget + " " + Account.Currency + " | Dist: " + Math.Round((Account.Equity - Account.Balance - CashTarget), 0) + " | Equity: " + Math.Round((Account.Equity), 0), StaticPosition.TopLeft);
}
protected override void OnStop()
{
// Put your deinitialization logic here
// will put a log here .. need to figure out how that works
}
private void closeWhenTarget(double target)
{
double profit = 0;
foreach (Position p in Positions)
profit += p.NetProfit;
// when profit is negative, we're done
if (profit < target)
return;
// target is reached
foreach (Position p in Positions)
ClosePosition(p);
// close all pending orders
foreach (PendingOrder o in PendingOrders)
CancelPendingOrder(o);
// go sleep
Stop();
}
}
}
Hi Panagiotis, can you have a look at the code in this utility.... I use this to close/stop Bots I have running and it appears to no longer work since my broker upgraded me to Ctrader 3.5... Thanks in advance...Cheers
Replies
Symposium
30 Jul 2019, 10:22
RE:
Panagiotis Charalampous said:
Hi Symposium,
Can you please explain what do you mean it doesn;t work? What do you expect it to do, what does it do instead and how can we reproduce the behavior?
Best Regards,
Panagiotis
Yes, The Utility tracks the profit (CashTarget) of a position and when that parameter is met ie: say $20.00 the Bot closes all positions and stops. The utility no longer stops the Bot when the Parameter is reached... it continues to trade.
@Symposium
PanagiotisCharalampous
30 Jul 2019, 10:44
Hi Symposium,
I just tried it and worked fine.
Best Regards,
Panagiotis
@PanagiotisCharalampous
Symposium
30 Jul 2019, 11:18
RE:
Panagiotis Charalampous said:
Hi Symposium,
I just tried it and worked fine.
Best Regards,
Panagiotis
Thanks Panagiotis.... it must be something I'm doing.... wasn't sure... Thanks for checking it... Cheers.
@Symposium
PanagiotisCharalampous
30 Jul 2019, 11:40
Hi Symposium,
Did you check the logs? Are the orders executed?
Best Regards,
Panagiotis
@PanagiotisCharalampous
Symposium
30 Jul 2019, 13:45
RE:
Panagiotis Charalampous said:
Hi Symposium,
Did you check the logs? Are the orders executed?
Best Regards,
Panagiotis
Yes, I backtest with the log tab open... It's mixed in with some other code, and I think maybe clashing is now the issue.... My coding ability is only mediocre so, I'll go back and take a look what is different in the last few algo's I have constructed.... appreciate your help... gratefull as always....
Hey, the new 3.5 version is so much better on memory and can be left running for days without issue... Cheers
@Symposium

PanagiotisCharalampous
30 Jul 2019, 10:02
Hi Symposium,
Can you please explain what do you mean it doesn;t work? What do you expect it to do, what does it do instead and how can we reproduce the behavior?
Best Regards,
Panagiotis
@PanagiotisCharalampous