i try to make an EA but i have some trouble

 
hello :)

sorry for my terrible english

i try to make an ea but i have problems with icustom

i am using supertrend
https://www.mql5.com/en/code/8268
variables Nbr_Periods and Multiplier
and nonlagdot
https://www.mql5.com/en/code/8026
variables Price, Length, Displace, Filter, Color, ColorBarBack, Deviation

i have written some code but now i have trouble

here is my code

  1. #include <stdlib.mqh>

  2. extern int TrailingStop11 = 10;
  3. extern int NewTakeProfit11 = 30;
  4. extern int TrailingGap11 = 3;
  5. extern double BuyLots9 = 0.3;
  6. extern int BuyStoploss9 = 50;
  7. extern int BuyTakeprofit9 = 100;
  8. double gd_104 = 1.0;
  9. bool gi_112 = FALSE;

  10. int init() {
  11. Comment("");
  12. return (0);
  13. }

  14. int start() {
  15. if (Bars < 10) {
  16. Comment("Not enough bars");
  17. return (0);
  18. }
  19. if (gi_112 == TRUE) {
  20. Comment("EA Terminated.");
  21. return (0);
  22. }
  23. OnEveryTick2();
  24. return (0);
  25. }

  26. void OnEveryTick2() {
  27. TrailingStop11();
  28. TechnicalAnalysis2x5();
  29. TechnicalAnalysis2x1();
  30. }

  31. void TrailingStop11() {
  32. for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) {
  33. if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES)) {
  34. if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1) {
  35. if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop11 * gd_104 * Point)
  36. if (OrderStopLoss() < Ask - (TrailingStop11 + TrailingGap11) * gd_104 * Point) OrderModify(OrderTicket(), OrderOpenPrice(), Ask - TrailingStop11 * gd_104 * Point, Ask + (NewTakeProfit11 + TrailingStop11) * gd_104 * Point, OrderExpiration(), White);
  37. if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TrailingStop11 * gd_104 * Point)
  38. if (OrderStopLoss() > Bid + (TrailingStop11 + TrailingGap11) * gd_104 * Point) OrderModify(OrderTicket(), OrderOpenPrice(), Bid + TrailingStop11 * gd_104 * Point, Bid - (NewTakeProfit11 + TrailingStop11) * gd_104 * Point, OrderExpiration(), White);
  39. }
  40. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  41. }
  42. }

  43. void TechnicalAnalysis2x5() {
  44. if (iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) > iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) && iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0) > iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0)) IfOrderDoesNotExist6();
  45. }

  46. void IfOrderDoesNotExist6() {
  47. bool li_0 = FALSE;
  48. for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
  49. if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
  50. if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) li_0 = TRUE;
  51. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  52. }
  53. if (li_0 == FALSE) {
  54. }
  55. }

  56. void TechnicalAnalysis2x1() {
  57. if (iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) > iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) && iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0) > iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0)) IfOrderDoesNotExist3();
  58. }

  59. void IfOrderDoesNotExist3() {
  60. bool li_0 = FALSE;
  61. for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
  62. if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
  63. if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) li_0 = TRUE;
  64. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  65. }
  66. if (li_0 == FALSE) IfOrderDoesNotExist7();
  67. }

  68. void IfOrderDoesNotExist7() {
  69. bool li_0 = FALSE;
  70. for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
  71. if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
  72. if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) li_0 = TRUE;
  73. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  74. }
  75. if (li_0 == FALSE) BuyOrder9();
  76. }

  77. void BuyOrder9() {
  78. bool l_bool_4;
  79. int l_ticket_0 = OrderSend(Symbol(), OP_BUY, BuyLots9, Ask, 4, 0, 0, "My Expert", 1, 0, Blue);
  80. if (l_ticket_0 > -1) {
  81. OrderSelect(l_ticket_0, SELECT_BY_TICKET);
  82. l_bool_4 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask - BuyStoploss9 * gd_104 * Point, Ask + BuyTakeprofit9 * gd_104 * Point, 0, Blue);
  83. if (l_bool_4 == FALSE) Print("OrderModify() error - ", ErrorDescription(GetLastError()));
  84. } else Print("OrderSend() error - ", ErrorDescription(GetLastError()));
  85. }

  86. int deinit() {
  87. return (0);
}



my plan
if the supertrend indicator change to uptrend (green) and the dots are blue (uptrend) > buy
if the supertrend indicator change to downtrend (red) and the dots are red (downtrend) > sell

thank you very much
 

I have a problem too ... but the different is that I am not making a single EA at all ...
I have been thinking "where is my problem come from?" ... the answer is : "I can not
making an EA" ...

 
Montajo wrote >>
hello :)

sorry for my terrible english

i try to make an ea but i have problems with icustom

i am using supertrend
https://www.mql5.com/en/code/8268
variables Nbr_Periods and Multiplier
and nonlagdot
https://www.mql5.com/en/code/8026
variables Price, Length, Displace, Filter, Color, ColorBarBack, Deviation

i have written some code but now i have trouble

