Replies

kurtisnauss
13 Oct 2022, 04:29

RE:

PanagiotisChar said:

Hi there, 

An easier option is the below

Positions.Count(x => x.SymbolName == SymbolName)

Aieden Technologies

Need help? Join us on Telegram

Need premium support? Trade with us

 

 

Works like a charm... Thank you!


@kurtisnauss

kurtisnauss
18 Aug 2022, 21:02

RE:

PanagiotisCharalampous said:

Hi kurtisnauss,

I would suggest to use ModifyStopLossPrice() instead.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

The first reply actually did work when I added that to the final modify position line.

What would be the difference or benefit of doing it that way instead?

thanks


@kurtisnauss

kurtisnauss
04 Aug 2022, 04:19 ( Updated at: 21 Dec 2023, 09:22 )

RE:

firemyst said:

Bars.ClosePrices[index] > slowMa.Result[index]

This is going to happen on every bar where the close price is greater than the MA. If you have a long uptrend, and are on a small/fast time frame over a long period of back testing, this could happen thousands of times. 

For example:

The condition will evaluate to true for every single one of those bars shown above if your slow MA is the yellow line, because the close price is above the MA.

But that's only in theory since we don't have the whole of your code and don't know what else is happening in your bot.

Yes, that makes sense that would be reading and storing data for every bar that is printed.

Therefore, when writing it as in example #1, does that tell it to only read it one time on the initial cross and then waits until the next time we see it crossover?


@kurtisnauss

kurtisnauss
11 Jul 2022, 15:58

RE:

PanagiotisCharalampous said:

Hi kurtisnauss,

Yes you can. Check here how.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook

thank you, much appreciated!


@kurtisnauss

kurtisnauss
15 Jun 2022, 15:39

RE: Thank you, I will try that out and play around with it. There are other parameters I would like to add but needed that before anything.

amusleh said:

H,

You can use standard deviation indicator and a multiplier number like Bollinger Bands, example:

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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
    public class MADeviationBot : Robot
    {
        [Parameter("Instance Name", DefaultValue = "")]
        public string InstanceName { get; set; }

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

        [Parameter("MA Type")]
        public MovingAverageType Type { get; set; }

        [Parameter("MA Period")]
        public int MAPeriod { get; set; }

        [Parameter("Stop Loss")]
        public int StopLoss { get; set; }

        [Parameter("Risk %", MinValue = 0.01, Step = 0.01)]
        public double RiskPerTrade { get; set; }

        [Parameter("Std Multiplier", DefaultValue = 1)]
        public double StdMultiplier { get; set; }

        private MovingAverage _ma;

        private StandardDeviation _standardDeviation;

        protected override void OnStart()
        {
            _ma = Indicators.MovingAverage(SourceSeries, MAPeriod, Type);
            _standardDeviation = Indicators.StandardDeviation(SourceSeries, MAPeriod, Type);
        }

        protected override void OnBar()
        {
            int index = Bars.Count - 1;
            Entry(index);
            Exits(index);
        }

        private void Entry(int index)
        {
            if (_ma.Result[index] - Bars.ClosePrices[index] > _standardDeviation.Result[index] * StdMultiplier)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, GetVolume(StopLoss), InstanceName, StopLoss, null);
            }
            else if (Bars.ClosePrices[index] - _ma.Result[index] > _standardDeviation.Result[index] * StdMultiplier)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, GetVolume(StopLoss), InstanceName, StopLoss, null);
            }
        }

        private void Exits(int index)
        {
            var positions = Positions.FindAll(InstanceName, SymbolName);

            foreach (var position in positions)
            {
                if ((position.TradeType == TradeType.Buy && Bars.ClosePrices[index] > _ma.Result[index]) || (position.TradeType == TradeType.Sell && Bars.ClosePrices[index] < _ma.Result[index]))
                {
                    ClosePosition(position);
                }
            }
        }

        private double GetVolume(double? stopLossPips = null)
        {
            double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;

            // Change this to Account.Equity if you want to
            double baseNumber = Account.Balance;

            double sizeInLots = Math.Round((baseNumber * RiskPerTrade / 100) / (stopLossPips.Value * costPerPip), 1);

            var result = Symbol.QuantityToVolumeInUnits(sizeInLots);

            return result;
        }
    }
}

 

 


@kurtisnauss

kurtisnauss
09 Jun 2022, 13:41

RE:

amusleh said:

Hi,

Please check my reply on: 

You don't have to open multiple threads for same topic.

Hi,

Yes I saw that you replied on there, I did not see that my thread was posted and when I clicked on on it was blank, I thought there was an error when being posted so I made a new one.

 

But thank you very much for helping with that I will try put that together into my bot. Much appreciated! 


@kurtisnauss