noob here, can you please give an example of simple open order

Created at 05 Jul 2013, 17:18
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!
ST

stoko

Joined 05.07.2013

noob here, can you please give an example of simple open order
05 Jul 2013, 17:18


Hi,

Could you guy give an example with simple open order code.

I want simple cBot that opens 1 order with stop loss and take profit values and as soon the order is closed to have a new one opened.

I will then start from there my cBot coding.

 

Maybe its already done and I am just spamming!!! Please delete this post if so.

 

Thanks!


@stoko
Replies

cAlgo_Fanatic
05 Jul 2013, 17:53

UPDATED:

 

//  ​The cBot when started will execute an  order, setting Take Profit and Stop Loss.
//  In the event that the position opens it prints a message to the log.
//  In the event that the position closes it prints a message to the log and executes another order.

using cAlgo.API;

namespace cAlgo.Robots.Samples
{
    [Robot()]
    public class SampleBuyOrder : Robot
    {
        [Parameter("Buy", DefaultValue = true)]
        public bool TradeTypeBuy { get; set; }

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

        [Parameter(DefaultValue = "myLabel")]
        public string cBotLabel { get; set; }

        
        [Parameter(DefaultValue = 10)]
        public double TakeProfitPips { get; set; }
        
        [Parameter(DefaultValue = 10)]
        public double StopLossPips { get; set; }

        protected TradeType cBotTradeType
        {
            get { return TradeTypeBuy ? TradeType.Buy : TradeType.Sell; }
        }
 
        protected override void OnStart()
        {
            Positions.Opened += OnPositionsOpened;
            Positions.Closed += OnPositionsClosed;

            ExecuteMarketOrder(cBotTradeType, Symbol, Volume, cBotLabel, StopLossPips, TakeProfitPips);
        }

        protected void OnPositionsOpened(PositionOpenedEventArgs args)
        {
            var position = args.Position;
            if (position.Label == cBotLabel)
                Print("Position opened by cBot");
        }

        private void OnPositionsClosed(PositionClosedEventArgs args)
        {
            var position = args.Position;
            if (position.Label == cBotLabel)
                Print("Position closed by cBot");

            ExecuteMarketOrder(cBotTradeType, Symbol, Volume, cBotLabel, StopLossPips, TakeProfitPips);
        }
    }
}

 


@cAlgo_Fanatic

stoko
05 Jul 2013, 18:09

RE:

impressive fast reply!!

I was just going to see if I can close my post becasue I used your Martingale Sample to figure out how to do it.

Your code is super helpful!

 

Thanks!


@stoko