Download MetaTrader 5

Defining the colour in OrderClose()

To add comments, please log in or register
Sneck55
113
Sneck55  

Hello,

My EA has different types of order and with some of them, if I specify a colour in OrderSend() and OrderClose(), it creates a big mess on the chart with repeated trades opening and closing. Therefore for some orders I need a colour and for others I need nothing.  

My code is as follows:

string EntryExitColour; 

if(Type == 26)  EntryExitColour = "CLR_NONE"; else EntryExitColour = "clrAquamarine";

if(OrderClose(OrderTicket(),OrderLots(),MarketInfo(Symbol(),MODE_BID),Slippage,EntryExitColour))

{

..code etc

}

When I compile I am getting the message "implicit conversion from 'string' to 'number'".  Could somebody tell me how to use a variable to specify the colour to use, or none, or alternatively is there a table where all the colours have numbers and I can specify it as an integer?

Thanks. 

Fernando Carreiro
2947
Fernando Carreiro  
Sneck55: My EA has different types of order and with some of them, if I specify a colour in OrderSend() and OrderClose(), it creates a big mess on the chart with repeated trades opening and closing. Therefore for some orders I need a colour and for others I need nothing.  When I compile I am getting the message "implicit conversion from 'string' to 'number'".  Could somebody tell me how to use a variable to specify the colour to use, or none, or alternatively is there a table where all the colours have numbers and I can specify it as an integer?

Firstly, use the "SRC" button when adding source code and secondly, colours are "color" and not "string".

You can also use inline Ternary Operator instead of the "if" function for assigning values to a variable.

You should also use the Order Close Price instead of Bid or Ask, when closing an Order, irrespective of it being a buy or a sell order.
color EntryExitColour;

EntryExitColour = (Type == 26) ? clrNone : clrAquamarine;

if( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, EntryExitColour ) )
{
   //..code etc
}
As for the list of colours, they are available in the documentation as the standard Web Colors.
Ternary Operator ?: - Operators - Language Basics - MQL4 Reference
Ternary Operator ?: - Operators - Language Basics - MQL4 Reference
  • docs.mql4.com
Ternary Operator ?: - Operators - Language Basics - MQL4 Reference
Sneck55
113
Sneck55  
Fernando Carreiro:

Firstly, use the "SRC" button when adding source code and secondly, colours are "color" and not "string".

You can also use inline Ternary Operator instead of the "if" function for assigning values to a variable.

You should also use the Order Close Price instead of Bid or Ask, when closing an Order, irrespective of it being a buy or a sell order.
color EntryExitColour;

EntryExitColour = (Type == 26) ? clrNone : clrAquamarine;

if( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), Slippage, EntryExitColour ) )
{
   //..code etc
}
As for the list of colours, they are available in the documentation as the standard Web Colors.
Thank you Fernando
Sneck55
113
Sneck55  
Sneck55:
Thank you Fernando
Could you please tell me where the SRC button is as I can't find it in the menus or toolbar customiser and it doesn't appear to have been included with Help.
whroeder1
16058
whroeder1  
Are you blind?
It's not in "menus or toolbars," therefor is won't be in the help.
We're talking about this forum.
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it
Sneck55
113
Sneck55  
whroeder1:
Are you blind?
It's not in "menus or toolbars," therefor is won't be in the help.
We're talking about this forum.
Please edit your post.
For large amounts of code, attach it
Kindly don't be rude whroeder1. Therefore has an e on the end. I asked a simple question and the previous comment did not make that clear
To add comments, please log in or register