how to close position for certain symbol ?

Created at 24 Mar 2017, 13:15
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!
HA

handiphangceo@gmail.com

Joined 22.03.2017

how to close position for certain symbol ?
24 Mar 2017, 13:15


if i use closeposition(position); they will close all my openedposition, how if i want to close only ceertain symbol?


@handiphangceo@gmail.com
Replies

... Deleted by UFO ...

... Deleted by UFO ...

handiphangceo@gmail.com
24 Mar 2017, 15:07

thanks for replying Sir..

but i got this error

Error CS0136: A local variable named 'position' cannot be declared in this scope because it would give a different meaning to 'position', which is already used in a 'parent or current' scope to denote something else.

 

this is my code

foreach (var position in Positions)
            {
                if (position.TradeType == TradeType.Buy)
                {
                    if (((Symbol.Bid + Symbol.Ask) / 2) <= (distanceFromKijun - 0.02))
                    {

                        if (position.SymbolCode == Symbol.Code)
                        {

                            ClosePosition(position);
                        }
                        {
                        }
                    }
                    else if (position.TradeType == TradeType.Sell)
                    {
                        if (((Symbol.Ask + Symbol.Bid) / 2) >= (distanceFromKijun + 0.02))
                        {
                            foreach (var position in Positions)
                                if (position.SymbolCode == Symbol.Code)
                                {

                                    ClosePosition(position);
                                }
                            {
                            }
                        }
                    }


sorry if its messy > . <


@handiphangceo@gmail.com

handiphangceo@gmail.com
24 Mar 2017, 15:11

ups sorry i miss a line

here is the complete one

 

foreach (var position in Positions)
            {
                if (position.TradeType == TradeType.Buy)
                {
                    if (((Symbol.Bid + Symbol.Ask) / 2) <= (distanceFromKijun - 0.02))
                    {
                        foreach (var position in Positions)
                        if (position.SymbolCode == Symbol.Code)
                        {

                            ClosePosition(position);
                        }


                    }
                    else if (position.TradeType == TradeType.Sell)
                    {
                        if (((Symbol.Ask + Symbol.Bid) / 2) >= (distanceFromKijun + 0.02))
                        {
                            foreach (var position in Positions)
                            if (position.SymbolCode == Symbol.Code)
                            {

                                ClosePosition(position);
                            }
                            {
                            }
                        }
                    }


@handiphangceo@gmail.com

mindbreaker
24 Mar 2017, 18:56

        protected override void OnTick()
        {
            // Put your core logic here

            // Put your initialization logic here
            foreach (var position in Positions)
            {
                // for buy
                if (position.TradeType == TradeType.Buy)
                {
                    if (((Symbol.Bid + Symbol.Ask) / 2) <= (5 - 0.02))
                    {
                        if (position.SymbolCode == Symbol.Code)
                        {

                            ClosePosition(position);
                        }


                    }
                }
                // for sell
                if (position.TradeType == TradeType.Sell)
                {
                    if (((Symbol.Ask + Symbol.Bid) / 2) >= (5 + 0.02))
                    {
                        if (position.SymbolCode == Symbol.Code)
                        {

                            ClosePosition(position);
                        }
                    }
                }

            }
            // end foreach
        }

 


@mindbreaker

... Deleted by UFO ...

handiphangceo@gmail.com
24 Mar 2017, 19:50

excellent! it works! ^^ thank you


@handiphangceo@gmail.com