here is my code

  1. #include <stdlib.mqh>

  2. extern int TrailingStop11 = 10;
  3. extern int NewTakeProfit11 = 30;
  4. extern int TrailingGap11 = 3;
  5. extern double BuyLots9 = 0.3;
  6. extern int BuyStoploss9 = 50;
  7. extern int BuyTakeprofit9 = 100;
  8. double gd_104 = 1.0;
  9. bool gi_112 = FALSE;

  10. int init() {
  11. Comment("");
  12. return (0);
  13. }

  14. int start() {
  15. if (Bars < 10) {
  16. Comment("Not enough bars");
  17. return (0);
  18. }
  19. if (gi_112 == TRUE) {
  20. Comment("EA Terminated.");
  21. return (0);
  22. }
  23. OnEveryTick2();
  24. return (0);
  25. }

  26. void OnEveryTick2() {
  27. TrailingStop11();
  28. TechnicalAnalysis2x5();
  29. TechnicalAnalysis2x1();
  30. }

  31. void TrailingStop11() {
  32. for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) {
  33. if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES)) {
  34. if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1) {
  35. if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop11 * gd_104 * Point)
  36. if (OrderStopLoss() < Ask - (TrailingStop11 + TrailingGap11) * gd_104 * Point) OrderModify(OrderTicket(), OrderOpenPrice(), Ask - TrailingStop11 * gd_104 * Point, Ask + (NewTakeProfit11 + TrailingStop11) * gd_104 * Point, OrderExpiration(), White);
  37. if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TrailingStop11 * gd_104 * Point)
  38. if (OrderStopLoss() > Bid + (TrailingStop11 + TrailingGap11) * gd_104 * Point) OrderModify(OrderTicket(), OrderOpenPrice(), Bid + TrailingStop11 * gd_104 * Point, Bid - (NewTakeProfit11 + TrailingStop11) * gd_104 * Point, OrderExpiration(), White);
  39. }
  40. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  41. }
  42. }

  43. void TechnicalAnalysis2x5() {
  44. if (iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) > iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) && iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0) > iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0)) IfOrderDoesNotExist6();
  45. }

  46. void IfOrderDoesNotExist6() {
  47. bool li_0 = FALSE;
  48. for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
  49. if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
  50. if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) li_0 = TRUE;
  51. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  52. }
  53. if (li_0 == FALSE) {
  54. }
  55. }

  56. void TechnicalAnalysis2x1() {
  57. if (iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) > iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) && iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0) > iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0)) IfOrderDoesNotExist3();
  58. }

  59. void IfOrderDoesNotExist3() {
  60. bool li_0 = FALSE;
  61. for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
  62. if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
  63. if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) li_0 = TRUE;
  64. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  65. }
  66. if (li_0 == FALSE) IfOrderDoesNotExist7();
  67. }

  68. void IfOrderDoesNotExist7() {
  69. bool li_0 = FALSE;
  70. for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
  71. if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) {
  72. if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) li_0 = TRUE;
  73. } else Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
  74. }
  75. if (li_0 == FALSE) BuyOrder9();
  76. }

  77. void BuyOrder9() {
  78. bool l_bool_4;
  79. int l_ticket_0 = OrderSend(Symbol(), OP_BUY, BuyLots9, Ask, 4, 0, 0, "My Expert", 1, 0, Blue);
  80. if (l_ticket_0 > -1) {
  81. OrderSelect(l_ticket_0, SELECT_BY_TICKET);
  82. l_bool_4 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask - BuyStoploss9 * gd_104 * Point, Ask + BuyTakeprofit9 * gd_104 * Point, 0, Blue);
  83. if (l_bool_4 == FALSE) Print("OrderModify() error - ", ErrorDescription(GetLastError()));
  84. } else Print("OrderSend() error - ", ErrorDescription(GetLastError()));
  85. }

  86. int deinit() {
  87. return (0);
}



my plan
if the supertrend indicator change to uptrend (green) and the dots are blue (uptrend) > buy
if the supertrend indicator change to downtrend (red) and the dots are red (downtrend) > sell

thank you very much


supertrend has two colored lines, buffer 1 and buffer 2. You need to access both and compare.
Look iCustom for to access the buffers then you will find out when they change from uptrend to downtrend
 

Hi there,

I have never used custom indicators, but a quick scan of the code reveals the following :-

Have a look at this statement on line 50

iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) > iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0)
What is the point of this, as it is comparing something to itself? The second part of the statments should be different to the first part in some way else this statment will ALWAYS result in false. For example :-

if (1 > 1) {Do_This}
will always be false and the "Do_This" routine will never ever be executed.

Also just a comment on your coding.....I am not one to judge as I am still learning, but I would imagine that it would be better to avoid calling functions from within functions. Where possible, create a function to do a specific task(preferably only 1) and use the result of that function to branch off from a central control point rather than dashing from place to place.

I would rather have the program flow look something like this :-

if (TechnicalAnalysis2x5() == true)IfOrderDoesNotExist6();
//======================Other Code========================


//===================End Other Code=======================
bool TechnicalAnalysis2x5() 
{
     if (iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) > iCustom(NULL, 0, "SuperTrend", 1, 1, 1, 0) &&                             //check SuperTrend
         iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0) > iCustom(NULL, 0, "nonlagdot", 1, 1, 1, 1, 1, 1, 1, 1, 0)){  //confirm nonlagdot 
         return(true);
     }
     return(false);//returns false if the icustom indications fails
}//end bool TechnicalAnalysis2x5() 
One more thing, you need to Normalise your doubles(Stoploss & Takeprofit) in the OrderModify routine, or you also headed for more problems.

Hope it helps.
 

i guess that the nonlagdot should work with manual trading only that the NLD value shift returns same number with nol and 1 value shift

that is to avoid the work to quote incoming number with the value shift request

 
pipsfighter:

i guess that the nonlagdot should work with manual trading only that the NLD value shift returns same number with nol and 1 value shift

that is to avoid the work to quote incoming number with the value shift request


Do you expect a reply from the OP after 3 years ? please do not dredge up old threads/posts without a very good reason.

Thread started - 2010.03.22


Reason: