Help with Parameter for $ Value
Help with Parameter for $ Value
28 Jul 2017, 00:39
I'm working on a trigger that stops the bot and closes all positions when equity hits a set target. I need to try work around the target being in % or multiplication of balance, but instead the actual profit value in $$ ($400).
[Parameter("Equity Profit Trigger (%)", DefaultValue = 0.25)]
public double EquityPercent { get; set; }
double _myEquity;
protected override void OnTick()
{
if ((_myEquity / Account.Equity) > EquityPercent)
{
Stop();
}
}
protected override void OnStop()
{
foreach (var position in Positions)
{
ClosePosition(position);
}
}
Replies
theonlinemick
28 Jul 2017, 07:51
Thanks, I got it working :)
This allows you to input your starting capital prior to launching the bot, your desired profit amount in $, and the bot stops when equity reaches that profit level - then closes all positions.
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; using System.Text; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class ShadowHedge : Robot { [Parameter("Starting Balance ($)", DefaultValue = 5000)] public int StartingBalance { get; set; } [Parameter("Profit Target ($)", DefaultValue = 500)] public int ProfitTarget { get; set; } double _myEquity; protected override void OnTick() { if (Account.Equity > (StartingBalance + ProfitTarget)) { Stop(); } } protected override void OnStart() { _myEquity = Account.Equity; } protected override void OnStop() { foreach (var position in Positions) { ClosePosition(position); } } } }
@theonlinemick
theonlinemick
28 Jul 2017, 07:55
Using Account.Balance didnt get the desired results - as the balance gradually decreses while the equity steps up. Resulting in the set profit value not generally stopping at a profitable point. This allows you to fix the starting capital and trigger the take profits when equity reaches a set amound above the fixed capital amount, regardless of account balance drawdown.
@theonlinemick
BeardPower
28 Jul 2017, 01:30
RE:
theonlinemick said:
You want to stop the bot, once your profit reached a specific cash goal?
@BeardPower