Stop notices in backtest report with no stop mode activated

Hi!

I should appreciate it if someone would help me with the following issue. I cannot figure out by myself.

When backtesting this sample system, I get Profit / Trail / Max Loss notices in the report, even when neither the formula contains any stop indication nor the backtester settings window has any stop activated.

// --- Strategy 1 ---
S1_Buy  = Day() == 1;
S1_Sell = 1;

// --- Strategy 2 ---
S2_Buy  = Day() == 5;
S2_Sell = 1;

// --- Strategy 3 ---
S3_Buy  = Day() == 10;
S3_Sell = 1;

// --- Strategy 4 ---
S4_Buy  = Day() == 15;
S4_Sell = 1;

// --- Backtester ---
Strategy = 0;
Buy = 0;
Sell = 0;

for(i = 0; i < BarCount; i++)
{
	switch(Strategy)
	{
	case 0:
		if(S1_Buy[i]) 
			Strategy = Buy[i] = 1;
		else if(S2_Buy[i])
			Strategy = Buy[i] = 2;
		else if(S3_Buy[i])
		    Strategy = Buy[i] = 3;
		else if(S4_Buy[i])
			Strategy = Buy[i] = 4;
		break;
		
	case 1:
		if(S1_Sell[i]) 
		{
			Sell[i] = Strategy;
			Strategy = 0; 
		}
		break;

	case 2:
		if(S2_Sell[i]) 
		{
			Sell[i] = Strategy;
			Strategy = 0; 
		}
		break;
		
	case 3:
		if(S3_Sell[i]) 
		{
			Sell[i] = Strategy;
			Strategy = 0; 
		}
		break;
			
	case 4:
		if(S4_Sell[i]) 
		{
			Sell[i] = Strategy;
			Strategy = 0; 
		}
		break;
	}
}

BuyPrice    = Open;
SellPrice   = Close; 

Would you know why that is happening?

Thank you for your help.

Regards.

You are putting values other than 1 in your Sell signal array, which causes AmiBroker to identify those exits as stops or profit targets. For a list of the exit types/reasons, see the ExitTrade function here: Porfolio Backtester Interface Reference .

long ExitTrade ( long Bar, string Symbol, float Price, [optional] variant ExitType )

Low-level method that exits trade on any symbol. This method searches open trade list and if there is no open trade on given symbol it does nothing. Optional ExitType parameter specifies the reason for exit (1 - regular exit, 2 - max. loss, 3 - profit, 4 - trail, 5 - N-bar, 6 - ruin)

1 Like

Also read carefully

1 Like

mradtke, awilson,

Thank you for your fast answers.

I have debugged the formula and learnt how to identify in the report what system generates the trade.

:slight_smile:

// --- Strategy 1 ---
S1_Buy  = Day() == 1;
S1_Sell = 1;

// --- Strategy 2 ---
S2_Buy  = Day() == 5;
S2_Sell = 1*20;

// --- Strategy 3 ---
S3_Buy  = Day() == 10;
S3_Sell = 1;

// --- Strategy 4 ---
S4_Buy  = Day() == 15;
S4_Sell = 1;

// --- Backtester ---
Strategy = 0;
Buy = 0;
Sell = 0;

for(i = 0; i < BarCount; i++)
{
  switch(Strategy)
  {
  case 0:
  	if(S1_Buy[i]) 
  		Strategy = Buy[i] = 1;
  	else if(S2_Buy[i])
  		Strategy = Buy[i] = 2;
  	else if(S3_Buy[i])
  	    Strategy = Buy[i] = 3;
  	else if(S4_Buy[i])
  		Strategy = Buy[i] = 4;
  	break;
  	
  case 1:
  	if(S1_Sell[i]) 
  	{
  		Sell[i] = 10;
  		Strategy = 0; 
  	}
  	break;

  case 2:
  	if(S2_Sell[i]) 
  	{
  		Sell[i] = 20;
  		Strategy = 0; 
  	}
  	break;
  	
  case 3:
  	if(S3_Sell[i]) 
  	{
  		Sell[i] = 30;
  		Strategy = 0; 
  	}
  	break;
  		
  case 4:
  	if(S4_Sell[i]) 
  	{
  		Sell[i] = 40;
  		Strategy = 0; 
  	}
  	break;
  }
}

BuyPrice    = Open;
SellPrice   = Close; 

1 Like

Nothing new under the sun.
It is all described in the Knowledge Base:

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