Take a buy on the movement of the last tick.(last_tick)

 

Hello engineers

I have a small problem that I would like your help :


Here is my problem: I want to buy on a small move on the last tick.

For example the last tick(last_tick[0].last) is moving down and it is currently priced at 100.18 once it goes up one step, either it comes back to 100.17 I take a buy position.

I believe that everything is possible in programming, here is my source code that I try to adapt but which really does not work
MqlTick last_tick[3];

   if(SymbolInfoTick(Symbol(),last_tick[0])) {

           double Last = last_tick[0].last;

     if (last_tick[0].last > last_tick[1].last)

       {   

       Comment("Waitting");   

       }

     else   

     if (last_tick[0].last < last_tick[1].last) 

     {    Comment("Tack a buy"); }   

     }

it doesn't produce what i want

Thank you in advance for your help.

 
You need to use CopyTicks instead of SymbolInfoTick
 
Dominik Christian Egert #:
You need to use CopyTicks instead of SymbolInfoTick

Thank you sir for your answer, i try it but i don't have access to the  last_tick[ 1 ].last

can you just help by  showing me a small code please?

thank you sir 

 
Noxtube: I want to buy on a small move on the last tick.

You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          MT4: New candle - MQL4 programming forum #3 (2014)
          MT5: Accessing variables - MQL4 programming forum #3 (2022)

I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum (2011)

 
Look up the function in the docs, Copy ticks.

Else, with your code, and assuming it is run on every tick in OnTick. You could add this to get your array filled over time.

static MqlTick last_tick[3];

last_tick[2] = last_tick[1];
last_tick[1] = last_tick[0];

... continue with your code as posted ...
 
Dominik Christian Egert #:
Look up the function in the docs, Copy ticks.

Else, with your code, and assuming it is run on every tick in OnTick. You could add this to get your array filled over time.

Thank you for your help, I tried it works fine but every time the tick moves up both variables change values.
therefore impossible to compare the 2 because last tick2 will never be greater than last tick1 because they move together
 
William Roeder #:

You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          MT4: New candle - MQL4 programming forum #3 (2014)
          MT5: Accessing variables - MQL4 programming forum #3 (2022)

I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum (2011)

Thanks for your help,

as it is impossible is there a way to program in 1 second to take the price at the close of each 1 second candle?

Thanks

 


in fact what I want is to place an automatic STOP LOSS in my Expert when I am in a position (Bearish or bullish) each time the ticks are in a reverse direction at 1000 ticks from the last tick (The lowest levels reached), he comes straight out of position, that's my goal.


Thanks in advance
 
Noxtube #: as it is impossible is there a way to program in 1 second to take the price at the close of each 1 second candle?

Use the timer.

 
William Roeder #:

Use the timer.

Thank you very much but I really don't know how to go about it and how can you give me some ideas?

Thank you sir for your time

Reason: