Replies

Kevin
20 Apr 2015, 20:22

Thank you so much, this will be a great help!  :D


@Kevin

Kevin
13 Apr 2015, 21:16

The idea is to prevent a limit order being filled after the winning value has been reached.


@Kevin

Kevin
09 Dec 2013, 00:06

Ahahaha, wow i'm so stupid. Problem solved:

PlaceLimitOrder(TradeType.Sell, Symbol, 10000, Symbol.Sell + 0.5 * Symbol.PipSize, nullnullnull, expiry

I had replaced "Bid" with "Sell" by mistake thinking it said "Buy"


@Kevin

Kevin
09 Dec 2013, 00:02

Adding "using System" solves the problem with the buy order, but another fault comes up with the sell order:

 

private void Sell()
        {
            DateTime expiry = Server.Time.AddMinutes(5);
            PlaceLimitOrder(TradeType.Sell, Symbol, 10000, Symbol.Sell + 0.5 * Symbol.PipSize, nullnullnull, expiry);
        }

 

Error: 'cAlgo.API.Internals.Symbol' does not contain a definition for 'Sell" and no extension method 'Sell" accepting a first arguement or type 'cAlgo.API.Internals.Symbol' could not be found (are you missing a using directive o...


@Kevin

Kevin
08 Dec 2013, 02:38

Using system..?


@Kevin

Kevin
06 Dec 2013, 20:35

Aha, I didn't know about the Null bit. It still doesn't like it though:

Error: The type or namespace name 'DateTime' could not be found (are you missing a using directive or an assembly reference?)


@Kevin

Kevin
06 Dec 2013, 15:16

I have also played around with this:

public TradeResult PlaceLimitOrder(TradeType tradeType, Symbol symbol, long volume, double targetPrice, string label, int? stopLossPips, int? takeProfitPips, DateTime? expiration, string comment)

But keep having the same problem.


@Kevin

Kevin
06 Dec 2013, 12:25

I've done it! Thanks again for your help, I have a much better understanding of C# now.


@Kevin

Kevin
06 Dec 2013, 01:39

Hi, thanks for that   :)   Yes much adjustent needed *fingers-crossed*.

I also want a similar robot that places trades based on the crossover of MacD and Signal lines, relative to each other. If the histo crosses above signal, buy. If it crosses down, sell. Simples. But I can't find anything on here. I found the HasCrossedBelow function but am not having much luck with it   :(

Any help would be much appreciated and thanks again for the above.


@Kevin

Kevin
05 Dec 2013, 23:33

It's ok, I did it. Learning all the time!  :)

 

Thanks for your help.


@Kevin

Kevin
05 Dec 2013, 22:08

C# is completely new to me (how i've managed to get this far is a wonder). So could you write this for me pleeeeeeease   :D

 

My total code at the moment is:

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    [Robot()]
    public class 30k : Robot
    {
        private MacdHistogram _macd;
        private Position _position;

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

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

        [Parameter("Long Cycle", DefaultValue = 22)]
        public int LongCycle { get; set; }

        [Parameter("Short Cycle", DefaultValue = 9)]
        public int ShortCycle { get; set; }

        protected override void OnStart()
        {
            _macd = Indicators.MacdHistogram(LongCycle, ShortCycle, Period);
        }

        protected override void OnBar()
        {
            if (Trade.IsExecuting)
                return;

            bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
            bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;

            if (_macd.Histogram.LastValue > 0.0 && _macd.Signal.IsRising() && !isLongPositionOpen)
            {
                ClosePosition();
                Buy();
            }

            if (_macd.Histogram.LastValue < 0.0 && _macd.Signal.IsFalling() && !isShortPositionOpen)
            {
                ClosePosition();
                Sell();
            }
        }
        private void ClosePosition()
        {
            if (_position != null)
            {
                Trade.Close(_position);
                _position = null;
            }
        }

        private void Buy()
        {
            Trade.CreateBuyMarketOrder(Symbol, Volume);
        }

        private void Sell()
        {
            Trade.CreateSellMarketOrder(Symbol, Volume);
        }

        protected override void OnTick()
        {
            foreach (var position in Account.Positions)
            {
                if (position.GrossProfit >= 24)
                {
                    Trade.Close(position);
                }

            }
        }
    }
}


@Kevin

Kevin
05 Dec 2013, 20:13

Awesome, thanks!  :D

I noticed you replied to my other post too and I have a similar problem with this in that I don't know how to add it to the code I already have.

Also, I can change the email address as that is quite clear, but where do I edit/add the account balance or percentage?


@Kevin

Kevin
05 Dec 2013, 20:09

I saw that (or something similar) but don't know how to introduce that to my code:

 

        protected override void OnBar()
        {
            if (Trade.IsExecuting)
                return;

            bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
            bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;

            if (_macd.Histogram.LastValue > 0.0 && _macd.Signal.IsRising() && !isLongPositionOpen)
            {
                ClosePosition();
                Buy();
            }

            if (_macd.Histogram.LastValue < 0.0 && _macd.Signal.IsFalling() && !isShortPositionOpen)
            {
                ClosePosition();
                Sell();
            }
        }
        private void ClosePosition()
        {
            if (_position != null)
            {
                Trade.Close(_position);
                _position = null;
            }
        }

        private void Buy()
        {
            Trade.CreateBuyMarketOrder(Symbol, Volume);
        }

        private void Sell()
        {
            Trade.CreateSellMarketOrder(Symbol, Volume);
        }

        protected override void OnTick()
        {
            foreach (var position in Account.Positions)
            {
                if (position.GrossProfit >= 9)
                {
                    Trade.Close(position);
                }

            }
        }
    }
}


@Kevin