Relative Strength MA buy/sell order


Category:
0
0

Hi Pete,

Awhile ago you gave the code for a relative strength moving average.

https://www.hahn-tech.com/ans/reference-an-indicator-dataset/

I’m trying to use it as a strategy and I’m not getting any buy order. Did I forget someting ?

Of course, enabled is checked and position effect is “auto”. I’ve made both the long entry/exit as follow:

Long entry:

input CorrelationWithSecurity = “SPX”;

input averageType = AverageType.EXPONENTIAL;

input length = 21;

def close2 = close(CorrelationWithSecurity);

plot RS = if close2 == 0 then 0 else close/close2;

RS.setDefaultColor(GetColor(6));

def sr = CompoundValue(“historical data” = RS, “visible data” = if isNaN(sr[1]) then RS else sr[1]);

plot SRatio = sr;

SRatio.setDefaultColor(GetColor(5));

plot ma = MovingAverage(averageType, RS, length);

def rsma = ma [0]>ma[2];

AddOrder(OrderType.BUY_AUTO, rsma [0], open [-1], tickcolor = GetColor (0), arrowcolor = GetColor (0)) ;

Long exit:

same exept for:

def rsma =  ma[0] < ma[2] ;

AddOrder(OrderType.SELL_AUTO, rsma [0], open [-1], tickcolor = GetColor (4), arrowcolor = GetColor (4)) ;

Also, SPX is the default symbol in the code for the rs. Is there any way it can be the same as the one used in the relative strength moving average lower study ?

Thank’s !

Louis

Marked as spam
Posted by (Questions: 5, Answers: 3)
Asked on March 13, 2020 4:28 am
149 views
0
Private answer

Works just fine when I test it. However I had to change the long exit portion because you cannot assign two different values to the same variable. You need to have separate variable names for your long entry and long exit variables.

def longEntry = ma[0 ]> ma[2];
AddOrder(OrderType.BUY_AUTO, longEntry [0], open [-1], tickcolor = GetColor (0), arrowcolor = GetColor (0)) ;

def longExit = ma[0] < ma[2] ;
AddOrder(OrderType.SELL_AUTO, longExit [0], open [-1], tickcolor = GetColor (4), arrowcolor = GetColor (4)) ;

The moving average is already being computed from the Relative Strength (which is derived from the default symbol "SPX"). So I don't understand your last question.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 13, 2020 7:17 am