Download MetaTrader 5
To add comments, please log in or register
Did you like the article? Share it with your friends!
arkan1976_6
9
arkan1976_6 2016.10.01 21:36 
hello all, please,  It is possible to modify this code to Buy_TP and Sell_TP be equal to the opening price of the current candle?
Thanks.
CODE: [SELECT ALL]
  1.  
  2. extern double Buy_TP=1.3000; //Here be open price current candle
  3. extern double Buy_SL=0;
  4. extern double Sell_TP=1.3000; //Here be open price current candle
  5. extern double Sell_SL=0;
  6. //+------------------------------------------------------------------+
  7. //| expert initialization function |
  8. //+------------------------------------------------------------------+
  9. int init()
  10. {
  11. //----
  12.  
  13. //----
  14. return(0);
  15. }
  16. //+------------------------------------------------------------------+
  17. //| expert deinitialization function |
  18. //+------------------------------------------------------------------+
  19. int deinit()
  20. {
  21. //----
  22.  
  23. //----
  24. return(0);
  25. }
  26. //+------------------------------------------------------------------+
  27. //| expert start function |
  28. //+------------------------------------------------------------------+
  29. int start()
  30. {
  31. //----
  32. int HowDeepIsYourLove = OrdersTotal();
  33. double TP,SL;
  34. for(int z=0;z<HowDeepIsYourLove;z++) {
  35. if(OrderSelect(z,SELECT_BY_POS,MODE_TRADES)) {
  36. if(OrderType()==OP_BUY||OrderType()==OP_BUYSTOP||OrderType()==OP_BUYLIMIT) {
  37. TP=NormalizeDouble(Buy_TP,Digits);
  38. SL=NormalizeDouble(Buy_SL,Digits);
  39. if(OrderTakeProfit()!=TP||OrderStopLoss()!=SL) {
  40. if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,CLR_NONE))
  41. Print("Something happened in BuyHood =), error#"+GetLastError());
  42. }
  43. } else if(OrderType()==OP_SELL||OrderType()==OP_SELLSTOP||OrderType()==OP_SELLLIMIT) {
  44. TP=NormalizeDouble(Sell_TP,Digits);
  45. SL=NormalizeDouble(Sell_SL,Digits);
  46. if(OrderTakeProfit()!=TP||OrderStopLoss()!=SL) {
  47. if(!OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,CLR_NONE))
  48. Print("Something happened in SellHood =), error#"+GetLastError());
  49. }
  50. }
  51. }
  52. }
  53. //----
  54. return(0);
  55. }
  56. //+------------------------------------------------------------------+
whroeder1
13641
whroeder1 2016.10.02 12:45  
arkan1976_6  It is possible to modify this code to Buy_TP and Sell_TP be equal to the opening price of the current candle?
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Of course it's possible.
    learn to code it, or pay someone. We're not going to code it FOR you.
    We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
  3. But what will you do if you exceed limits. Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
arkan1976_6
9
arkan1976_6 2016.10.02 16:47  
thanks for answer.I tried this change, will be correct ? thanks
double    price=iOpen(Symbol(),0,0);
double    Buy_TP=price; 
double    Buy_SL=0;
double    Sell_TP=price;
double    Sell_SL=0;
// + ----------------------------------------------- ------------------- +
// | función de inicialización experto |
// + ----------------------------------------------- ------------------- +
int  init ( )
{
// ----
 
// ----
retorno ( 0 ) ;
}
// + ----------------------------------------------- ------------------- +
// | función deinicialización experto |
// + ----------------------------------------------- ------------------- +
int  deinit ( )
{
// ----
 
// ----
retorno ( 0 ) ;
}
// + ----------------------------------------------- ------------------- +
// | Función de arranque experto |
// + ----------------------------------------------- ------------------- +
int  inicio ( )
{
// ----
int  HowDeepIsYourLove  =  OrdersTotal ( ) ;
doble  TP, SL ;
para ( int  z = 0 ; z < HowDeepIsYourLove ; z ++ )  {
si ( OrderSelect ( z, SELECT_BY_POS , MODE_TRADES ) )  {
si ( OrderType ( ) == OP_BUY || OrderType ( ) == OP_BUYSTOP || OrderType ( ) == OP_BUYLIMIT )  {
TP = NormalizeDouble ( Buy_TP, Dígitos ) ;
SL = NormalizeDouble ( Buy_SL, Dígitos ) ;
si ( OrderTakeProfit ( ) ! = TP || OrderStopLoss ( ) ! = SL )  {
si ( ! OrderModify ( OrderTicket ( ) , OrderOpenPrice ( ) , SL, TP, 0 , CLR_NONE ) )
Imprimir ( "Algo pasó en BuyHood =), el error #" + GetLastError ( ) ) ;
}
}  Demás  si ( OrderType ( ) == OP_SELL || OrderType ( ) == OP_SELLSTOP || OrderType ( ) == OP_SELLLIMIT )  {
TP = NormalizeDouble ( Sell_TP, Dígitos ) ;
SL = NormalizeDouble ( Sell_SL, Dígitos ) ;
si ( OrderTakeProfit ( ) ! = TP || OrderStopLoss ( ) ! = SL )  {
si ( ! OrderModify ( OrderTicket ( ) , OrderOpenPrice ( ) , SL, TP, 0 , CLR_NONE ) )
Imprimir ( "Algo pasó en SellHood =), el error #" + GetLastError ( ) ) ;
}
}
}
}
// ----
retorno ( 0 ) ;
}
// + ----------------------------------------------- ------------------- +
Fernando Carreiro
1520
Fernando Carreiro 2016.10.02 17:43  
arkan1976_6: I tried this change, will be correct?

Why are you writing your code with the built-in function names translated into Spanish? You cannot just change MQL's function names into another human language just on a whim? You must use the proper original names of MQL! There is no "si", "para", "retorno", "Imprimir", etc.! You must to use "if", "for", "return", "Print", etc.

You should first learn coding in general, so that you can understand the basics of coding before trying to code your own Indicator or EA. It is of no use to anyone if you don't first learn the basics. This can take many months (even a couple of years), for a complete beginner, to properly learn to code Indicators or EAs. You need time to properly gain the necessary knowledge and coding experience for it. Obviously, if you are serious about it and have the dedication to stick with it, then go for it. But remember that it is a long-term project, and not short term.

If however, you are not serious about learning to code, or you need a solution quickly, then please consider hiring someone to code for you. Go to the Freelance section and place a Job advert, stating your budget and describing your requirements.

whroeder1
13641
whroeder1 2016.10.02 19:35  
arkan1976_6: I tried this change, will be correct ? thanks
  1. All you did was translate your original post. That is nonsense. Babel. No attempt.
  2. Where do you try to Buy_TP and Sell_TP be equal to the opening price of the current candle? You didn't! No attempt.
  3. learn to code it, or pay someone. We're not going to code it FOR you.
    We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
/
To add comments, please log in or register