Topics
18 Nov 2020, 00:19
 1433
 4
08 Nov 2020, 23:37
 961
 3
06 Nov 2020, 01:58
 1491
 11
Replies

mgpublic
18 Nov 2020, 01:08

RE: RE:

mparama said:

mgpublic said:

Hi,

I need help with the code below so that it only closes the position with the indicated SymbolName for example "USDJPY"

I'm using the code below and it closes all positions.

if ()                   

{
foreach (var position in Positions)
ClosePositionAsync(position);
}

Thx for help!

//mgpublic

You should use:

            var posBuy = Positions.FindAll(Label, SymbolName, TradeType.Buy);
            var posSell = Positions.FindAll(Label, SymbolName, TradeType.Sell);

           

if ()                   

{
foreach (var position in posBuy)
ClosePositionAsync(position);
}

Thx for reply and help.

How do I code so that it finds and closes the position with SymbolName "USDJPY" either if its posBuy or posSell. In the example above its only posBuy.


@mgpublic

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

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

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

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
09 Nov 2020, 21:27

RE:

PanagiotisCharalampous said:

Hi mgpublic,

You can use the Stop() method to do so.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

Thank you very much! Works fine!

Best Regards,

mgpublic


@mgpublic

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