Assistance with Implementing Three-Level Scale-Out Strategy

Hi there,

I have reviewed several videos and scripts related to scale-out strategies; however, I am struggling to apply the concept to my own strategy.

In my custom script, I aim to implement a scale-out in three levels:

  1. The first level based on a specific percentage.
  2. The second level based on another percentage.
  3. The third level based on a custom criterion:
  • sell = MA < Close

My question is: How can I implement the scale-out for the third level, which is based on this custom criterion?

Thank you for your support and guidance.

Best regards,
Ahmad



Master_Close_Type  = ParamList( "Master Close Type", "Last|Vwap", 0 ); 
Master_Slopes_Type = ParamList( "Master Slopes Type", "UP Confirmation|Down Confirmation", 0 ); 
MAs          = ParamList ( "MA Method", "Simple|Exponential|Weighted|Hull" , 0);
MAfps        = ParamList ( "MA FPs", "Open|High|Low|Close" , 0);
MAperiod     = Param     ( "MA Period", 12, 2, 1000 );
MAwidth      = Param     ( "MA width", 1, 2, 1000 );
MAStyle      = ParamStyle( "MAs Style" , styleNoDraw|styleNoRescale, maskAll );
MAsupclr 	 = ParamColor( "MAs UpColor"  , colorGreen);
MAsdwnclr    = ParamColor( "MAs DownColor", colorRed  );

//firstlevel       = Param     ( "first scale out level"  , 50, 1, 1000 ); 
//secondlevel      = Param     ( "second scale out level" , 30, 1, 1000 );
//--------------------------------------------------
// get field prices value 
MAPrice = 0.0;

switch( MAfps )
{
	case "Open":
		MAPrice = O;
		break;

	case "High":
		MAPrice = H;
		break;

	case "Low":
		MAPrice =L;
		break;

	case "Close":
		MAPrice = IIf( Master_Close_Type == "Last" , C, OpenInt);
		break;


}
//--------------------------------------------------
// get movin averages value
MAsval = 0;
switch( MAs )
{
	case "Simple":
		MAsval = MA( MAPrice, MAperiod );
		break;

	case "Exponential":
		MAsval = EMA( MAPrice, MAperiod );
		break;

	case "Weighted":
		MAsval = WMA( MAPrice, MAperiod );
		break;
		
	case "Hull":
		MAsval = HMA( MAPrice, MAperiod );
		break;
}
//--------------------------------------------------
// handle slope up and down cases
MAsclr = colorAqua;
switch( Master_Slopes_Type )
{
	case "UP Confirmation":
		MAsclr = IIf( MAsval > Ref(MAsval,-1) , MAsupclr , MAsdwnclr);
		break;

	case "Down Confirmation":
		MAsclr = IIf( MAsval < Ref(MAsval,-1) , MAsdwnclr , MAsupclr);;
		break;

}

// visualize my moving average on chart
Plot( MAsval, "MAs" + "(" + MAperiod + ")" , MAsclr ,  MAStyle, Null, Null, 0, 0, width =  MAwidth);
//--------------------------------------------------
//--------------------------------------------------
// Signals criterion
Buy  = MAsval >= Close;
Sell = MAsval <  Close;


// first level of scale out precentage from long 
firstlevel   = 50 ; 
SetPositionSize( firstlevel, spsPercentOfPosition ); // for scale-out use 50% of current position size

// second level of scale out precentage from long 
secondlevel  = 30 ; 
SetPositionSize( secondlevel, IIf( Buy == sigScaleOut, spsPercentOfPosition, spsNoChange ) ); // for scale-out use 30% of current position size




// third level of scale out based on custom criteria ?????

SetPositionSize( ??); // for scale-out use custom criteria of sell ....   ( Sell = MAsval <  Close )
//--------------------------------------------------
//--------------------------------------------------


Filter = 1;









Hi
Did you try to read this Portfolio-level back testing ?
in you case you need to read the read the Example 4: partial exit (scaling out) on profit target stops

1 Like

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