Download MetaTrader 5

Coding a looping function

To add comments, please log in or register
Brian
498
Brian  

Hello,

I'm trying to code a repeating (looping) function. I'm not looking for the entire program (EA), just the function that will do the following:

Buy at price A

Place stop at A-50

If stopped out buy again at A+50

Place new stop at A

If stopped out buy again at A+100

Place new stop at A-50

Keep repeating indefinitely.

As you can see, the stop is always a consistent distance behind the entry (in this case 50 pips)

Whenever we are stopped out a new order is placed a consistent distance above the price that was just stopped out. (in this case 100 pips)

Thanks in advance for the help.

Brian

Ian Flanagan
549
Ian Flanagan  
You can't do that within a single function (easily). The start function is called every time there is a new price.
Tjipke de Vries
6384
Tjipke de Vries  
4000:

Hello,

I'm trying to code a repeating (looping) function. I'm not looking for the entire program (EA), just the function that will do the following:

Buy at price A

Place stop at A-50

If stopped out buy again at A+50

Place new stop at A

If stopped out buy again at A+100

Place new stop at A-50

Keep repeating indefinitely.

As you can see, the stop is always a consistent distance behind the entry (in this case 50 pips)

Whenever we are stopped out a new order is placed a consistent distance above the price that was just stopped out. (in this case 100 pips)

Thanks in advance for the help.

Brian


keep trying

for help show your attempt

To add comments, please log in or register