I need a piece of code that returns the close price of a certain candle after a trade is opened. "The order is still open". I want to know the price of different candles every time I run the EA. this code must count the candles (according to the number I set in the expert specification everytime I run the expert) and returns that candle's close price NOT THE ORDER CLOSE PRICE. it must be in the form of: double (pip-difference) . . . . . . . . . return (pip-difference); (or any of these sort of codes, i just wrote this as an example. you decide how it must be). Here is another example of what I want: //================================================================================================ double LotsOptimized() { double lot=Lots; int orders=HistoryTotal(); // history orders total int losses=0; // number of losses orders without a break //--- select lot size lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1); //--- calcuulate number of losses orders without a break if(DecreaseFactor>0) { . . . . . . . if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1); } //--- return lot size if(lot<0.1) lot=0.1; return(lot); } //===================================================================================================== I want to call this function anywhere in the EA I want. So it must be a separeate function. it must work in all the mt4 experts. Just like the example above, It must return a value only. Conditions: 1. all the variables and things that this code needs must be inside itself. the only variable that is allowed to be outside of the code is "extern double candle_number = .... " which is the number of candles that i set every time i run my expert. Only this variable MUST be outside of the code and I put it in my expert( this is a MUST and is very important). 2. every time a trade is opened, this code must count the candles ( according to what I set for candle number) and returns the close price of the CANDLE (the order is still open). 3.It gets only one input as "Extern Double" ( which I ditermine every time I run my expert and I should be able to change it anytime I want) The only job this code must do is: imagine I determine the candle_number=5, When a trade is opened, this code must return the close of the 5th candle from the trade open. If I set the candle_number = 13, any position that is opened, this code must return the 13th candle's close price. please see the images to get the exact idea. Important note: I set the days of finishing this job for 5 days because of checking and revising, So please finish the code in 1-2 days so, we have enough time to test and revise it. In the testing and revising the code, I may add or delete some things from the code,like if I forgot something in the explanation above, so please accept that in advance.