Moving Average (Offset)
Author: RodrigoAcioli
Creation Date: 10/16/2020 11:27 AM
profile picture

RodrigoAcioli

#1
I wonder if there is a possibility to run a test with Moving Average (Offset).


For example:
- arithmetic moving average of the minimum of two periods, with a displacement of 1
- arithmetic moving average of the maximum of two periods, with a displacement of 1

- Logic: buy the asset when it touches the arithmetic moving average of the minimum of the last two candles (not including the current one, hence the offset); sell the asset when it touches the arithmetic moving average of the maximum of the last two candles (not including the current one, hence the offset).

- Practice: touched the minimum average is bought and sells when touching the average maximum.


I'm a beginner, I appreciate help!
profile picture

Cone

#2
"Anything's possible" Rodrigo, so the question should be "How do I..."

To move a series forward in time, i.e., access a delayed series, use the >> operator. In this case, it would be useful to show the plotted series this way, but you don't need to do this offset in the trading rules because it happens "automatically". Maybe the code will make it clear:

CODE:
Please log in to see this code.
profile picture

Eugene

#3
Hi,

Sure it's possible:

Offset of a moving average?
Offset DataSeries?

You can also do it in Rule-based strategies by using the ShiftedMA indicator.
profile picture

RodrigoAcioli

#4
Thank you very much Cone, that was exactly it!

Eugene,
but how could i do it using Rule-based strategies (using the ShiftedMA indicator)?
profile picture

Eugene

#5
Choose it as an Indicator parameter for conditions from the "General Indicators" group.

There's a walkthrough in post #2 (for a pretty specific case, I admit) which should show you how to use it:

Condition true today and yesterday
profile picture

RodrigoAcioli

#6

Eugene, thank you very much, I managed to configure the ShiftedMA, but the rule (General Indicator) to buy and sell at the exact points, I couldn't, could you help me again?
profile picture

Eugene

#7
Help with what exactly?
profile picture

RodrigoAcioli

#8
Which General Indicator, should I use for the points to buy and sell?

- Practice: touched the minimum average is bought and sells when touching the average maximum.

Because, I didn't find one that was suitable.

Thank you for your attention!
profile picture

Eugene

#9
Perhaps "Price crosses X% [0.01] below (above) indicator". But a trade would happen on the next bar unlike Cone's code in post #2.
profile picture

RodrigoAcioli

#10

Thank you very much Eugene, even managing to change to buy and sell, in the current bar, it was not possible to start the operation at the exact point (touched the minimum average is bought and sells when touching the maximum maximum). I used the attached rule, but I think the problem would be the "close" setting in "Limit Price" and "Price".

I really appreciate your help!
profile picture

Eugene

#11
Well, Rule-based strategies have their limitations. You can use code in post #2.
profile picture

RodrigoAcioli

#12
It's okay, Eugene, thank you very much for your attention!
Cone, thank you again for your attention!

Thank you very much for your help!!!
profile picture

Eugene

#13
You're welcome!
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).