Reply To: Backtest – Exit Criteria – Setup bar and Trigger price

Optuma Forums Optuma Scripting Backtest – Exit Criteria – Setup bar and Trigger price Reply To: Backtest – Exit Criteria – Setup bar and Trigger price

#51707
Trevor R
  • Topics: 107
  • Replies: 316
  • Posts: 423

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

 

Pin It on Pinterest