Replies

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

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
27 Jul 2017, 11:24

Great, thank you, works perfectly.

added the parameter and label for anyone who wants to save time.

[Parameter("Cancel Pending Orders", DefaultValue = 30, MinValue = 0)]
        public int MaxPipDistance { get; set; }

 

protected override void OnTick()
        {
            foreach (var order in PendingOrders)
            {
                var pipDistance = Math.Abs((order.TargetPrice - Symbol.Ask) / Symbol.PipValue);
                if (pipDistance > MaxPipDistance)
                {
                    CancelPendingOrder(order);
                    Print("Order Has Reached Max Distance, Order Cancelled");
                }
            }
        }


@theonlinemick

theonlinemick
26 Jul 2017, 21:07

Ok scratch that, I just thought of a much better work around.

Very simple question...

How do I cancel all pending orders on all symbols reach a specific pip distance from respective bid/ask price?


@theonlinemick

theonlinemick
26 Jul 2017, 20:26

"The equity is gaining well, but the acc bal slowly reduces" - yes, I do mean the equity (it is not a martigale bot).


@theonlinemick