Opposite direction trend trade

Created at 17 Apr 2020
KO

kobus.strachan

Joined 17.04.2020

Status

Closed


Budget

100.00 EUR


Payment Method

via  Freelancer

Job Description

I am interested in a cBot whereby a position is opened by selecting "Buy / Sell", at volume (user defined parameter) default minimum = 0.01 (lots), with Stop Loss (PIP parameter, user defined), Take Profit (PIP parameter, user defined). When the Take Profit PIP target is achieved, the position should auto close-out, and a new position in the same direction as last should be opened, with an initial minimum volume - effectively this is a new cycle.

If the position reaches the Stop Loss target, then the position should be auto closed-out, and a new position should be opened in the opposite direction.

Volume step option parameter, 0, 1, 2, 3, 4 etc. When 0, then the minimum volume will apply in every instance, and it will remain at the minimum volume (ie. 0.01) for every trade regardless of losing or not. When "1" is selected, then every losing cycle will increase by 1; ie. 1, 2, 3, 4, etc. when "2", then every losing cycle will increase to next by 2 i.e. cycle will then effectively double from one to next sequence. Example, when "2" is selected then the sequence in terms of losing trades will be 1, 2, 4, 8, 16 etc. When user defined parameter "3" is selected, then the sequence on losing trades will be will be 1, 3, 9, 27. Note first / initial sequence will also commence with user defined minimum, ie. 0.01

Sequence limit, user defined parameter. With this parameter, the number of times the losing trades in the sequence is to be limited. As an example, if "3" is selected, then after 3 consecutive losing trades the sequence should revert back to a new cycle, back to the first position in sequence with the new initial position being the same direction of trade as the last losing position. Back to minimum volume for first position.

When a winning trade is achieved, revert back to initial first sequence, and commence new cycle in trade with same direction as last win.

 

On this forum I have noted the following from "slootwege" and "lucian", with credit to them both - but it is not quite what I want. Just added here as info only, the below:  

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OpennewinOpositedirection : Robot
    {
        [Parameter("Profit $", DefaultValue = 5.0)]
        public double _profit { get; set; }
        [Parameter("Loss $", DefaultValue = -3.0)]
        public double _loss { get; set; }
        [Parameter("Initial Volume", DefaultValue = 10000, MinValue = 0)]
        public int _volume { get; set; }
        private Random random = new Random();

        protected override void OnStart()
        {
            ExecuteOrder(_volume, GetRandomTradeType());
            Positions.Closed += Positions_Closed;
        }

        protected override void OnTick()
        {
            foreach (var trade in Positions)
            {

                if ((trade.Label.StartsWith("SlootWege")) && ((trade.GrossProfit >= _profit) || (trade.GrossProfit <= _loss)))
                {
                    ClosePosition(trade);
                }
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
        private void Positions_Closed(PositionClosedEventArgs args)
        {
            if (args.Position.GrossProfit <= _loss)
            {
                if (args.Position.TradeType == TradeType.Buy)
                {
                    ExecuteOrder(_volume, TradeType.Sell);
                }
                else
                {
                    ExecuteOrder(_volume, TradeType.Buy);
                }
            }
            if (args.Position.GrossProfit >= _profit)
            {
                if (args.Position.TradeType == TradeType.Buy)
                {
                    ExecuteOrder(_volume, TradeType.Buy);
                }
                else
                {
                    ExecuteOrder(_volume, TradeType.Sell);
                }
            }
        }
        private void ExecuteOrder(long volume, TradeType tradeType)
        {
            var result = ExecuteMarketOrder(tradeType, Symbol, volume, "SlootWege", null, null);

            if (result.Error == ErrorCode.NoMoney)
                Stop();
        }
        private TradeType GetRandomTradeType()
        {
            return random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
        }
    }
}

Comments
KO
kobus.strachan · 4 years ago

I will contact you direct.

KO
kobus.strachan · 4 years ago

Ok, when will you able to deliver completed version?

 

When do you expect payment - upon delivery?

SA
sascha.dawe · 4 years ago

Hi,

I can program this.

Contact sascha.coding@gmail.com

Regards,

Sascha