Replies

richard_alcaide
06 Aug 2022, 15:24

Indicators Doesn't Show Up

Hi indicators are not showing up after the last update..I'm hoping this will be resolved quickly because I rely heavily on indicators in my trading. Thank You!


@richard_alcaide

richard_alcaide
28 Nov 2016, 23:08

RE:

Thank You tradermatrix it works great!


@richard_alcaide

richard_alcaide
10 Nov 2016, 13:19

RE: RE:

richard_alcaide said:

tmc. said:

Try following code. It's checking symbol code instead of label so you don't have to set different label for each instance to make them work seperatly.

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AlcaideSR : Robot
    {
        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("Pips away", DefaultValue = 20)]
        public int PipsAway { get; set; }

        [Parameter("TP", DefaultValue = 60)]
        public int TakeProfitPips { get; set; }

        [Parameter("SL", DefaultValue = 20)]
        public int StopLossPips { get; set; }

        [Parameter("Label", DefaultValue = "Rich")]
        public string Label { get; set; }

        [Parameter("Buy ?", DefaultValue = true)]
        public bool IsBuy { get; set; }

        protected override void OnStart()
        {
            if (Positions.Where(pos => pos.SymbolCode == Symbol.Code).Count() == 0)
            {
                if (IsBuy)
                {
                    double targetPrice = Symbol.Ask - PipsAway * Symbol.PipSize;
                    PlaceLimitOrder(TradeType.Buy, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
                else
                {
                    double targetPrice = Symbol.Bid + PipsAway * Symbol.PipSize;
                    PlaceLimitOrder(TradeType.Sell, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
            }

            Positions.Opened += OnPositionOpened;
        }

        private void OnPositionOpened(PositionOpenedEventArgs obj)
        {
            if (obj.Position.SymbolCode == Symbol.Code)
            {
                if (obj.Position.TradeType == TradeType.Buy)
                {
                    double targetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;
                    PlaceStopOrder(TradeType.Sell, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
                else
                {
                    double targetPrice = Symbol.Ask + PipsAway * Symbol.PipSize;
                    PlaceStopOrder(TradeType.Buy, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
            }
        }
    }
}

 

Excellent tmc.! its working perfect now Thanks to both of you for being helpful!

One last thing guys I also need  to automatically cancel the Pending order of the pair where TP made. TIA


@richard_alcaide

richard_alcaide
09 Nov 2016, 21:24

RE:

tmc. said:

Try following code. It's checking symbol code instead of label so you don't have to set different label for each instance to make them work seperatly.

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

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AlcaideSR : Robot
    {
        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("Pips away", DefaultValue = 20)]
        public int PipsAway { get; set; }

        [Parameter("TP", DefaultValue = 60)]
        public int TakeProfitPips { get; set; }

        [Parameter("SL", DefaultValue = 20)]
        public int StopLossPips { get; set; }

        [Parameter("Label", DefaultValue = "Rich")]
        public string Label { get; set; }

        [Parameter("Buy ?", DefaultValue = true)]
        public bool IsBuy { get; set; }

        protected override void OnStart()
        {
            if (Positions.Where(pos => pos.SymbolCode == Symbol.Code).Count() == 0)
            {
                if (IsBuy)
                {
                    double targetPrice = Symbol.Ask - PipsAway * Symbol.PipSize;
                    PlaceLimitOrder(TradeType.Buy, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
                else
                {
                    double targetPrice = Symbol.Bid + PipsAway * Symbol.PipSize;
                    PlaceLimitOrder(TradeType.Sell, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
            }

            Positions.Opened += OnPositionOpened;
        }

        private void OnPositionOpened(PositionOpenedEventArgs obj)
        {
            if (obj.Position.SymbolCode == Symbol.Code)
            {
                if (obj.Position.TradeType == TradeType.Buy)
                {
                    double targetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;
                    PlaceStopOrder(TradeType.Sell, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
                else
                {
                    double targetPrice = Symbol.Ask + PipsAway * Symbol.PipSize;
                    PlaceStopOrder(TradeType.Buy, Symbol, Volume, targetPrice, Label, StopLossPips, TakeProfitPips);
                }
            }
        }
    }
}

 

Excellent tmc.! its working perfect now Thanks to both of you for being helpful!


@richard_alcaide

richard_alcaide
09 Nov 2016, 20:59

RE:

lucian said:

Try to remove any instance from cAlgo or cTrader, and close cAlgo and/or cTrader.

Reload cTrader/cAlgo and add again the instances with carefully setting of the Label.

I just did it but still doesn't work


@richard_alcaide

richard_alcaide
09 Nov 2016, 19:38

RE:

lucian said:

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 AlcaideSR : Robot
    {
        [Parameter(DefaultValue = 1000)]
        public int Volume { get; set; }

        [Parameter("Pips away", DefaultValue = 20)]
        public int PipsAway { get; set; }

        [Parameter("TP", DefaultValue = 60)]
        public int tp { get; set; }

        [Parameter("SL", DefaultValue = 20)]
        public int sl { get; set; }

        [Parameter("Label", DefaultValue = "Rich")]
        //Use different Label for different instance
        public string Label { get; set; }

        [Parameter("Buy ?", DefaultValue = true)]
        public bool buy { get; set; }




        protected override void OnStart()
        {

            Positions.Opened += OnPositionsOpened;

            if (Positions.Count == 0 && buy)
            {
                var buyOrderTargetPrice = Symbol.Ask - PipsAway * Symbol.PipSize;
                PlaceLimitOrder(TradeType.Buy, Symbol, Volume, buyOrderTargetPrice, Label, sl, tp);
            }
            if (Positions.Count == 0 && !buy)
            {
                var sellOrderTargetPrice = Symbol.Bid + PipsAway * Symbol.PipSize;
                PlaceLimitOrder(TradeType.Sell, Symbol, Volume, sellOrderTargetPrice, Label, sl, tp);
            }
        }

        void OnPositionsOpened(PositionOpenedEventArgs args)
        {

            var originalPosition = args.Position;

            if (originalPosition.TradeType == TradeType.Buy && originalPosition.Label == Label)
            {
                var sellOrderTargetPrice = Symbol.Bid - PipsAway * Symbol.PipSize;
                PlaceStopOrder(TradeType.Sell, Symbol, Volume, sellOrderTargetPrice, Label, sl, tp);
                //break; // optional break to hedge only one position
            }
            else
            {
                var buyOrderTargetPrice = Symbol.Ask + PipsAway * Symbol.PipSize;
                PlaceStopOrder(TradeType.Buy, Symbol, Volume, buyOrderTargetPrice, Label, sl, tp);
                //break; // optional break to hedge only one position
            }

        }



    }
}

 

Thanks Lucian no error now but still it doesn't fix the issue :(


@richard_alcaide

richard_alcaide
09 Nov 2016, 17:58 ( Updated at: 21 Dec 2023, 09:20 )

RE:

lucian said:

change:

  void OnPositionsOpened(PositionOpenedEventArgs args)
        {

            var originalPosition = args.Position;

            if (originalPosition.TradeType == TradeType.Buy)

with:

  void OnPositionsOpened(PositionOpenedEventArgs args)
        {

            var originalPosition = args.Position;

            if (originalPosition.TradeType == TradeType.Buy && originalPosition.Label==Label)

 

Lucian there was an error


@richard_alcaide

richard_alcaide
18 Oct 2016, 20:08

RE: RE:

Hi Lucian I still can't make it work, can you give me sample how to code this please..

Try to put volume sequence in a list:

var Buy_sequence= new List{1000, 1000, 1900};

and use Buy_sequence[0] for first buy pending order,  Buy_sequence[1] for second buy pending order, etc.

 

 

 

 


@richard_alcaide

richard_alcaide
14 Oct 2016, 13:29

RE:

Thank You Lucian..

Try to put volume sequence in a list:

var Buy_sequence= new List{1000, 1000, 1900};

and use Buy_sequence[0] for first buy pending order,  Buy_sequence[1] for second buy pending order, etc.

 

 

 


@richard_alcaide

richard_alcaide
14 Oct 2016, 13:28

RE:

Hi Lucian, I just tried to run this bot in multiple pairs but the problem is every time there is a pair that execute a market order the other pairs also execute a market order, how can I prevent this to happen?

Start backtest with this code:

 

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 sergie : Robot
    {

        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }
        [Parameter("Buy ?", DefaultValue = true)]
        public bool buy { get; set; }
        protected override void OnStart()
        {

            Positions.Closed += closedposition;
            if (buy)
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "sergio", 10, 10);
            if (!buy)
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "sergio", 10, 10);

        }

        public void closedposition(PositionClosedEventArgs arg)
        {
            var pos = arg.Position;
            if (((pos.Label == "sergio") && (pos.NetProfit > 0) && (pos.TradeType == TradeType.Sell)) || ((pos.Label == "sergio") && (pos.NetProfit < 0) && (pos.TradeType == TradeType.Buy)))
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "sergio", 10, 10);
            if (((pos.Label == "sergio") && (pos.NetProfit < 0) && (pos.TradeType == TradeType.Sell)) || ((pos.Label == "sergio") && (pos.NetProfit > 0) && (pos.TradeType == TradeType.Buy)))
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "sergio", 10, 10);

        }

    }
}

 

 

 


@richard_alcaide

richard_alcaide
11 Oct 2016, 02:34

RE:

lucian said:

You can try something like this:

 

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 alcaide : Robot
    {

        [Parameter("Volume", DefaultValue = 1000)]
        public int Volume { get; set; }

        protected override void OnStart()
        {
            Positions.Opened += openedposition;
            PlaceStopOrder(TradeType.Sell, Symbol, Volume, Symbol.Ask - (5 * Symbol.PipSize), Volume.ToString());

        }

        public void openedposition(PositionOpenedEventArgs arg)
        {
            var pos = arg.Position;
            var volume = pos.Label;
            int vol = Int32.Parse(volume);
            vol = Volume + vol;
            PlaceStopOrder(TradeType.Sell, Symbol, vol, pos.EntryPrice - (5 * Symbol.PipSize), vol.ToString());

        }

    }
}

 

Thanks Lucian but with your code given how can I create a pending order sequence like these below?

Pending Buy Order = 1000, 1000, 1900
Pending Sell Order = 1400, 1400, 2500

 


@richard_alcaide

richard_alcaide
09 Oct 2016, 09:05

RE:

lucian said:

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 richard : Robot
    {
        [Parameter("Buy ?")]
        public bool buy { get; set; }
        [Parameter("Sell ?")]
        public bool sell { get; set; }
        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnBar()
        {
            if (Positions.Count == 0 && buy)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "Label", null, null, null);
            }
            if (Positions.Count == 0 && sell)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "Label", null, null, null);
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 

Many thanks Lucian I just backtested it and it works!


@richard_alcaide

richard_alcaide
09 Oct 2016, 09:01

RE:

lucian said:

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 richard : Robot
    {
        [Parameter("Buy ?")]
        public bool buy { get; set; }
        [Parameter("Sell ?")]
        public bool sell { get; set; }
        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnBar()
        {
            if (Positions.Count == 0 && buy)
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "Label", null, null, null);
            }
            if (Positions.Count == 0 && sell)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "Label", null, null, null);
            }
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

 

Many thanks Lucian I just backtested it and it works!


@richard_alcaide