Backtest - Exit Criteria - Setup bar and Trigger price

Hi,

Can you please help with the following requirement in exit criteria in back tester:

 

Setup bar: Close below a Moving Average:

Trigger/Exit Price: Price crosses below the low of setup bar

In attach the exit setup

Thanks

 

Joao Rei

 

 

 

 

Hi Joao,

A simple script like the following (based on a 50 Bar Exponential Moving Average using the Close) will meet your basic criteria:

EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

Setup = CLOSE(0) < EMA50;

Setup

Using SHOWBAR, this will produce the following result:

20190316 Joao's Script 1

 

That highlights every Close below the EMA, which may not be quite what you want. A further criteria may be that the previous Close must be above the EMA. The following scripts adds that refinement and results in the chart below.

EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

Setup = If(CLOSE(1) > EMA50 AND CLOSE(0) < EMA50,1,0);

Setup

20190316 Joao's Script 2

I hope this helps you find the results you are looking for.

Cheers

Trevor

The Auld Tyma at

Auld Tyma Data Logo with URL 1 cm

 

Thank you Trevor,

The second code is near of what I need.

However, to trigger the setup, I need also the Low of close(0) bar and the Low of close(1) bar to be surpassed on the downside.

Any ideas?

 

Thanks.

 

Hi Joao,

I'm not 100% sure I got your extra criteria straight, so here are two options:

Option 1 (Script: //Ticket #51943 20190324) which requires the Entry Bar to meet:

  • Close of Entry bar and the Close preceding bar to be below to 50 EMA
  • Low of the Entry Bar to be below the Low of the preceding two Bars, regardless of the relationship of the Lows of those two preceding Bars

This script meets those criteria:

// Ticket #51943 20190324

EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

Sig1 = If(CLOSE(1) > EMA50 AND CLOSE(0) < EMA50, 1, 0);

Sig2 = If( LOW(0) < LOW(1) and LOW(0) < Low (2), 1, 0);

Entry = If(Sig1 and Sig2, 1, 0);

Entry

The SHOWBAR result from this script is shown in Red on the chart below.

Option 2 (Script: //Ticket #51943 20190324-A) which requires the Entry Bar to meet:

  • Close of Entry bar and the Close preceding bar to be below to 50 EMA
  • Low of the Entry Bar to be below the Low of the preceding Bar and the Low of the preceding Bar to be below the Low of the Bar preceding it

This script meets those criteria:

// Ticket #51943 20190324-A

EMA50 = MA(BARS=50, STYLE=Exponential, CALC=Close);

Sig1 = If(CLOSE(1) > EMA50 AND CLOSE(0) < EMA50, 1, 0);

Sig2 = If( LOW(0) < LOW(1) and LOW(1) < Low (2), 1, 0);

Entry = If(Sig1 and Sig2, 1, 0);

Entry

The SHOWBAR result from this script is shown in Blue on the chart below.

20190324 Joao's Script 3

Cheers

Trevor

The Auld Tyma at

Auld Tyma Data Logo with URL 1 cm

Hi Trevor,

Thank you very much for your help.

These 2 options follow the requirements.

Best Regards

Joao

 

 

 

Hi

I'm looking for something similar to this in the backtester.

I am able to create a script that gives me a setup bar. Instead of entering on the next open, or the close of the signal day, I would prefer to enter as soon as the next bar breaks the high of the setup bar (for long entry). And if that next bar fails to break the high, I would like to delete the pending trade.

Is it possible to simulate this through the backtester?

Thanks
Steve

 

Hi Steve,

Please post you code so we can see exactly what you are trying to achieve and so provide contextual assistance.

Cheers

Trevor