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.
-
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.
-
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.
-
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)