Problem with OrderSend - invalid symbol - page 2

 
HerbertH:
No, the original OrderProfit() does work.

There is however another small glitch which is causing the Profit not to work:

You have double defined the Ticket variables: once global and the 2nd time in the Buy() function

Just remove the "int" in the Buy function and Profit will work.

(Otherwise the ticketnumbers will remain local and not be known globally to be used for the other functions)

Put: Comment("Current profit: ", pl); in the TotalProfit() and you will see it updated in the upperleftcorner of your screen.

Just one other question:

How do you determine the right Lots for these 4 different currencypairs?

Is this a one time correlation or does it need to be changed overtime?

Cheers

Herbert

About the global scope of the ticket variables and the use of Profit(), you are totally right !!

 

For the close function to work properly, you will have to remove the "int" declaration in the buy function. By declaring locally in "buy", these variables are not available to other functions. You have already declared them for the program above, and that is correct.

Keep us informed how it does.

 

To close ALL orders after a profit target is reached do something like this:

extern int profittarget=100; //closes after total profit of all orders is > $100

if (AccountProfit()>profittarget)

{

while(OrdersTotal()>0)

{

OrderSelect(0,SELECT_BY_POS);

if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);

if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);

if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());

}

return(0);

}

AccountProfit() returns total profit or loss of ALL currently opened orders.

Hope this may help.

 

Accountprofit

wolfe:
To close ALL orders after a profit target is reached do something like this:

extern int profittarget=100; //closes after total profit of all orders is > $100

if (AccountProfit()>profittarget)

{

while(OrdersTotal()>0)

{

OrderSelect(0,SELECT_BY_POS);

if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);

if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);

if(OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP||OrderType()==OP_BUYLIMIT||OrderType()==OP_SELLLIMIT) OrderDelete(OrderTicket());

}

return(0);

}

AccountProfit() returns total profit or loss of ALL currently opened orders.

Hope this may help.

Wolfe, the disadvantage of using Accountprofit() is that it will also show the profit (or loss) of all other possible running Experts, not just the profit of the 4 orders from this expert.

This is not what you want this EA to calculate in order to close these 4 orders.

 
HerbertH:
Wolfe, the disadvantage of using Accountprofit() is that it will also show the profit (or loss) of all other possible running Experts, not just the profit of the 4 orders from this expert. This is not what you want this EA to calculate in order to close these 4 orders.

Good point, I didn't take into account for multiple EA's running at the same time.

If each EA had a different magic number attached to it when loading to the chart, you could call for the total profit of that specific magic number for your four pairs and close only all orders with that specific magic number when your profit target has been reached.

Reason: