Profit Re-Invest

Posted By: MatPed

Profit Re-Invest - 02/20/18 18:28

Hi,
the following script allow to control the profit reinvestment during trading using the built in sliders.
It works but has the limit that the margin is not reset at the initial margin when Oversampling is set.
I can not understand if is a bug or some mistakes in coding. Any help is welcome

By the way, the Capital value is not set by purpose at this stage of development.

Ciao

Code:
function theSlider(){
	var intialMargin;
	
	if(is(INITRUN)){
		myMargin			= slider(1, 500, 0, 5000,"Margin","Trading Margin");
		myCapital		= slider(2, 0, 0, 10000,"Init-Capital","Required Capital");
		intialMargin	= slider(3, 0, 0, 1000, "Init-Margin","Initial margin for the Required Capital");
	}	
	if(Train) {return; }
	
	myMargin  		= slider(1);
	myCapital 		= slider(2);
	intialMargin 	= slider(3);
	
	var myWin = WinTotal-LossTotal;
	if (myCapital > 0 && intialMargin > 0 && myWin > 0 && !Train) {
		
		var reinvest	= sqrt(1 + myWin/myCapital);		
		var newMargin 	= intialMargin * reinvest;
		
		newMargin = max(myMargin, newMargin);
		
		slider(1, newMargin);
		myMargin = slider(1);

		Margin 	= myMargin;
		
//		print(TO_ANY, "n Margin: %.2f  - myMargin: %.2f", Margin, myMargin);	
	}
}

Posted By: OptimusPrime

Re: Profit Re-Invest - 12/27/18 16:26

Thank you Matped
Posted By: OptimusPrime

Re: Profit Re-Invest - 12/27/18 18:47

Thank you Matped
© 2024 lite-C Forums