|
Jeff D
2014-01-18 11:37:40
|
|
Trying to do a conditional buy where if the stock is above its ema(20) then buy otherwise buy SPY. This works fine (buy = (res <= 1) and newmonth;) so i'm just tryning to add the ema filter.
Here are just the lines I'm not sure of:
1. Can I assign a symbol to cahs in this way?
2. Is conditional in this way feasible?
cash = "SHY";
mafilter = close > ema(20);
buy = iff(mafilter==1, (res <= 1) && newmonth, cash);
Thanks guys.
|
|
|
|
QuantShare
2014-01-18 11:48:12
0
|
|
Best Answer
It doesn't work that way.
In the trading system symbols, add one or several stocks then add SPY.
Type the following formula:
isSPY = StringEqual(Name(), "SPY");
mafilter = close > ema(20);
buy = iff(mafilter, (res <= 1) && newmonth && !isSPY, isSPY);
|
|
|
|
Jeff D
2014-01-18 13:53:09
0
|
|
Perfect. Thanks.
|
|
|
|
Kiran
2016-02-10 20:37:25
0
|
|
This logic works if there are only 2 stocks SPY and the other.
How do we implement logic in a simulation of 20 positions, where in each position, it buys the stock if Condition is met, else it buys SPY for each position?
|
|
|
|
QuantShare
2016-02-11 02:59:27
0
|
|
The simulation formula is run for each security. For each run, it checks the security close price and compares it with the moving average.
So the logic works with any number of positions.
|
|
|
|
Nuno
2016-06-11 08:37:11
0
|
|
What is "res"?
|
|
|
|
QuantShare
2016-06-11 10:43:04
0
|
|
"res" is a simple variable (like isSPy and mafilter) used by "Jeff D". He did not specify how that variable was calculated.
|
|
|
|