# orderclose not working. Can somebody Point to me whats wrong with my code. correct me.( this readable raptorUk)?

117

Experts plz make this orderclose work thank yu. any help suggestions are welcome

```
int a=1,b=2, c=1,d=2;   //VALUES ALWAYS TRUE IF NO ORDERS THEN OPEN 2 ORDERS

//**************
//OPEN A HEDGE**
//**************

{
}

{
}

if(c<d)
{
opensell=true;  //if open sell true
}

if(opensell==true)
{
tellsell=2; // initiate tell sell
}

// THE CLOSING ORDERS
//\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$\$

double currprice=iClose(NULL,PERIOD_D1,0);                   // gives the currentprice

{
}

if( tellsell==1 && currprice<tellbuy && currprice<tellsell)         //if the current is now less than the price of opensell.
{                                                              //then close sell
closesell=true;
}

//CLOSING ORDERS -->
//****************************************************************************************************************************************************************
//8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
//****************************************************************************************************************************************************************

//here is OrderClose functions.

while(true)
{
{
RefreshRates()
Cpos=OrderClose(ticket,lots,Bid,3,Yellow);

if(Cpos==true)
{
break;
}
if(Fun_Error(GetLastError())==1)
continue;
return;
}

if(Tip==1 && closesell==true)   // closing of sell
{
RefreshRates();

if(Cpos==true)
{
break;
}

if(Fun_Error(GetLastError())==1
continue;
return;
}
break;
}

//****************************************************************************************************************************************************************
//8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
//****************************************************************************************************************************************************************

```
Files:
greedy_1.mq4  9 kb
17400

Here is my attempt download the EA, check the source code thank you for yo help.

Remember if current price is above OrderOpenPrice (of both orders) close buy and Close sell when the price is below OrderOpen price (of both Orders)

17400

Experts plz make this orderclose work thank yu. any help suggestions are welcome

17400

It's better . . .

In this code, where does the value of ticket come from ? you seem to be using the same value of ticket to try and close a buy and a sell, if you have a Buy and a Sell they will each have unique ticket numbers . . .

```   while(true)
{
{
RefreshRates();
Cpos=OrderClose(ticket,lots,Bid,3,Yellow);

if(Cpos==true)
{
break;
}
if(Fun_Error(GetLastError())==1)
continue;
return;
}

if(Tip==1 && closesell==true)
{
RefreshRates();

if(Cpos==true)
{
break;
}
if(Fun_Error(GetLastError())==1)
continue;
return;
}
break;
}```

You should only check GetLastError() when you need to, so if Cpos = false then GetLastError() and report the error and any relevant variables that you will need to diagnose the issue.

117

RaptorUK:

It's better . . .

In this code, where does the value of ticket come from ? you seem to be using the same value of ticket to try and close a buy and a sell, if you have a Buy and a Sell they will each have unique ticket numbers . . .

You should only check GetLastError() when you need to, so if Cpos = false then GetLastError() and report the error and any relevant variables that you will need to diagnose the issue.

THANKS