Simple beginner problem - How to close an open order with OrderClose() ???

 
i am writing a very basic expert so i can get used to writing code.

Basically i buy when a bar is higher than the previous high and close the position when the bar is lower than the previous low.

i can get the buy to work, but i cant close it and i keep getting this error : " invalid ticket for OrderClose function "

I dont understand what i am doing wrong.

Can someone please post some basic code on how you close an open position.

This is what i am using at the moment :

To Open:
 ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-highLowRange,0,"My order #2",16384,0,Green); 



and to Close (this is the problem) :

 OrderClose(ticket,OrderLots(),Bid,3,Orange); 
 
Is your ticket a static or global variable? Otherwise the ticket will be forgotten on the next tick (when the start function has been left and start is called again for a new tick).



Markus
 

Is your ticket a static or global variable? Otherwise the ticket will be forgotten on the next tick (when the start function has been left and start is called again for a new tick).



Markus


i didnt even think of that, yes it is being forgotten on the next tick...

Thankyou Markus
 
You're welcome.

Good luck with your trading!


Markus