Adjusting Positionsizes while always remaining in the market

Hello friends, I'm having difficulty coming up with the code that will allow me to adjust position sizes while remaining in the market all the time. What I'm trying to do is just follow a standard say typical 80% equity 20% fixed income portfolio while my rules say to be risk-on, and then switch to a more conservative portfolio, say 20% equity 80% fixed income when my rules turn to risk-off. So I'm really just wanting to adjust the position sizes according to the model, rather than buying and selling whole positions. I've been successful getting the risk on side of the trade to work with the case statement (provided by one of the contributors here I'm sure). However, I'm having difficulty getting it to adjust the position sizes on a move to risk-off which I had been calling 'closingtrade' (a misnomer now).
this is what I have so far:

/*openingtrade=some risk-on condition*/
/*closingtrade=/*some risk-off condition*/



if (openingtrade==1)
	case "VFIAX": ps=38.6;	break;
	case "VEXAX": ps=8.4;	break;
	case "VTMGX": ps=23.5;	break;
	case "VEIEX": ps=7.9;	break;
	case "VBIRX": ps=6.1;	break;
	case "VBILX": ps=3.7;	break;
	case "VBLLX": ps=4.1;	break;
	case "OMBAX": ps=3.8;	break;
	case "VTABX": ps=0;	break;


	case "VFIAX": ps=10;	break;
	case "VEXAX": ps=10;	break;
	case "VTMGX": ps=10;	break;
	case "VEIEX": ps=10;	break;
	case "VBIRX": ps=10;	break;
	case "VBILX": ps=10;	break;
	case "VBLLX": ps=10;	break;
	case "OMBAX": ps=10;	break;
	case "VTABX": ps=10;	break;


Thank you for any help or guidance! The error I'm getting is Error 6: Condition in if,while, for statements has to be numeric or boolean...

Like the error says... because you are using an array in conditional statement.
variable openingtrade has multiple values (0/1). So if(openingtrade==1) is not possible.

1 Like

There exists thread already explaining if-else vs. IIf:

As for your multi symbol conditional position size issue thread exists too.

In addition you might use scale in/out.

1 Like

Ah yes, your solution in the second link will work perfectly. Thank you very much for pointing me in the right direction my friend.
Tony R

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.