How to get values from iCustom and use them in signal logic

 

Hey guys, 


First post here, but lurk alot.


Recently got into learning programming and mql4, so i apologise if this has been answered multiple times before...but i couldn't find anything that fit 


So i have a custom indicator that draws horizontal lines on my chart of x periods, and i'm trying to figure out how to get the values of the lines on my chart. 


I would share my code if i even knew where to start, but i've really come up against a brick wall and kinda looking for some basic hand holding for the initial part.


i've included a photo to help visualise it, basically how do i say in mql4 a cross above the red = buy and a cross below blue = sell? 

also included the indicator too

Files:
 
If it is drawing a HLine object, you don't use iCustom which reads buffers.
 

sorry probably should have been clearer, it does draw lines, but as little dots (probably easier to see in photo) 


after getting a little help i can now set to buy and sell at the right places using buffers...but now my problem is the indicator isn't updating the high/low, so it just buys and sells at the same price as the last high/low but doesn't recalculate the high low when price does break said lines.


i've been thinking maybe it would be better to calculate the high/lower period myself in the EA? However how can i "save" the price of a 20 period high for example instead of just returning the highest bar of the last 20 bars?

 
  1. Your code is repainting. Don't look at newer bars (relative to Count.) Don't.
              if(High[Count]>High[Count-j]) countup=countup+1

  2. No need for the decrement. Contradictory information on IndicatorCounted() - MQL4 programming forum
  3. You should stop using the old event handlers and IndicatorCounted() and start using the new ones.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference
              How to do your lookbacks correctly.
  4. If you use counting variables (like countup,) they must be static or global. You aren't remembering anything.
  5. If you use static/global variables, you must initialize them if IndicatorCounted is zero. You are using a variable value from the previous iteration, which means, as is, you can't process bar zero (the forming one,) more than once, ever.
    1. You can put it in a buffer so you can get the previous bar value.
    2. Only process bar zero once (or none.)
    3. Save and restore them when processing bar zero.
    4. Use an array (size 2) and use iNS=rates_total-1-iBar, iCur=iNS%2, iPre=!iCur; var[iCur]=function(var[iPre]);. No save/restore required.

  6. No need to do any of that. Just call iHighest and then get the price of that bar.