Set up a combine alert on RSI/DMI/STO


0
0

Hello,

I want to set up an alert trigger for when the combine signals of these 3 indicators are in agreement for. I just cant seem to get the code just right to trigger the signals just right, please see blow:

def rsi1 = if reference RSI(length = 14).”RSI” >= 50 then 10 else 9;

def rsi2 = if reference RSI(length = 14).”RSI” < 50 then 10 else 9;

def rsiDescending = rsi1 > rsi2;

 

def dmi1 = if DMI(length = 14).”DI+” >= DMI(length = 14).”DI-” then 8 else 7;

def dmi2 = if DMI(length = 14).”DI+” < DMI(length = 14).”DI-” then 8 else 7;

def dmiDescending = dmi1 > dmi2;

 

def sto1 = if StochasticMomentumIndex().”SMI” >= StochasticMomentumIndex().”AvgSMI” then 6 else 5;
def sto2 = if StochasticMomentumIndex().”SMI” < StochasticMomentumIndex().”AvgSMI” then 6 else 5;

def stoDescending = sto1 > sto2;

 

plot trigger = rsiDescending and dmiDescending and stoDescending;

Marked as spam
Posted by (Questions: 5, Answers: 16)
Asked on January 26, 2019 4:23 pm
275 views
0

You are going to have to provide more details because your code does nothing to explain what you are trying to accomplish. Which is probably why you are not getting expected results.
For example we’ll take your rsi1 and rsi2 statements. Both of these are always going to be equal. (either both will be 10 or both will be 9). The only time they will be different is when RSI equals exactly 50. Not sure you realize that. So by the time to test for rsi1 > rsi2 you have nearly zero chance of getting a result other than false.

( at January 27, 2019 12:01 pm)
0

Hello Pete, I submitted additional information, please let me know if you received it. I submitted a new answer but dont see it reflected in the thread. Thanks again.

( at January 27, 2019 7:52 pm)
0

If you provided more information using the “Post your Answer” at the bottom of the thread it was deleted and you were notified via email. That box at the bottom is reserved for new solutions to the post. Comments and additional details are provided only through the comments.

( at January 28, 2019 10:56 am)
0
Pete, My apologies, I did not see where to include an attachment via the “Add Comment” area, hence the reason I used the “Post your Answer” box. I did some additional work since my initial post, please see below: Right now the code works only when all three are TRUE: #The Indicator Alert 1 input length = 14; #RSI Settings def rsi = if reference RSI(length = 14).”RSI” >= 50 then 10 else 9; #DMI Settings def dmi = if DMI(length = 14).”DI+” >= DMI(length = 14).”DI-” then 8 else 7; #Stochastics Settings def sto = if StochasticMomentumIndex().”SMI” >= StochasticMomentumIndex().”AvgSMI” then 6 else 5; plot trigger = (rsi > rsi [1] and dmi > dmi [1] and sto > sto [1]); I would like the trigger to be: if any two are TRUE, then trigger when the third becomes TRUE. For example, if RSI and DMI are TRUE, the trigger will only occur if STO becomes TRUE, same for any combination of the 3. Also, please let me know how i can attach an image to show you my code working against the indicator, below is the code for the indicator: declare lower; input length = 14; #RSI Settings plot rsi1 = if reference RSI(length = 14).”RSI” >= 50 then 10 else 9; plot rsi2 = if reference RSI(length = 14).”RSI” = DMI(length = 14).”DI-” then 8 else 7; plot dmi2 = if DMI(length = 14).”DI+” = StochasticMomentumIndex().”AvgSMI” then 6 else 5; plot sto2 = if StochasticMomentumIndex().”SMI” < StochasticMomentumIndex()."AvgSMI" then 6 else 5; AddCloud(sto1, sto2, Color.Green, Color.red); rsi1.SetDefaultColor(Color.GRAY); rsi2.SetDefaultColor(Color.GRAY); dmi1.SetDefaultColor(Color.GRAY); dmi2.SetDefaultColor(Color.GRAY); sto1.SetDefaultColor(Color.GRAY); sto2.SetDefaultColor(Color.GRAY);
( at January 28, 2019 1:10 pm)
0

Pete,
Did the information provided help understand the use case?
Thanks for your time.

( at January 29, 2019 2:11 pm)
0
Private answer

Ok, now that we have the full details, here is the solution. (I have not tested this but I think I got it right. Let me know).

input length = 14;
#RSI Settings
def rsi = reference RSI(length = 14).”RSI” >= 50;
#DMI Settings
def dmi = DMI(length = 14).”DI+” >= DMI(length = 14).”DI-”;
#Stochastics Settings
def sto = StochasticMomentumIndex().”SMI” >= StochasticMomentumIndex().”AvgSMI”;
def conditionRSI = rsi and !rsi[1];
def conditionDMI = dmi and !dmi[1];
def conditionSTO = sto and !sto[1];
plot trigger = (rsi and dmi and conditionSTO) or (rsi and sto and conditionDMI) or (sto and dmi and conditionRSI);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on January 29, 2019 2:15 pm
0

Pete,
It worked! Brilliant… quick question, what does the “!” mean/tell the code to do?
Thanks

( at January 29, 2019 2:38 pm)
0

The “!” means NOT. So I changed your code so that rsi, dmi, and sto are true/false statements. So if we say: def myTest = rsi we are testing if rsi is true. When we apply the “!” to this we are testing if it is false: def myTest = !rsi.

( at January 29, 2019 2:47 pm)
0

Got it! Thanks again for your time and knowledge.

( at January 29, 2019 3:30 pm)