Open position

Created at 09 Mar 2018, 09:06
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!
JJ

jjwes76@gmail.com

Joined 03.11.2017

Open position
09 Mar 2018, 09:06


My cbot is opening a first  sell position on Bar how do get the cbot not to open another position unless my first position is in profit

can sumone please explane


@jjwes76@gmail.com
Replies

PanagiotisCharalampous
09 Mar 2018, 09:13

Hi jjwes76@gmail.com,

You can use the NetProfit property of the opened position to check if is profitable. If you most your cBot code, I might be able to modify it accordingly for you.

Best Regards,

Panagiotis


@PanagiotisCharalampous

jjwes76@gmail.com
09 Mar 2018, 10:36

RE:

Panagiotis Charalampous said:

Hi jjwes76@gmail.com,

You can use the NetProfit property of the opened position to check if is profitable. If you most your cBot code, I might be able to modify it accordingly for you.

Best Regards,

Panagiotis

{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BuyBot : Robot
    {
        [Parameter("Source")]
        public DataSeries Source { get; set; }

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

        [Parameter("Instance Name", DefaultValue = "SampleRSI")]
        public string InstanceName { get; set; }

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


        [Parameter("Source SMA #1")]
        public DataSeries SourceSma1 { get; set; }

        [Parameter("Period SMA #1", DefaultValue = 150)]
        public int PeriodsSma1 { get; set; }







        [Parameter("Source EMA #1")]
        public DataSeries SourceEma1 { get; set; }

        [Parameter("MAType EMA #1", DefaultValue = MovingAverageType.Exponential)]
        public MovingAverageType MaType { get; set; }

        [Parameter("Period EMA #1", DefaultValue = 5000)]
        public int PeriodsEma1 { get; set; }



        [Parameter("RSI BUY", DefaultValue = 20)]
        public int RsiBuy { get; set; }


        private RelativeStrengthIndex rsi { get; set; }
        private SimpleMovingAverage _sma1 { get; set; }
        private ExponentialMovingAverage _emaSlow { get; set; }


        protected override void OnStart()
        {

            _sma1 = Indicators.SimpleMovingAverage(SourceSma1, PeriodsSma1);
            rsi = Indicators.RelativeStrengthIndex(Source, Periods);
            _emaSlow = Indicators.ExponentialMovingAverage(SourceEma1, PeriodsEma1);

        }

        protected override void OnBar()
        {
            if (rsi.Result.LastValue < RsiBuy)


                if (_sma1.Result.LastValue < _emaSlow.Result.LastValue)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, "Instance Name", nullnull);
                    {
                    }
                }
        }
    }

}

The cbot can open positions if the price is higher on open buy positions but not lower on the open buy positions

and lower on sell positions but not higher

I want the cbot to open a trade evry minute  if those conditions are met i do have a cbot that will stop the trades if the market turn against me

thank you


@jjwes76@gmail.com

PanagiotisCharalampous
09 Mar 2018, 11:35

Hi jjwes76@gmail.com,

What happens if many positions are open?

Best Regards,

Panagiotis


@PanagiotisCharalampous

jjwes76@gmail.com
09 Mar 2018, 12:08

I have two cbots running with this one protecting me from blowing my acc if all the conditions are met the cbot can open as meny trade as it wants 

 


@jjwes76@gmail.com

PanagiotisCharalampous
09 Mar 2018, 12:13

Hi,

Regarding your first question on how to avoid executing an order if one position is open has negative profit, you can use a condition like the following

if (Positions.Count == 0 || Positions[0].NetProfit > 0)

However it is still vague to me what you are trying to do, so I cannot advise you how to properly use it in your code.

Best Regards,

Panagiotis


@PanagiotisCharalampous

jjwes76@gmail.com
09 Mar 2018, 12:28

Conditions to open a buy position

1) Rsi must be oversold

2) 100 SMA  must be under the 500 EMA

3) if a buy position is opened the cbot can open another position if  NO 1 and NO 2 are met and the first position is not in profit

i do not want the cbot to open a trade if one of my trades is in profit

is this a good explination


@jjwes76@gmail.com

ClickAlgo
09 Mar 2018, 17:37

Hi, JJwes,

It looks like you may need some professional help, we can offer you programming assistance much faster than posting on forums and waiting for a reply, why not visit us at ClickAlgo.com and see how we can help you with your algorithmic trading.

Paul Hayes
cTrader Specialists
Emailcontact@clickalgo.com
Phone: (44) 203 289 6573
Websitehttps://clickalgo.com


@ClickAlgo

jjwes76@gmail.com
11 Mar 2018, 17:08

thanks for your help Panagiotis i got the cbot to work


@jjwes76@gmail.com

jjwes76@gmail.com
21 Mar 2018, 21:42

when the sma cross above a opensell position how do i open a nother buy position


@jjwes76@gmail.com

PanagiotisCharalampous
22 Mar 2018, 09:31

Hi jjwes76@gmail.com,

You can use a condition like the one below

            if (_sma.Result.LastValue > position.EntryPrice)
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000);

Let me know if this helps,

Best Regards,

Panagiotis


@PanagiotisCharalampous

jjwes76@gmail.com
22 Mar 2018, 10:31

EntryPrice will be the open position can i add a lable or volume to code


@jjwes76@gmail.com

jjwes76@gmail.com
22 Mar 2018, 10:31

EntryPrice will be the open position can i add a lable or volume to code


@jjwes76@gmail.com

jjwes76@gmail.com
22 Mar 2018, 10:31

EntryPrice will be the open position can i add a lable or volume to code


@jjwes76@gmail.com

jjwes76@gmail.com
22 Mar 2018, 10:58

Error CS0103: The name 'position' does not exist in the current context

How do i fix this


@jjwes76@gmail.com

PanagiotisCharalampous
22 Mar 2018, 11:15

Hi jjwes76@gmail.com,

The code snippet is just an example. You need to adjust it based on your code.

Best Regards,

Panagiotis


@PanagiotisCharalampous