Page 1 of 1

Coding a certain value difference between moving averages

Posted: Sat Mar 19, 2022 10:20 am
by Demalesius
Hello guys

I have following problem. I want to have a code for an opening order for following criteria:

EMA8 has to be higher than EMA14 but also with at least 5% or a certain value.

This is working fine but doesn't includes the 5% or a value:



longCondition1 = ema(close, 8) > ema(close, 14)



So I tried something like this for the 5%:



longCondition1 = ema(close, 8) > (ema(close, 14) * 1.05)

longCondition1 = ema(close, 8) > ((ema(close, 14) + (ema(close,14) * 0.05))



And I tried this for the value of for example 200:



longCondition1 = ema(close, 8) > (ema(close, 14) + 200)



I really can't figure it out.

May someone can help me please..

Re: Coding a certain value difference between moving averages

Posted: Fri Mar 25, 2022 2:16 pm
by processingclouds
Hey,

Issue is when you add 5% it will add a huge difference to the ema 8 and ema14 which will mean ema8 will never cross that point. Just to show this here is code to plot ema 8 , ema 14 and ema14*1.05 lines.

Code: Select all

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © processingclouds

//@version=5
indicator("My script", overlay=true)

ema8 = ta.ema(close, 8)
ema14= ta.ema(close, 14)

plot(ema8, color = color.green, linewidth = 2)
plot(ema14, color = color.purple, linewidth = 2)
plot(ema14*1.005, color = color.orange, linewidth = 2)