Page 1 of 4

Moving-average based stop order [new] + FIFO now!

PostPosted: Mon Oct 04, 2010 2:40 pm
by Nikolay.Gekht
This is an update for Moving-Average based stop order published here: viewtopic.php?f=31&t=2209

The strategy moves stop level of the chosen position exactly on the chosen Moving Average Value. The recommended settings are in range 100-200 for hourly or higher time frame.

Unlike the previous version, this strategy:
a) Starts to work immediately, without waiting for the first tick on chosen instrument.
b) Checks the the most recent MVA value every chosen period (1 second by default) and updates stop if MVA is changed more than for 1/10 of pip.
c) Stops automatically when trade disappears.
d) With "autotrading patch" does not show annoying "Event Log" window every time when stop order is changed. So, if you switched "Don't show this window on next event" to avoid "stop order changed events" you can switch it back, so, other alerts will not skipped anymore.

mvastop3.png


Because this strategy manages the regular stop order, it CANNOT be used on FIFO accounts (any accounts opened in US broker). For US accounts please use
net stop version of the strategy.

Download signal:
mvastop3.lua
(7.94 KiB) Downloaded 2704 times


The Strategy was revised and updated on December 11, 2018.

Re: Moving-average based stop order [new version]

PostPosted: Mon Oct 18, 2010 12:48 pm
by Nikolay.Gekht
Wonderful instruction by Jason Rodgers on how to use the strategy can be found here:
http://www.informedtrades.com/blogs/jas ... -loss.html

FIFO (net stop) version

PostPosted: Wed Oct 20, 2010 6:14 pm
by Nikolay.Gekht
If your account is opened in FXCM US or other US-based broker, you cannot use the regular stop and limit orders due to NFA regulation (google for "NFA rule 2-43(b)") which prohibits selective positions management. In other words - you must close first the older positions on the same account for the same instruments. The mvastop3 strategy in the first post of this topic cannot be used as well.

However, the Trading Station provides a good alternative for stop orders - the net stop orders. You can set up them via "Summary" view for chosen account and instrument. If you recognize the whole amount of particular instrument on particular account as one netting position this orders works good enough for risk management.

So, please find the netting stop MVA-based order below. Unlike the strategy above, this strategy is attached to the instrument and the account (instead of the instrument and the trade). Everything else is the same - if the set of positions is long and chosen MVA value is below the market - the strategy creates and then tracks the order according MVA value. And, in opposite case - if the set of positions is short and chosen MVA value is above the market...

The strategy creates the stop order only in case the position exist. If position is closed, the strategy does not stop, but waits until the next position is created.

Please DO NOT use this strategy on non-FIFO (for example FXCM UK or dbFX accounts)!

Download:
mvastop4.lua
(8.19 KiB) Downloaded 1902 times

Re: Moving-average based stop order [new] + FIFO now!

PostPosted: Wed May 04, 2011 5:46 am
by alepan72
Hi Nikolay!
I love this strategy (mvastop3). I use it for all of my trades. I want to write the code in my strategies, but I have a big problem and I wonder if you can help me... :roll:
If I write the code in a tick strategy (like orders) everything is OK. When I include the mvastop strategy into a candle strategy, mvastop3 stop the trade when the price hit an EMA but on close of current candle. Can you tell me how I must write the code, so strategy open a trade on a close candle (e.g. MA_advisor or RSI_strategy) but the mvastop work on tick?
I am grateful if you can me help with the code or if it exists somewhere a document - guide to read.
Best regards!
Thanks in advance :!:

Re: Moving-average based stop order [new] + FIFO now!

PostPosted: Wed May 04, 2011 7:47 am
by Nikolay.Gekht
alepan72 wrote:Hi Nikolay!
I love this strategy (mvastop3). I use it for all of my trades. I want to write the code in my strategies, but I have a big problem and I wonder if you can help me... :roll:
If I write the code in a tick strategy (like orders) everything is OK. When I include the mvastop strategy into a candle strategy, mvastop3 stop the trade when the price hit an EMA but on close of current candle. Can you tell me how I must write the code, so strategy open a trade on a close candle (e.g. MA_advisor or RSI_strategy) but the mvastop work on tick?
I am grateful if you can me help with the code or if it exists somewhere a document - guide to read.
Best regards!
Thanks in advance :!:

Do you use helper.lua in your strategy? (It is just a slightly different approach in case it is used or not).

Re: Moving-average based stop order [new] + FIFO now!

PostPosted: Wed May 04, 2011 9:28 am
by alepan72
Thanks for direct correspondence

Yes, I use helper.lua

Re: Moving-average based stop order [new] + FIFO now!

PostPosted: Thu May 05, 2011 10:56 am
by Nikolay.Gekht
With helper Lua:

1) Add a subscribtion for ticks:

Code: Select all
bid = ExtSubscribe(id, nil, "t1", true, "close");
-- or
ask = ExtSubscribe(id, nil, "t1", false, "close");


where id is an integer number which is different from the subscribtion id used for other collections you subscribed.

2) Add the case into ExtUpdate(id, source, period)

Code: Select all
if id == _your_bar_history_id_ then
   ...
elseif id == _your_tick_history_id_ then
   --
   -- this case will work on every tick!
   --

   -- calc stop level here
   ...
   -- apply stop level here
   ...
end

Re: Moving-average based stop order [new] + FIFO now!

PostPosted: Thu May 05, 2011 1:33 pm
by alepan72
Thanx a lot :!: :!: :!:
Your services are so helpfull!

Keep coding ;)
:lol:

Re: Moving-average based stop order [new] + FIFO now!

PostPosted: Tue May 10, 2011 3:48 pm
by bguguen
Hey hey, im absolutely loving this feature, found it very useful however, just couple of question, is it possible to add a feature to it so i get to ADD more positions into the strategy?? because if im understanding correctly this strategy can only manage 1 trade at a time using the parameteres set, but what if i keep adding positions with the same purpose of having the SL following the EMA and eventually they will all Stop out as trend changes, and some will hit SL with a BE Positive win...

yea thats about it...

Re: Moving-average based stop order [new] + FIFO now!

PostPosted: Mon Apr 23, 2012 4:26 am
by spinemaligna
hi all,
Is it possible, and if so, could you add the facility to offset the value of the average by a number of pips.

Many thanks,
Ross