Response to FAQ I want an EA to Close order at TakeProfit and StopLoss

 

I believe I have seen this request a few times so with my best programmers hat on I have written the following, yet to test it on demo account criticisms please

Note it was written for clarity not efficiency - I'll screem if you also ask for it to place a trade at price :-)

(maybe I will add that much much later)

Files:
 

Your ClosePrice() function has an error in it, why not simply use OrderClosePrice(), then you don't need your ClosePrice() function.

Also, this is incorrect . . "1 pip = smallest decimal place of Broker" IMO

And you don't need the ND or NormalizeDouble() . . .

 

ClosePrice - OrderClosePrice() - Lack of experience will change *edit - have changed

1 pip definition taken from investopedia "The smallest price change that a given exchange rate can make. Since most major currency pairs are priced to four decimal places, the smallest change is that of the last decimal point..."

There is some old school 4 decimial place people who refer to the 5th dp as a tenth of a pip but when you read the definition its the smalest change - very confusing to new trader like me!

Thinking behind NormalizeDouble() was to stop user (deliberate error?) of too many decimal places. I just hate seeing NormalizeDouble() in equations - its just too long!

*edit

Perhaps it should read 1 pip = smallest change in currency pair?

 

This error message is incorrect:

   Ticket=GetTicket() ;
   if (Ticket < 0)     
     { 
      RemoveEA("Negative or Zero SL/TP is not supported") ;
     }

With regards to a pip, I regard a pip as the 4th digit on 5 digit pairs, the 2nd digit on 3 digit pairs, etc . . . pip is a potentially ambiguous term, why not just use point ?

Shouldn't the Order you are managing have SL and/or TP set to zero ? shouldn't you check that is the case ?

Regarding NormalizeDouble: a user cannot cause too many decimal places, the user input is by way of extern ints . . . you don't need the NormalizeDouble.

 
Ickyrus:

As Per above - changes made- see attached file

1. SL and TP of watched order should not matter - if the order is closed manually or by SL/TP then the EA would Alert that the ticket it is watching has been closed.

2. I am right in thinking that the extern values are static?

3. Where int2text just does a type conversion on an int value.

1. it just seemed to me that managing an order with SL and/or TP set defeats the purpose of the code and is most likely the result of a mistake by the user.

2. yes I think so . . . but they are reset to their set values on timeframe and variable change (F7)

3. I prefer to use StringConcatenate(), then there is no need for the int2text.

RemoveEA( StringConcatenate( "Ticket ", Ticket, " Now Closed - EA removed from chart" ) ) ;
Reason: