• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Modify the DMI Oscillator strategy in ToS

Mzxir

New member
VIP
Hello everyone, I am having some trouble trying to edit the code for the DMI Oscillator strategy on think or swim. I am trying to add a long signal on the hist every time the value crosses 22.5 and a short every time crosses -22.5 but this is a bit trickier then I thought. I've gotten s far as to write out the basic code for these commands but I think it's not working because I am using a constant with an "if" expression the wrong way. Because apparently this isn't the correct way. Can anybody help me get this right?

plot <Hist>;
if <integer crosses 22.5> [then] {
<Hist> = <OrderType.BUY_TO_OPEN>;
} else {
if <integer crosses -5> [then] {
<Hist> = <SELL_TO_CLOSE>;
} else {
<plot_name> = <expression3>;
}
}
plot <Hist>;
if <integer crosses 22.5> [then] {
<Hist> = <OrderType.SELL_TO_OPEN>;
} else {
if <integer crosses 10> [then] {
<Hist> = <BUY_TO_CLOSE>;
} else {
<plot_name> = <expression3>;
}
}
 
Last edited by a moderator:

BenTen

Administrative
Staff
VIP
Something like this?

Code:
input length = 10;
input paintBars = yes;
input averageType = AverageType.WILDERS;

def diPlus = DMI(length, averageType)."DI+";
def diMinus = DMI(length, averageType)."DI-";

def Osc = diPlus - diMinus;

def buy = Osc crosses above 22.5;
def sell = Osc crosses below 22.5;

AddOrder(OrderType.BUY_TO_OPEN, condition = buy, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = sell, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");
 

Similar threads

Top