Take Profit from EMA value creeps higher

Created at 31 Jan 2025, 09:47
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!
JE

Jexodus

Joined 15.04.2023

Take Profit from EMA value creeps higher
31 Jan 2025, 09:47


I have a robot that calls the following method from within OnBarClosed():

        private void AdjustTakeProfitLevels()        {            if (Positions.Count > 0)            {                foreach (var position in Positions)                {                    if (position.SymbolName == Symbol.Name)                    {                    	var tpValue = Math.Round(_tpEma.Result.LastValue, Symbol.Digits);                        ModifyPosition(position, null, tpValue);                    }                }            }        }

The issue I have is that when the cBot is started initially, the take profits are set correctly. After running for a while (about an hour+), the take profit begins to be set higher than the EMA. An example is in the image below. the purple line is set to represent the take profit EMA.  The actual take profit is being set by the cBot.  

Is there anything I might be missing that might be causing this issue? At the moment, I just restart the cBot and it corrects the take profit, but after a while it drifts higher again.

Thanks in advance for any help you can provide.


@Jexodus
Replies

firemyst
07 Feb 2025, 02:54 ( Updated at: 14 Feb 2025, 18:18 )

Try rounding to (Symbol.Digits + 1) instead of just Symbol.Digits

 

 


@firemyst