Replies

sergiestudillo1
17 Oct 2016, 22:14

Hello,

 

I have a new code for this condition... I have a little problem, when I executed this cbot for example in EURUSD and I stoped one position in other market, the cbot executed new orders in EURUSD.... I don't know what is the problem.

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

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

        [Parameter("Stop Loss (pips)", DefaultValue = 20, MinValue = 1)]
        public int StopLossInPips { get; set; }


        protected override void OnStart()
        {

            Positions.Closed += closedposition;
            ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Sergi", StopLossInPips, 0);
            ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "Sergi", StopLossInPips, 0);

        }

        public void closedposition(PositionClosedEventArgs arg)
        {
            var pos = arg.Position;


            if ((pos.NetProfit < 0))
                Positions.Closed -= closedposition;


            OnStart();






        }

 


@sergiestudillo1

sergiestudillo1
15 Oct 2016, 00:33

Hello all,

I have checked the cbot "TP & SL" and,  my initial intention is no good, but I've thought a new best system ( I believe...) I have modificated the Lucian code for make a sistem grid more or less....

I open 2 positions, 1 short and 1 long, every one with S.L at the "X" pips... when the price take de S.L, is opened 2 news positions short & long with de same S.L that the initials positions.

My problem is when open a new positions is opened 4 new positions. and more exponential every time the S.L is checked. I want only 2 news positions every time.
I'm crazy with this problem :-(

I dont know that I have wrong.

 

 

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; }
        public bool sell { get; set; }
        protected override void OnStart()
        {

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

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

        }

        public void closedposition(PositionClosedEventArgs arg)
        {
            var pos = arg.Position;

            if (((pos.Label == "sergio") == (pos.NetProfit < 0)))
                ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, "sergio", 2, 0);
            if (((pos.Label == "sergio") == (pos.NetProfit < 0)))
                ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "sergio", 2, 0);




        }

    }
}

 


@sergiestudillo1

sergiestudillo1
12 Oct 2016, 17:27

RE:

lucian said:

Thank you very much.

I test this cbot for if my expectatives is correct or no and only is a sweet dreams.... ;-)

 

Best regards. 

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);

        }

    }
}

 

 

 


@sergiestudillo1