Don't execute order

Created at 06 Nov 2020, 01:58
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!
MG

mgpublic

Joined 06.11.2020

Don't execute order
06 Nov 2020, 01:58


Hello,

I want help with code to not execute order if something occurs.

What is the opposite of the code below when I dont want to execute order.

  if (XXXXXX)
                {
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, label, StopLossInPips, TakeProfitInPips);

                    consolidation = 0;

Thx for help!


@mgpublic
Replies

PanagiotisCharalampous
06 Nov 2020, 08:26

Hi mgpublic,

Can you be more specific. Do you want the order to execute when XXXXX is false?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

mgpublic
06 Nov 2020, 20:15

RE:

PanagiotisCharalampous said:

Hi mgpublic,

Can you be more specific. Do you want the order to execute when XXXXX is false?

Best Regards,

Panagiotis 

Join us on Telegram

Hi,

Thx for help! I'm searching for a code to limit max open positions and I found the one below. I want help to make the code to work. Can you help me with the code to not execute a new order if max positions is open. Thx again'!

        [Parameter(DefaultValue = 1, MinValue = 1)]
        public int MaxPositions { get; set; }

        protected override void OnTick()
        {
            if (Positions.Count < MaxPositions)
            {
                // Do somehting
            }
        }

        protected override void OnStop()
        {

        }


@mgpublic

PanagiotisCharalampous
09 Nov 2020, 08:31

Hi mgpublic,

If you write your execution code inside the if statement, it should work as you expect it to work.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

mgpublic
10 Nov 2020, 00:07

RE:

PanagiotisCharalampous said:

Hi mgpublic,

If you write your execution code inside the if statement, it should work as you expect it to work.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

Thx! I will try.

//mgpublic

 


@mgpublic

mgpublic
10 Nov 2020, 12:51

RE:

PanagiotisCharalampous said:

Hi mgpublic,

If you write your execution code inside the if statement, it should work as you expect it to work.

Best Regards,

Panagiotis 

Join us on Telegram

Hi again Panagiotis,

I need more help. Can you help with the code how to maximize for example 50 positions but max 1 of a kind? (See the code above early in this conversation)

For example I want max 50 positions total but only five position of AUDUSD at a time? I want to use multiple instances and dont want for example the bot to open 50 AUDUSD only.

Thanks again!

 


@mgpublic

PanagiotisCharalampous
10 Nov 2020, 14:15

Hi mgpublic,

You can use conditions in your Count() method like below

            if (Positions.Count(x => x.SymbolName == "AUDUSD") < 5)
            {
                // Do something
            }

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

mgpublic
10 Nov 2020, 16:11

RE:

PanagiotisCharalampous said:

Hi mgpublic,

You can use conditions in your Count() method like below

            if (Positions.Count(x => x.SymbolName == "AUDUSD") < 5)
            {
                // Do something
            }

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

Thx again! I will try.

//mgpublic


@mgpublic

mgpublic
11 Nov 2020, 17:59

RE:

PanagiotisCharalampous said:

Hi mgpublic,

You can use conditions in your Count() method like below

            if (Positions.Count(x => x.SymbolName == "AUDUSD") < 5)
            {
                // Do something
            }

Best Regards,

Panagiotis 

Join us on Telegram

Hi again Panagiotis,

Sorry but I don't get it to work as I want. For example I want max 10 positions and max 5 EURUSD and 5 GBPUSD.

I'm using the code below and it only opens 5 positions, either EURUSD or GBPUSD. What i'm I doing wrong?

protected override void OnTick()
        {
            if (Positions.Count < MaxPositions)
                if (Positions.Count(x => x.SymbolName == "EURUSD") < 5)
                    if (Positions.Count(x => x.SymbolName == "GBPUSD") < 5)

//mgpublic


@mgpublic

PanagiotisCharalampous
13 Nov 2020, 14:56

Hi mgpublic,

The code snippet does not help me understand the problem. You need to provide to complete cBot code.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

mgpublic
13 Nov 2020, 21:13

RE:

PanagiotisCharalampous said:

Hi mgpublic,

The code snippet does not help me understand the problem. You need to provide to complete cBot code.

Best Regards,

Panagiotis 

Join us on Telegram

Hi,

I solved it. Thx again for all the help!

//mgpublic


@mgpublic