Use moving average as profit target!

Created at 26 May 2014, 23:28
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!
KT

ktzn

Joined 26.05.2014

Use moving average as profit target!
26 May 2014, 23:28


Trying to make a robot but im having some trouble defining my target

 

Its using BB and RSI to define entry and i want the exit to be the SMA in the BB. However i can only find "TakeProfitInPips" and when i then use mAverage as target it only gives 1.3 pips (on eurusd) - is there a way to work around this problem ?

 

The idea is that the target should keep being updated to be the current SMA as the bars create until the price goes through it where the positions should be closed.

 

  ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, StopLossInPips, mAverage);

 

thats what i use now.

 

Thank you in advance

 

 


@ktzn
Replies

modarkat
27 May 2014, 09:20

There are two ways to do that.

First of all you can convert moving average value to pips distance from a spot price.

Another way is to execute market order without TP and then modify TP as an absolute value.

            ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, StopLossPips, null);
            if (LastResult.IsSuccessful)
            {
                ModifyPosition(LastResult.Position, LastResult.Position.StopLoss, mAverage);
            }

 


@modarkat

ktzn
27 May 2014, 10:56

RE:

modarkat said:

There are two ways to do that.

First of all you can convert moving average value to pips distance from a spot price.

Another way is to execute market order without TP and then modify TP as an absolute value.

            ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, StopLossPips, null);
            if (LastResult.IsSuccessful)
            {
                ModifyPosition(LastResult.Position, LastResult.Position.StopLoss, mAverage);
            }

 

Thanks alot!

 

It works but not sure if it is doing exactly what i want. I want it to keep updating the target to current SMA, not just to modify the position once at entry to make target SMA.

 

The idea is that all trades should be exited as soon as price touches SMA no matter if it is long or short

 

is that possible?


@ktzn

ktzn
13 Jun 2014, 23:21

no one ? :)


@ktzn

breakermind
14 Jun 2014, 13:58

RE:

Hi,

look at this: (MA - movingAverage) something like this

        protected override void OnTick()
        {

            foreach (var position in Positions)
            {

                if (position.TradeType == TradeType.Buy)
                {
                    // TP == MA
                    ModifyPosition(position, position.StopLoss, Convert.ToInt64(Ma));
                }
                if (position.TradeType == TradeType.Sell)
                {

                    // HighMinusLow == Ma 
                    ModifyPosition(position, Convert.ToInt64(Ma), position.TakeProfit);
                }

            }

        }

 

or:

            if (Symbol.Bid > Ma)
            {
                foreach (var openedPosition in Positions)
                {
                    ClosePosition(openedPosition);
                }
                Stop();
            }

close all position is allways possible :D:D:D

Regards


@breakermind

ktzn
29 Jul 2014, 20:40

RE: RE:

Thanks Breaker!

 

Have completely forgotten to check here for a while - tried to look at what you posted but I cant get it to work according to what i have in mind :(

 

Possible to have a quick skype chat maybe, I can also post the full code here if it helps.

 

breakermind said:

Hi,

look at this: (MA - movingAverage) something like this

        protected override void OnTick()
        {

            foreach (var position in Positions)
            {

                if (position.TradeType == TradeType.Buy)
                {
                    // TP == MA
                    ModifyPosition(position, position.StopLoss, Convert.ToInt64(Ma));
                }
                if (position.TradeType == TradeType.Sell)
                {

                    // HighMinusLow == Ma 
                    ModifyPosition(position, Convert.ToInt64(Ma), position.TakeProfit);
                }

            }

        }

 

or:

            if (Symbol.Bid > Ma)
            {
                foreach (var openedPosition in Positions)
                {
                    ClosePosition(openedPosition);
                }
                Stop();
            }

close all position is allways possible :D:D:D

Regards

 


@ktzn