Get indicator values by tick NOT per bar history

 

Hi all,


Im trying to code a crossover and crossunder EA, problem is when using the copybuffer function to get current and last values of an indicator ( for argument sake, an MA ) it return the values the MA's was at at the close of each bar, this is NOT want I want.

I want to execute a trade immediately on the tick where the crossover of MA's happen, is there anything in MQL5 I can use to do so please?


all help appreciated.

 
Devan Gert De Kock: it return the values the MA's was at at the close of each bar, this is NOT want I want.

It does not — it returns what you ask for. Ask for the current bar and the previous one.

Always post all relevant code (using SRC).
     How To Ask Questions The Smart Way. 2004
          Be precise and informative about your problem

We can't see your broken code.

Fix your broken code.

 

You can do so by running the application realtime, so in OnTick().

Call for the MA of the last bar will return the newest or latest value available.

This value simply gets recalculated or updated on every new tick until a new bar starts and then the last value will become the previous bar's close value.

Devan Gert De Kock:

I want to execute a trade immediately on the tick where the crossover of MA's happen, is there anything in MQL5 I can use to do so please?

The question is a bit contradictory because what you ask is already what it does when you call for the latest value on every new tick.

You only have to check the crossover state upon every tick and open a new order when it changes state.

 
Marco vd Heijden:

You can do so by running the application realtime, so in OnTick().

Call for the MA of the last bar will return the newest or latest value available.

This value simply gets recalculated or updated on every new tick until a new bar starts and then the last value will become the previous bar's close value.

The question is a bit contradictory because what you ask is already what it does when you call for the latest value on every new tick.

You only have to check the crossover state upon every tick and open a new order when it changes state.

Hi Marco, thanks for your reply,

in my code I get the RSI ( for this example ) values via copybuffer see code below please :

      int RSIDef = iRSI(Symbol(), Period(),RSIPeriod, PRICE_CLOSE);
      ArraySetAsSeries(RSIArray, true);
      CopyBuffer(RSIDef,0,0,2,RSIArray);

so the values returned to me is RSIArray[0] == current Value and RSIArray[1]  == is the previous ( Candle Close RSI value ) so what I am getting is 1 value per candle, what I want or need is the current RSI value and the Previous TICK's RSI value, otherwise there might be some time before the new candle forms and then only registered as a crossover/under.

If I'm understanding the copybuffer function correctly ( last RSI value on closed candle ) + current RSI value,  or please tell me if I'm not making sense.

thanks

 

Okay so you store the previous value in a variable for example old_value and then when a new tick comes in you can compare that new_value to the one tick old_value.

After that, you overwrite the old_value with the new_value and wait for the next tick and compare it again until it changes state so that you can open the order on that tick.

 
Marco vd Heijden:

Okay so you store the previous value in a variable for example old_value and then when a new tick comes in you can compare that new_value to the one tick old_value.

After that, you overwrite the old_value with the new_value and wait for the next tick and compare it again until it changes state so that you can open the order on that tick.

perfect thank you Marco, I was thinking the same thing, was just hoping that I could use standard code / built-in function, but a few lines of code and sorted. thank you again.

 
Devan Gert De Kock:
  1. You wasted everyones time, because you couldn't understand the reply.
  2. You code was broken. You do NOT need past values by tick to test for a MA cross. Only the current tick values and the previous bar values.
  3. I don't help rude, arrogant, or ignorant persons. You appear to be all three.
  4. Added to my do not help list. Live in ignorance.
 
William Roeder:
  1. You wasted everyones time, because you couldn't understand the reply.
  2. You code was broken. You do NOT need past values by tick to test for a MA cross. Only the current tick values and the previous bar values.
  3. I don't help rude, arrogant, or ignorant persons. You appear to be all three.
  4. Added to my do not help list. Live in ignorance.

" Added to my do not help list." much appreciated and the only thing you've said so far that's helpful.

Reason: