# How to make the algo decide over a optimal selling point?

Please don't bully if its a basic question.Kinda new to the topic hence experimenting.
Problems to construct trading algorithm.For the example I assume I am getting a buy signal from the DMI/ADX indicator(a simple crossover) and my algorithm buys the stock.The question is now how do I make my algorithm sell the stock optimally?The indicator after the crossover might go apart and then come again together.Which precise point am I to tell the algo to sell the stocks?
Obviously no algo would give 100% success rate. But since I am new to the topic would like to know if there is already any indicator/strategy/algorithm which explains a partial/optimal solution to the problem.
Thanks

• I don't understand your question but this might be because I don't use this indicator. I seems to me that when the crossover goes the other way around you sell - does this make sense? investopedia.com/articles/trading/07/adx-trend-indicator.asp – vonjd Apr 3 '15 at 11:24
• How do I explain the algo 'what number is the other way around' ?A possible logic would be in 5 min time-frame,considering each time frame as t,if the algo finds t2>t1 then hold the stock,the moment as its rising,if t2<t1 then sell.After selling suppose t1<t3>t2 or t1>t3>t2 in such scenarios the algo fails optimally as the algo is made to exit the first time it finds a low.My question -is there any algo written for optimal exit in such trades? – guly Apr 3 '15 at 11:34