Create sell order based on either of two conditions


Category:
0
0

Ive been playing with a strategy that uses MACD, RSI and VWAP to choose entry and exit points. All of the individual parameters work but I cant figure out how to format the SELL_AUTO statement to choose between 3 different possibilities. The character limit wouldnt let me post all of the code so the segment below is where Im having truoble. Thanks

def selTrig; 
if diff < 0 and price is less than VWMA [then] {selTrig = 1;
} else if rsi is greater than or equal to 67 and diff crosses below 0
[then] {selTrig = 1;
} else {selTrig = 0;
}

AddOrder(OrderType.BUY_AUTO, diff crosses above 0 and rsi is less than 37 within 6 bars and rsi is greater than or equal to 33 within 1 bars , tickColor = GetColor(0), arrowColor = GetColor(0), name = "MACD+RSI_LE");

AddOrder(OrderType.SELL_AUTO, selTrig = 1, tickColor = GetColor(1), arrowColor = GetColor(1), name = "MACD+RSI_LX");

Marked as spam
Posted by (Questions: 3, Answers: 1)
Asked on June 2, 2020 1:48 pm
67 views
1
Private answer

The character limit is there specifically to prevent folks from posting code that is longer than 24 lines in the body of their question. The correct move at that point is to save the code to a plain text file and add it as an attachment when posting your question. To late to do that once you have submitted your question.

Rather than try to fix what you have I will show you the way I would write this. I tend to break things down into basic elements. Makes it easier to trouble shoot the code and make changes later on.

I cannot tell if this actually solves your problem. But if it does not give you expected results you have things broken down into separate pieces to make it easier to see where the failure is.

def sellConditionOne = diff < 0 and price is less than VWMA;
def sellConditionTwo = rsi is greater than or equal to 67 and diff crosses below 0;
AddOrder(OrderType.SELL_AUTO, sellConditionOne or sellConditionTwo, tickColor = GetColor(1), arrowColor = GetColor(1), name = "MACD+RSI_LX");

This method will enable you to convert those two def statements to plots so you can look at them on the chart and see where they are being triggered.

Marked as spam
Posted by (Questions: 37, Answers: 3223)
Answered on June 2, 2020 3:42 pm
That did the trick, thanks for your help.
( at June 3, 2020 8:00 am)