distance StopLoss et TakeProfit

Created at 23 May 2015, 12:47
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
TR

tradermatrix

Joined 24.07.2012

distance StopLoss et TakeProfit
23 May 2015, 12:47


hello
 in my  system I would increase  the SL and TP. ( public double distanceMultiplier { get; set; })
 each trade perdand I would increase the distance of TakeProfit and StopLoss and return when the trade is a winner...Comme a martingale.
 somebody t it a solution?
 cordially.

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 SampleTrendcBot : Robot
    {
        [Parameter("MA Type")]
        public MovingAverageType MAType { get; set; }

        [Parameter()]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Slow Periods", DefaultValue = 10)]
        public int SlowPeriods { get; set; }

        [Parameter("Fast Periods", DefaultValue = 5)]
        public int FastPeriods { get; set; }

        [Parameter(" MaxPositions ", DefaultValue = 1, MinValue = 1)]
        public int MaxPositions { get; set; }

        [Parameter(DefaultValue = 10000, MinValue = 0)]
        public int Volume { get; set; }

        [Parameter(DefaultValue = 20)]
        public double TakeProfit { get; set; }

        [Parameter(DefaultValue = 20)]
        public double StopLoss { get; set; }

        [Parameter("distance Multiplier", DefaultValue = 2)]
        public double distanceMultiplier { get; set; }




        private int Count = 0;

        private MovingAverage slowMa;
        private MovingAverage fastMa;
        private const string label = "Sample Trend cBot";

        protected override void OnStart()
        {
            fastMa = Indicators.MovingAverage(SourceSeries, FastPeriods, MAType);
            slowMa = Indicators.MovingAverage(SourceSeries, SlowPeriods, MAType);
        }

        protected override void OnTick()
        {


            Count++;
            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);

            var currentSlowMa = slowMa.Result.Last(0);
            var currentFastMa = fastMa.Result.Last(0);
            var previousSlowMa = slowMa.Result.Last(1);
            var previousFastMa = fastMa.Result.Last(1);

            if (Positions.Count < MaxPositions && previousSlowMa > previousFastMa && currentSlowMa <= currentFastMa && longPosition == null)
            {

                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label, StopLoss, TakeProfit);
                Count = 0;
            }
            else if (Positions.Count < MaxPositions && previousSlowMa < previousFastMa && currentSlowMa >= currentFastMa && shortPosition == null)
            {

                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, StopLoss, TakeProfit);
                Count = 0;
            }
        }
    }
}

 


@tradermatrix
Replies

Spotware
15 Jun 2015, 15:21

Dear Trader,

We do not provide coding assistance services. We more than glad to assist you with specific questions about cAlgo.API. You also can contact one of our Partners or post a job in Development Jobs section for further coding assistance.


@Spotware

tradermatrix
15 Jun 2015, 16:16

yes thank you
but sometimes some traders give solutions.
I too am doing to help others.
regarding my application I found a solution.
and I managed to improve the performance of my robots.
multiplying SL and TP and the volume but way less that a classic martingale (the risk is smaller)
I work in real account
cordially.


@tradermatrix