# Buy/Sell when MA reverses direction

**URL:** <https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695>\
**Category:** Seetu\
**Created:** [June 4, 2016, 9:09pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695 "2016-06-04T21:09:32Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![RayCharles](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/raycharles/32/238_2.png) [@RayCharles](https://forums.collective2.com/u/RayCharles)\
**Post date:** [June 4, 2016, 9:09pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/1 "2016-06-04T21:09:32Z")

</div>

Hi ,

Could you please provide some advice on creating a Buy or Sell signal when a Moving average reverses its direction.

Eg: MA reverses from Up to Down then Sell on next candle. Or the oposit for a Buying signal.

Thanks !

---

<div class="post-metadata">

**Author:** ![smallDogInvestor](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/smalldoginvestor/32/1487_2.png) [@smallDogInvestor](https://forums.collective2.com/u/smallDogInvestor)\
**Post date:** [June 5, 2016, 3:49pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/2 "2016-06-05T15:49:22Z")

</div>

Hi Ray, yes seetu can help you evaluate a few moving average reversals. However, to really get a feel for such a strategy you will need to evaluate hundreds of lengths of moving average over thousands of active products. Then you will need to evaluate the fade strategy for the same hundreds of lengths of moving average over the same thousands of products. Then summarize the findings to try to come to a data-driven conclusion about the merits of such a strategy. IMHO, seetu is not up to this larger task. You will need a general purpose language such as java, python, c++, etc.  
Best.  
-Allen

---

<div class="post-metadata">

**Author:** ![RayCharles](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/raycharles/32/238_2.png) [@RayCharles](https://forums.collective2.com/u/RayCharles)\
**Post date:** [June 5, 2016, 5:14pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/3 "2016-06-05T17:14:21Z")

</div>

Hi Allen, thanks for your reply.

Let me narrow down the variables to 1 symbol and 1 moving average, so the strategy might be feasible on Seetu.

For example:

- Buy SPY on the the opening of next candle after MA 9 Turns Up

- stop loss on the minimum of previous candle

- stop gain equals stop loss on opposite direction

- Sell SPY with same logic with opposite signals

My main trouble right now is how to detect that a MA change its direction.

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![GameTime](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/gametime/32/1487_2.png) [@GameTime](https://forums.collective2.com/u/GameTime)\
**Post date:** [June 5, 2016, 7:14pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/4 "2016-06-05T19:14:00Z")

</div>

likely you will never make any money long term. Guys if it was that simple everyone would be millionaires. Do you think your the first one that thought of that idea? I don’t mean to be critical but it amazes me how many people think trading is that easy. I trade full time for a living and i only wish it was that simple (and for the record, yes i have tried that and back tested it).

---

<div class="post-metadata">

**Author:** ![MachineLearningTradr](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/machinelearningtradr/32/1352_2.png) [@MachineLearningTradr](https://forums.collective2.com/u/MachineLearningTradr)\
**Post date:** [June 5, 2016, 8:13pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/5 "2016-06-05T20:13:32Z")

</div>

I code, but not Seetu. So I can’t give specifics, but generally:

If the MA increased from the previous MA, then it ‘turned up.’ And vice-versa.

How to tell if it increased/decreased?

Use a variable to store MA. Next day, compare new MA to MA that’s stored in a variable. Or,

If there is a way, just calculate current MA, and the MA from previous day, and compare.

HTH

---

<div class="post-metadata">

**Author:** ![MachineLearningTradr](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/machinelearningtradr/32/1352_2.png) [@MachineLearningTradr](https://forums.collective2.com/u/MachineLearningTradr)\
**Post date:** [June 5, 2016, 9:01pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/6 "2016-06-05T21:01:58Z")

</div>

Left some stuff out.

Actually, when the MA is increasing, it is up, of course. But you asked about reversals.

So, when the MA goes from down to up, then a reversal has taken place.

So, you may need an additional variable to store the _direction_ of the MA (up/down).

And vice-versa on all of the above.

---

<div class="post-metadata">

**Author:** ![smallDogInvestor](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/smalldoginvestor/32/1487_2.png) [@smallDogInvestor](https://forums.collective2.com/u/smallDogInvestor)\
**Post date:** [June 5, 2016, 11:32pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/7 "2016-06-05T23:32:05Z")

</div>

gametime, i think ray is picking a facile strategy as a self-challenge to learn seetu programming, not necessarily to proclaim it a profitable strategy.

---

<div class="post-metadata">

**Author:** ![smallDogInvestor](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/smalldoginvestor/32/1487_2.png) [@smallDogInvestor](https://forums.collective2.com/u/smallDogInvestor)\
**Post date:** [June 5, 2016, 11:39pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/8 "2016-06-05T23:39:21Z")

</div>

Ray,  
you need to compare current close with previous two closes.  
if close[-2] greater than close[-1] and close[-1] is less than close[0] then you have a bounce.  
Best.  
-Allen

---

<div class="post-metadata">

**Author:** ![MachineLearningTradr](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/machinelearningtradr/32/1352_2.png) [@MachineLearningTradr](https://forums.collective2.com/u/MachineLearningTradr)\
**Post date:** [June 6, 2016, 12:04am UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/9 "2016-06-06T00:04:00Z")

</div>

He’s asking about the _moving average_ of closes.

---

<div class="post-metadata">

**Author:** ![RayCharles](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/raycharles/32/238_2.png) [@RayCharles](https://forums.collective2.com/u/RayCharles)\
**Post date:** [June 6, 2016, 1:55am UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/10 "2016-06-06T01:55:29Z")

</div>

**Gametime:** Thanks for the advice. As Allen mentioned, I am familiarizing with coding in Seetu with a popular setup from trader Larry Williams.

**MachineLearningTradr** and **AllenEverhart** , thanks for the tips, they make a lot of sense, I am about to test the Seetu code below:

MA9 = CalcMA (close, 9);  
MA9last1 = ref (MA9, -1);  
MA9last2 = ref (MA9, -2);

BuySignal = MAlast2 \> MA9last1 \< MA9last;

---

<div class="post-metadata">

**Author:** ![MachineLearningTradr](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/machinelearningtradr/32/1352_2.png) [@MachineLearningTradr](https://forums.collective2.com/u/MachineLearningTradr)\
**Post date:** [June 6, 2016, 5:26am UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/11 "2016-06-06T05:26:08Z")

</div>

Like I said, I don’t code Seetu, but it looks like you understand the logic of what I was trying to say. 😄

But, based upon what you wrote, maybe try:

BuySignal = MA9 \> MA9last1 \< MA9last2;

---

<div class="post-metadata">

**Author:** ![BobSvan2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/bobsvan2/32/21391_2.png) [@BobSvan2](https://forums.collective2.com/u/BobSvan2)\
**Post date:** [June 6, 2016, 11:10am UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/12 "2016-06-06T11:10:27Z")

</div>

Hello!

Just a remark:

```
BuySignal = MA9 > MA9last1 < MA9last2;

```

is not valid syntax.

Valid syntax is something like: BuySignal = A \> B AND B \< C;

Re the original question: See this for inspiration:

> [@More Question (position based management, turns, and triggers)](https://forums.collective2.com/t/more-question-position-based-management-turns-and-triggers/8194):
>
> Couple more questions for a newbie to Seetu: I couldn’t find functions/methods for this in the manual - if it exists, just point me to it. Position Based Management: How to sell a position after x bars, days, etc… How to sell a position after a profit is reached (% or $) How do I plot executed trades on the chart? Are there TurnUp/TurnDown functions? (maybe I thinking about this wrong - so let me know if this is the case) Do you have plans for triggers? This something really…

---

<div class="post-metadata">

**Author:** ![RayCharles](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/raycharles/32/238_2.png) [@RayCharles](https://forums.collective2.com/u/RayCharles)\
**Post date:** [June 6, 2016, 12:02pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/13 "2016-06-06T12:02:13Z")

</div>

Yes! That’s the idea, my typo.  
Cheers.

---

<div class="post-metadata">

**Author:** ![RayCharles](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/raycharles/32/238_2.png) [@RayCharles](https://forums.collective2.com/u/RayCharles)\
**Post date:** [June 6, 2016, 12:03pm UTC](https://forums.collective2.com/t/buy-sell-when-ma-reverses-direction/8695/14 "2016-06-06T12:03:04Z")

</div>

@BobSvan2 this post sums up most of my doubts. Thanks.
