Download MetaTrader 5
To add comments, please log in or register
Do you have Linux? Find out how to install MetaTrader on it!
Jan 2016.04.05 12:53 

Hey Guys,

I have a new problem ...

I'm writing a scalping bot at the moment and if I want to use the S/L and T/P I must be at least 40 points + spread away from the market.
Is there a way to close a order, for example order 2 if the market is at x or y?
So I must check if(Ask < x || Bid > y). But what do I writing then?

And can I check if my last position is closed or opened? - Because I only want to have one open order and not 10. So I would implemnt a counter and if the last position is closed i would say "counter = counter -1". But how can I check if my last position is closed or still open?

My last question is variables.  At the begin of my Expert Advisor I say "extern int counter = 0". So if I buy or sell something I will say "counter = counter +1". But the problem is, the counter is then everytime 0. But why?
Is the counter reseted to 0 everytime if I get a new tick?


Greetings :) 

Carl Schreiber
Carl Schreiber 2016.04.05 14:05  

a) read about OrderClose(..)

b) OrderSend will return the ticket number (if no error).
1) Check whether this ticket number is still in the heap of OrdersTotal(..) then close it.
2) Close the order with this ticket number - without checking anything. If you get an error it could have been closed already.

c) Read about global variables and static variables.
if you start the EA check all open positions and set your counter accordingly.
extern in counter = .. is the wrong way!

To add comments, please log in or register