Attachments forums

List of attachments posted on this forum.


All files on forums: 161075

Re: Coding Help

knaimad, Sun Oct 22, 2017 10:04 pm

knaimad wrote: Sun Oct 22, 2017 9:28 am Dear mladen

Please, be so kind as to review my copycat code:
I've made a function to change the color of the candles, but my gut is telling me that it can be made in simpler way...
anyway, show me the way...
thanks

Code: Select all

void SetCandleColor(int col, double& upw[], double& upc[], double& dnw[], double& dnc[], int i)
{
	double high,low,bodyHigh,bodyLow;


	{
		bodyHigh = MathMax(Open[i],Close[i]);
		bodyLow  = MathMin(Open[i],Close[i]);
		high          = High[i];
		low		  = Low[i];
	}

	upw[i] = low;	upc[i] = bodyLow;
	dnw[i] = low;	dnc[i] = bodyLow;
	

	switch(col)
	{
		case  1: 	upw[i] = high;	upc[i] = bodyHigh;	break;
		case -1: 	dnw[i] = high;	dnc[i] = bodyHigh;	break;
	
	}
}
or maybe the below is tad better?

Code: Select all

void SetCandleColor(double& _trend[], double& _upwick[], double& _dnwick[], double& _upbody[], double& _dnbody[], int i)
{
            if (_trend[i]== 1)
            {
               _upbody[i] = MathMax(Open[i],Close[i]);
               _dnbody[i] = MathMin(Open[i],Close[i]);
               _upwick[i] = High[i];
               _dnwick[i] = Low[i];
            };
            
            if (_trend[i]==-1)
            {
               _upbody[i] = MathMin(Open[i],Close[i]);
               _dnbody[i] = MathMax(Open[i],Close[i]);
               _dnwick[i] = High[i];
               _upwick[i] = Low[i];
            };
}
All files in topic