Indicator -> Automated Trade - Keeps firing - page 2

 
Seng Joo Thio:

Look at my earlier post - check return values, verify if they are EMTPY_VALUE. Also, follow what they said and use 0 IF the arrows appear at bar 0.

Ok, i'll work out how to do that later tonight. Need to take kids to practice now.

 
OK, I had a typo in the indicator name, will see how this goes now /facepalm
 

Thanks very much for your help guys. Ended up being a stupid mistake on my part and not having the spelling right. I can now see why it was failing, it's not returning an empty_value when not correct, rather a 1 (true) when it is valid. So my test (below) was incorrect in any case.


I'll correct this if statement later tonight. Can I convert to a boolean like in python or is it old school test like (var == 1.0)?

   double ArrowUP=iCustom(Symbol(), 0, indicator1, 0, 1);  
   double ArrowDN=iCustom(Symbol(), 0, indicator1, 1, 1);  
   
   double HistoUP=iCustom(Symbol(), 0, indicator2, 0, 1);  
   double HistoDN=iCustom(Symbol(), 0, indicator2, 1, 1);  
   
   Comment("ArrowUp: ", ArrowUP, "\nArrowDn: ", ArrowDN, "\nHistoUp: ", HistoUP, "\nHistoDn: ", HistoDN);
   
   // Incorrect test below
   if ((ArrowDN != EMPTY_VALUE ) && (HistoDN != EMPTY_VALUE ) && (CheckMoneyForTrade(Symbol(), lots, 1))) 
   {
      Comment("Sell - ", TimeToStr(TimeCurrent(),TIME_SECONDS));
   }
   
   if ((ArrowUP != EMPTY_VALUE ) && (HistoUP != EMPTY_VALUE ) && (CheckMoneyForTrade(Symbol(), lots, 0))) 
   {
      Comment("Buy - ", TimeToStr(TimeCurrent(),TIME_SECONDS));
   }
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Other Constants
  • www.mql5.com
The CLR_NONE constant is used to outline the absence of color, it means that the graphical object or graphical series of an indicator will not be plotted. This constant was not included into the Web-color constants list, but it can be applied everywhere where the color arguments are required. The EMPTY_VALUE constant usually corresponds...
 
NOENEEL NAVEEN SHARMA:

Thanks very much for your help guys. Ended up being a stupid mistake on my part and not having the spelling right. I can now see why it was failing, it's not returning an empty_value when not correct, rather a 1 (true) when it is valid. So my test (below) was incorrect in any case.

I'll correct this if statement later tonight. Can I convert to a boolean like in python or is it old school test like (var == 1.0)?

2147483647 is EMPTY_VALUE, so your comparison is valid. Check your bar index (i.e. last parameter of iCustom()) instead.

bool(EMTPY_VALUE) and bool(1) will give you true...

Other constants - Named Constants - Constants, Enumerations and Structures - MQL4 Reference
Other constants - Named Constants - Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
Used with array functions. Indicates that all array elements will be processed. Means the number of items remaining until the end of the array, i.e., the entire array will be processed The NULL constant can be assigned to a variable of any simple type or to an object structure or class pointer. The NULL assignment for a string variable means...
 
Aaaah then all good. Now onto the actual ordering code. Thanks again.
 
Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
          General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.
 
William Roeder:
Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
          General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon.

Aaah apologies, still trying to get used to this forum layout. I'm used to VB4.x sites.

I've got orderopen code in now but getting this error: Trade Disabled so will look at that today. It's not disabled as i have another EA on a different chart that is doing orders fine and autotrade is enabled.

Also, when using iCustom to pull buffer data from an indicator, is that indicator no longer required to be attached to the chart? For example, can i simply use the EA without the indicator now on chart?

 
NOENEEL NAVEEN SHARMA: , when using iCustom to pull buffer data from an indicator, is that indicator no longer required to be attached to the chart? For example, can i simply use the EA without the indicator now on chart?
  1. The indicator is on the chart, just invisible as EAs have no eyes.
  2. Unless the indicator has been made a resource of the EA, it needs to be installed.
  3. You can just embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.
              Use the publicly released code - Expert Advisors and Automated Trading - MQL5 programming forum
              Resources - MQL4 programs - MQL4 Reference

    Be aware that using resources is 40x times slower than using CIs directly.
              A custom indicator as a resource - MQL4 programming forum 2019.11.26

 
William Roeder:
  1. The indicator is on the chart, just invisible as EAs have no eyes.
  2. Unless the indicator has been made a resource of the EA, it needs to be installed.
  3. You can just embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.
              Use the publicly released code - Expert Advisors and Automated Trading - MQL5 programming forum
              Resources - MQL4 programs - MQL4 Reference

    Be aware that using resources is 40x times slower than using CIs directly.
              A custom indicator as a resource - MQL4 programming forum 2019.11.26

Ok, so when you say that the indicator is on the chart, does this hold true even if I do not manually add it to the chart? Is the EA when loading what loads the indicator? Sorry for asking the obvious, just wondering whether what I am doing atm is redundant - 

1. Add indicator

2. Add EA (which uses iCustom and the indicator)


Or is it a case of, I only need to add the EA as by adding the EA, it will also add the indicator to the chart.

Reason: