Help to write a rule for buying/selling when a ticker passes 1 or 2 indicatros

Hi,

Is there someone who could help to write this rule?

If a specific ticker crosses downward the SMA ( x), then sell 50% of the position, if the ticker crosses SMA ( y) downward than sell the other 50%.

if it crosses upward one SMA then you buy back 50% and if it crosses upward the second SMA than you buy the remaining 50%

Thanks

Steve

The “Eval” function allows partial sells, for instance:
Eval(close(0)<sma(50),0.5,0)
Will sell half if a position’s below the 50 bar sma. (See Help->Reference->Eval)

Apparently, partial buys aren’t supported…

thank you for your post.
I am not sure that it works on my end.
Do I need to paste the formula in the SELL formula?

Eval(close(0)<sma(50),0.5,0) Should be a sell rule.

Is it possible to specify on which ticker the formula Eval(close(0)<sma(50),0.5,0) is applied?
I believe that if I enter Eval(close(0)<sma(50),0.5,0) in my portfolio sell rule, it will calculate the SMA on my combined holdings, but if I want the formula to be applied on the SPY (ETF) of the S&P500, how can I declare that in the formula?

The sell rule is applied to each holding individually, not the entire portfolio.
To limit to one holding, such as SPY, just logically and a ticker function in the sell rule:
Ticker(“SPY”) & Eval(close(0)<sma(50),0.5,0)

If you’re just starting out, it might be helpful to read the HELP->Tutorials or HELP->Reference sections of P123…

steverose - if you are running a stock simulation (as opposed to an ETF sim) then you would use the following sell rule:

Eval(Close(0,GetSeries(“SPY”))<SMA(200,0,GetSeries(“SPY”)),0.5,0)

However, this will cause a 50% liquidation of every stock holding every rebalance period that the SPY is under its moving average. Is that what you are looking for?

Don’t be discouraged from asking questions. Yes it does help to read the documentation, but the platform can be overwhelming when you first start out and asking questions / getting answers can make the difference between staying or quitting.

Steve

Hi Steve Rose,

welcome to p123. Here the nearest approximation I would use:

Sell rule: Eval(Close(0)<SMA(x) and Close(0)>SMA(y),0.5,Eval(Close(0)<SMA(x) and Close(0)<SMA(y),1,0))

Buy rule: Eval(Close(0)>SMA(y) and Close(0)<SMA(x),0.5,Eval(Close(0)>SMA(x) and Close(0)>SMA(y),1,0))

Hth,
Florian

Sister - buy rules don’t recognize “0.5”, only TRUE or FALSE. Steve R is also asking about use of a specific ETF for timing. Perhaps what he should be using is the Hedge/timing module.

Steve

You’re right, Steve! I wonder why a 0.5 weighting was never implemented as an option in the buy rules.

Or the hedge module. It may require a bit of a change in the hedge module semantics, but I think it would work.

Walter

With the hedge module, you can use SHY and get a similar effect as cash.

Thanks for your feedback

my understanding is that it is not possible to use the hedging system in an ETF simulation or portfolio. It seems to work only for Stocks.

My objective is simple but even after reading the documentation and researching the forum (and even asking P123), I can’t do the following rules and it is really frustrating:

  1. I have an ETF only list that is rebalanced every 2 weeks following my ranker
  2. in the meantime, and on a daily basis, I want to check the overall trend in the market using a more wider ETF such as SPY (for the S&P500).
  3. if the SPY or another ETF is crossing an indicator such as SMA, then I don’t want to wait for the next rebalance (which can happen to be in 14 days per example) to get out of the market. In fact, I want to sell my portfolio in 2 steps. The first step is to sell x% of the portfolio when the SPY crosses indicator #1 and then sell the remaining portfolio if SPY crosses the second indicator.
  4. on the other hand, by checking daily the overall SPY trend, I want to be able to re-purchase my portfolio based on my ranker without having to wait for the next rebalance.

What I am not sure is if P123 can run 2 rebalance system concurrently to check different rules for different set of assets and then use one system to trigger the other system…

Without this kind of “cross-system”, I think there are a lot of limitations in the creativity you can apply.

BUT I am sure I don’t know enough of P123, so I must miss something here.

Steve

steverose - you should be able to do most of what you want to do. You have to “rebalance” daily. In the sim there is a setting. For ports, you have to rebalance manually every morning. Rebalancing every two weeks can be implemented with the sell rule Mod(NoDays,14)=0. However, you will have trouble setting the day of the week you want to rebalance on. You need to know the starting day of week for the sim and then it will maintain that day of week. This rule will skip weeks when holidays occur on the rebalance day so you need to have a way of accounting for this (if you care).

You will have to create your own version of CrossOver() and CrossUnder() as they do not support GetSeries(). You can create crossover as SMA(50,0,GetSeries(“SPY”))>SMA(200,0,GetSeries(“SPY”)) And SMA(50,1,GetSeries(“SPY”))<SMA(20,200,GetSeries(“SPY”)) .

To sell half you need to use the Eval statement as described earlier. Also you need to override your rebalancing rule as this would cause everything to be rebought.

You cannot buy half the quantity of each ETF. You can use the buy rule CashPct>50 which will keep 50% cash but it won’t scale back the qty of shares.

To re-buy all, you need to sell everything first i.e rebalance

Hope this helps,
Steve A