Defining the colour in OrderClose()

 

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. 

 
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
 
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:
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.
 
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
 
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