Financial Shock

Hi,

I want to create a script that triggers a sell signal as soon as the closing price is at least 5% below the moving average even if the moving average is still moving upwards (IsUp). The 5% downward movement does not have to happen in one day, but within 5 trading days or one week.

The same concept is used for a buy signal. A buy signal is given when the closing price is at least 5% above the moving average even if the moving average is still moving downwards (IsDown). The 5% upward movement does not have to happen in one day, but within 5 trading days or one week.

The first part of the script is easy:

Line1 = CLOSE() ;
Line2 = MA(Line1, BARS=50, STYLE=Simple, CALC=Close) ;
Line3 = Line2 IsUp ;
Line3

However, I have great difficulty programming the sell signal if the moving average is still moving upwards but a rapid price decline of at least 5% has occurred.

I tried many settings, but none of them worked.

Any suggestion is appreciated.

Thanks,
Thomas

1 Like

Hi Thomas,

Does this work?

V1 = MA(BARS=50, CALC=Close);
//Cross below MA within 5 days;
Sig1 = TIMESINCESIGNAL(CLOSE() crossesBelow V1)<=5;
//Up Slope MA;
Sig2 = V1 IsUp;
//More than 5% below MA;
Sig3 = DIFFPCT(CLOSE(),V1)<-5;
//All Signals;
Sig1 and Sig2 and Sig3

As per MTCH yesterday:

1 Like

Hello Darren,

Thank you very much for your efforts.

Your script example was very informative for me to make the necessary adjustments to my final script code.

Often, it’s just little ideas you get from somewhere to make another thing really good.

Many thanks for that!
Thomas

Hi,

It seems I need further help to get what I am looking for.

I have put together the following script for a sell signal:

// Getting the S&P 500 Data
D1 = GETDATA(CODE=SPX:WI, TIMEFRAME=1 Week) ;

// Defining the Sell Signal Trend Change Condition
SSTC1 = EHLERMA(D1, PERIOD=30) ;
SSTC2 = CLOSE(SSTC1) ;
SSTC3 = CLOSE(SSTC1)[3] ;
SSTC4 = DIFFPCT(SSTC2, SSTC3) ;
SSTC5 = SSTC4 >= 0 ;

// Defining the Sell Signal Price Change Condition
SSPC1 = DIFFPCT(CLOSE(D1), SSTC1) ;
SSPC2 = SSPC1 <= 0 ;

// Defining the Sell Signal Condition
Sig1 = SIGNALAFTER(SSTC5, SSPC2) ;
Sig1

The script works as it should. But the following code lines are not necessary:

// Defining the Sell Signal Price Change Condition
SSPC1 = DIFFPCT(CLOSE(D1), SSTC1) ;
SSPC2 = SSPC1 <= 0 ;

But the function SIGNALAFTER() requires two conditions, hence the code lines “SSPC1” and “SSPC2”. If there is a solution without the two lines of code, please give me a hint.

NOW THE REAL PROBLEM

I want to add a condition when there is a big price change that occurs before the above script gives a sell signal.

Here is the script for the extreme price change condition:

// Getting the S&P 500 Data
D1 = GETDATA(CODE=SPX:WI, TIMEFRAME=1 Week) ;

// Defining the Sell Signal Trend Change Condition
SSTC = EHLERMA(D1, PERIOD=30) ;

// Defining the Sell Signal Extreme Price Change Condition
SSEPC1 = DIFFPCT(CLOSE(D1), SSTC) ;
SSEPC2 = SSEPC1 <= -5 ;
SSEPC2

The extreme price change condition means that the %-difference between the close and the EHLERMA() is -5% or more. The script is correct no problem.

Now my question:

How can I put together the above sell signal script with the extreme price change condition script?

The sell signal script:

// Getting the S&P 500 Data
D1 = GETDATA(CODE=SPX:WI, TIMEFRAME=1 Week) ;

// Defining the Sell Signal Trend Change Condition
SSTC1 = EHLERMA(D1, PERIOD=30) ;
SSTC2 = CLOSE(SSTC1) ;
SSTC3 = CLOSE(SSTC1)[3] ;
SSTC4 = DIFFPCT(SSTC2, SSTC3) ;
SSTC5 = SSTC4 >= 0 ;

// Defining the Sell Signal Price Change Condition
SSPC1 = DIFFPCT(CLOSE(D1), SSTC1) ;
SSPC2 = SSPC1 <= 0 ;

// Defining the Sell Signal Condition
Sig1 = SIGNALAFTER(SSTC5, SSPC2) ;
Sig1

The extreme price change condition script:

// Getting the S&P 500 Data
D1 = GETDATA(CODE=SPX:WI, TIMEFRAME=1 Week) ;

// Defining the Sell Signal Trend Change Condition
SSTC = EHLERMA(D1, PERIOD=30) ;

// Defining the Sell Signal Extreme Price Change Condition
SSEPC1 = DIFFPCT(CLOSE(D1), SSTC) ;
SSEPC2 = SSEPC1 <= -5 ;
SSEPC2

The rule to merge the two scripts should be as follows:
The signal that is given first should be used to generate the sell signal.

  1. If the sell signal script is the first to give a sell signal, this sell signal is used and the extreme price change condition script is ignored.

  2. If the extreme price change condition script is the first to give a sell signal, this sell signal is used and the sell signal script is ignored.

  3. If the extreme price change condition script is the first to give a sell signal, only the first signal is used, and any further signals are ignored until the condition for the sell signal script is no longer met.
    The condition for the sell signal script is no longer met when:
    SSTC5 = SSTC4 == 0 ;

The problem for me is the combination of the two scripts, both scripts work.
I have attached the workbook for a better understanding of the issue.

Any help is appreciated.

Many thanks,
Thomas
TEST Sell Signal.owb (25.5 KB)

Hi,

Is there anyone out there who has any suggestions?

Many thanks,
Thomas