Chart Color
16 replies
JS17
6 years ago #201596
tomas262
6 years ago #201622
Hello,
do you mean MT chart background color? Right click on chart – select Properties and set the color
JS17
6 years ago #201630
tomas262
6 years ago #201632
Did you mean you need to change bckgnd color from within the EA?
JS17
6 years ago #201633
Karish
6 years ago #201638
//+——————————————————————+
//| The function receives chart background color. |
//+——————————————————————+
color ChartBackColorGet(const long chart_ID=0)
{
//— prepare the variable to receive the color
long result=clrNONE;
//— reset the error value
ResetLastError();
//— receive chart background color
if(!ChartGetInteger(chart_ID,CHART_COLOR_BACKGROUND,0,result))
{
//— display the error message in Experts journal
Print(__FUNCTION__+”, Error Code = “,GetLastError());
}
//— return the value of the chart property
return((color)result);
}
//+——————————————————————+
//| The function sets chart background color. |
//+——————————————————————+
bool ChartBackColorSet(const color clr,const long chart_ID=0)
{
//— reset the error value
ResetLastError();
//— set the chart background color
if(!ChartSetInteger(chart_ID,CHART_COLOR_BACKGROUND,clr))
{
//— display the error message in Experts journal
Print(__FUNCTION__+”, Error Code = “,GetLastError());
return(false);
}
//— successful execution
return(true);
}
JS17
6 years ago #201639
Karish
Thanks for the reply but I don’t do any coding at all and I was hoping that it could be done using the EA Wizard
Thankyou
Karish
6 years ago #201641
Why would you like to have EA Wiz to change your MT4’s chart background color for, i have trouble to understand
JS17
6 years ago #201646
Karish
I want the background color different if I am in a different trade, Hedge/Buy/Sell etc
Regards
John
tomas262
6 years ago #201648
Hello,
you can copy the Karish’s code into EA Wizard / code / CustomFunctions.mq4 (at the end) and save
In EA WIzard you can reference these using “Custom Action” like
CustomAction(ChartBackColorSet(white,0));
It should work
Karish
6 years ago #201678
Put this at the very end of: “EA Wizard / code / CustomFunctions.mq4″
bool ChartBackColorSet(const color clr,const long chart_ID=0)
{
//— reset the error value
ResetLastError();
//— set the chart background color
if(!ChartSetInteger(chart_ID,CHART_COLOR_BACKGROUND,clr))
{
//— display the error message in Experts journal
Print(__FUNCTION__+”, Error Code = “,GetLastError());
return(false);
}
//— successful execution
return(true);
}
Add this line of code after the OrderSend function ends:
if(OP_BUY){ChartBackColorSet(Green, 0);}
if(OP_SELL){ChartBackColorSet(Red, 0);}
Im sure you will understand, good luck.
JS17
6 years ago #201680
Karish
Thanks again for your help
But your faith in my abilities are not well placed – lol
I created a simple EA to test this and used CustomAction inside EA Wizard to change the background color to red if the EA closed all positions on equity target
When I complied it the editor showed 7 errror messages
I have attached the EA if you can help?
Regards
John
JS17
6 years ago #201682
This is the sqw file, just change the file extension back to .sqw and it should be OK
JS17
6 years ago #201684
that did not work, I give up with that lol
JS17
6 years ago #202118
Tomas
I don’t know were this post above should be ??????????????????, it must be an error
Have you looked at my background color file above yet ???
Regards
John
tomas262
6 years ago #202121
Hello,
you can simply do this. See file attached
You can use one of these codes https://docs.mql4.com/constants/objectconstants/webcolors