Traderji.com - Online community for Indian investors & traders!


Volatility Stop Loss /need code from Metasa to Amibroker/

Discuss Volatility Stop Loss /need code from Metasa to Amibroker/ at the AmiBroker within the Traderji.com - Online community for Indian investors & traders!; Hi There is quite good Volatility Stop Loss based on Average True Range (ATR). It ...


Go Back   Traderji.com - Online community for Indian investors & traders! > TOOLS & RESOURCES > Software > AmiBroker


Reply
 
Thread Tools
  #1  
Old 27th March 2010, 06:41 PM
szachool's Avatar
Member
 
Join Date: Aug 2009
Posts: 10
Thanks: 10
Thanked 5 Times in 2 Posts
szachool is on a distinguished road
Default Volatility Stop Loss /need code from Metasa to Amibroker/

Hi

There is quite good Volatility Stop Loss based on Average True Range (ATR). It depends on ATR, some kind of multipiler.
It is written in the code for Metastock, and I am looking someone, who would like to translate 3 short codes below. I thinkt that it may be very usefull for us.

Source page

This is the basic formula switching on stop breaks:
Quote:
SVE_Stop_Trail_ATR

atrper:=Input("ATR period :",1,100,5);
atrfact:=Input("ATR multiplication :",1,10,3.5);
loss:=atrfact*ATR(atrper);
trail:=
If(C>PREV AND Ref(C,-1)>PREV,
Max(PREV,C-loss),
If(C<PREV AND Ref(C,-1)<PREV,
Min(PREV,C+loss),
If(C>PREV,C-loss,C+loss)));
Trail
Stop Long
Quote:
SVE_StopLong_Trail_ATR_Date

{SVE_StopLong_Trail_ATR_Date - ATR trailing stop Long from date}
InpMonth:=Input("Month",1,12,1);
InpDay:=Input("Day",1,31,2);
InpYear:=Input("Year",1800,2050,2009);
InitStop:=Input("Initial Stop Price",0.1,10000,10);
atrper:=Input("ATR period :",1,100,5);
atrfact:=Input("ATR multiplication :",1,10,3.5);
loss:=atrfact*ATR(atrper);
EntryLong:= InpYear=Year() AND InpMonth=Month() AND InpDay=DayOfMonth();
EntryLock:=If(Ref(EntryLong,-1)=0 AND EntryLong=1,1,PREV);
support:=C-loss;
TrailStopLong:= If(EntryLock=0 OR EntryLong=1,InitStop,
If(support>Ref(Support,-1),Max(support,PREV),PREV));
TrailStopLong

Stop Short
Quote:
SVE_StopShort_Trail_ATR_Date

{SVE_StopShort_Trail_ATR_Date - ATR trailing stop Short from date}
InpMonth:=Input("Month",1,12,1);
InpDay:=Input("Day",1,31,2);
InpYear:=Input("Year",1800,2050,2009);
InitStop:=Input("Initial Stop Price",0.1,10000,10);
atrper:=Input("ATR period :",1,100,5);
atrfact:=Input("ATR multiplication :",1,10,3.5);
loss:=atrfact*ATR(atrper);
EntryLong:= InpYear=Year() AND InpMonth=Month() AND InpDay=DayOfMonth();
EntryLock:=If(Ref(EntryLong,-1)=0 AND EntryLong=1,1,PREV);
support:=C+loss;
TrailStopShort:= If(EntryLock=0 OR EntryLong=1,InitStop,
If(support>Ref(Support,-1),Min(support,PREV),PREV));
TrailStopShort
And this Volatility Stop can also be usefull for programmers.
Source page


Thanks, for any help.


Advertisements

Reply With Quote
Advertisements
  #2  
Old 13th July 2010, 05:30 PM
Member
 
Join Date: Sep 2009
Posts: 44
Thanks: 0
Thanked 44 Times in 26 Posts
tools&tradingideas will become famous soon enough
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

hi, this is what I get:

// from Metastock formula, link: http://stocata.org/metastock/stop_trail_atr.html
per = Param("per",20, 5, 150, 1);
mult = Param("mult",2, 1, 4, 0.05);
tr = mult * ATR(per);

trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
trailArray = Ref(trailArray,-1);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot(trailArray,"\ntrailArray",ParamColor("ColorTr ail",ColorRGB(255,255,255)),styleStaircase);
Plot( C, "\nCandle",colorWhite, styleCandle );
Reply With Quote
  #3  
Old 13th July 2010, 05:52 PM
Member
 
Join Date: Sep 2009
Posts: 44
Thanks: 0
Thanked 44 Times in 26 Posts
tools&tradingideas will become famous soon enough
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

put in a function and added some colours:

// from Metastock formula, link: http://stocata.org/metastock/stop_trail_atr.html

function vstop_func(tr)
{
trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
return trailArray;
}

per = Param("per",20, 5, 150, 1);
mult = Param("mult",2, 1, 4, 0.05);
tr = mult * ATR(per);
trailArray = vstop_func(tr);
//trailArray = Ref(trailArray,-1);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot(IIf(trailArray > C,trailArray,Null),"\ntrailShort",ParamColor("Colo rTrailShort",ColorRGB(255,0,0)),styleStaircase);
Plot(IIf(trailArray < C,trailArray,Null),"\ntrailLong",ParamColor("Color TrailLong",ColorRGB(0,255,0)),styleStaircase);
Plot( C, "\nCandle",colorWhite, styleCandle );

Last edited by tools&tradingideas; 22nd July 2011 at 04:09 AM.
Reply With Quote
The Following User Says Thank You to tools&tradingideas For This Useful Post:
Petom (18th July 2010)
  #4  
Old 14th July 2010, 02:35 AM
Member
 
Join Date: Sep 2009
Posts: 44
Thanks: 0
Thanked 44 Times in 26 Posts
tools&tradingideas will become famous soon enough
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

simple reversal system can be constructed using this volatility stop. Let me know if someone has ideas how to use it

Last edited by tools&tradingideas; 22nd July 2011 at 04:09 AM.
Reply With Quote
  #5  
Old 17th July 2010, 07:52 PM
Member
 
Join Date: May 2010
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
Ayuraveda is on a distinguished road
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

Could you pls. write the full AFL that included B/S arrow like the picture ?
Thanks
Reply With Quote
  #6  
Old 18th July 2010, 03:22 AM
Member
 
Join Date: Sep 2009
Posts: 44
Thanks: 0
Thanked 44 Times in 26 Posts
tools&tradingideas will become famous soon enough
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

Quote:
Originally Posted by Ayuraveda View Post
Could you pls. write the full AFL that included B/S arrow like the picture ?
Thanks
best to try to code it yourself since you only know if it can be used when you do some backtesting. This type of system works on very volatile futures like TF, see Friday trading:

Last edited by tools&tradingideas; 22nd July 2011 at 04:09 AM.
Reply With Quote
  #7  
Old 26th March 2011, 03:16 AM
szachool's Avatar
Member
 
Join Date: Aug 2009
Posts: 10
Thanks: 10
Thanked 5 Times in 2 Posts
szachool is on a distinguished road
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

Well done. Thank t&t
Reply With Quote
  #8  
Old 27th March 2011, 09:06 PM
Member
 
Join Date: Sep 2009
Posts: 160
Thanks: 1,009
Thanked 229 Times in 85 Posts
cbosein has a spectacular aura aboutcbosein has a spectacular aura aboutcbosein has a spectacular aura about
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

Hi Tools&tradingideas,

Good & decent chart
Thanks & regards
keerthi

Quote:
Originally Posted by tools&tradingideas View Post
put in a function and added some colours:

// from Metastock formula, link: http://stocata.org/metastock/stop_trail_atr.html

function vstop_func(tr)
{
trailArray[ 0 ] = C[ 0 ]; // initialize
for( i = 1; i < BarCount; i++ )
{
prev = trailArray[ i - 1 ];

if (C[ i ] > prev AND C[ i - 1 ] > prev)
{
trailArray[ i ] = Max(prev,C[ i ] - tr[ i ]);
}
else if (C[ i ] < prev AND C[ i - 1 ] < prev)
{
trailArray[ i ] = Min(prev,C[ i ] + tr[ i ]);
}
else if (C[ i ] > prev)
{
trailArray[ i ] = C[ i ] - tr[ i ];
}
else
{
trailArray[ i ] = C[ i ] + tr[ i ];
}
}
return trailArray;
}

per = Param("per",20, 5, 150, 1);
mult = Param("mult",2, 1, 4, 0.05);
tr = mult * ATR(per);
trailArray = vstop_func(tr);
//trailArray = Ref(trailArray,-1);

SetChartBkColor( ParamColor("ColorBG", ColorRGB( 0, 0, 0 ) ) );
GraphXSpace = 5;
SetChartOptions(0, chartShowDates);
Plot(IIf(trailArray > C,trailArray,Null),"\ntrailShort",ParamColor("Colo rTrailShort",ColorRGB(255,0,0)),styleStaircase);
Plot(IIf(trailArray < C,trailArray,Null),"\ntrailLong",ParamColor("Color TrailLong",ColorRGB(0,255,0)),styleStaircase);
Plot( C, "\nCandle",colorWhite, styleCandle );
Reply With Quote
  #9  
Old 27th March 2011, 11:05 PM
rpc rpc is offline
Member
 
Join Date: Aug 2005
Posts: 476
Thanks: 166
Thanked 35 Times in 24 Posts
rpc will become famous soon enough
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

@Ayurveda
add follo 3 lines at the end of code

Buy = Cross(C,trailarray);
Sell = Cross(trailarray,C);
PlotShapes(Buy*shapeUpTriangle+Sell*shapeDownTrian gle,IIf(Buy,colorBlue,colorYellow),0,IIf(Buy,L,H)) ;
Reply With Quote
The Following User Says Thank You to rpc For This Useful Post:
cbosein (28th March 2011)
  #10  
Old 27th May 2011, 03:45 AM
Member
 
Join Date: May 2011
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
huss1652 is on a distinguished road
Default Re: Volatility Stop Loss /need code from Metasa to Amibroker/

Great formula guys. I tried this with a dual moving average crossover system and I have an issue. The trailing stop at some points is above a buy position. Is anyone good enough to add to this code stating if a buy is generated to reset the stop below the buy signal?

Advertisements

Reply With Quote
Reply

Bookmarks


Advertise Here


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT +5.5. The time now is 01:51 PM.

Indemnity, Disclaimer & Disclosure Notice:
By visiting Traderji.com you automatically indicate that you agree to our Forum Rules, Indemnity, Disclaimer & Disclosure Notice and General Content Disclaimer Notice and indemnify Traderji.com, its associates and related parties of all claims howsoever resulting from the usage of the forum/site.
Disclaimer: Trading or investing in stocks & commodities is a high risk activity. Any action you choose to take in the markets is totally your own responsibility. You are recommended to make appropriate enquiries and seek appropriate advise before sending money, incurring any expenses, acting on recommendations or entering into any commitment in relation to any advertisement published here. Traderji.com does not vouch for any claims made by the advertisers of products and services. Traderji.com will not be held liable for any consequences in the event such claims are not honoured by the advertisers. Traderji.com will not be liable for any, direct or indirect, consequential or incidental damages or loss arising out of the use of any information by anybody mentioned anywhere on this site.
Disclosure: The information in this forum is neither an offer to sell nor solicitation to buy any of the securities mentioned herein. The writers may or may not be trading in the securities mentioned.
All names or products mentioned are trademarks or registered trademarks of their respective owners.
General Content Disclaimer Notice:
In light of our policy of encouraging candid, open exchanges of views and the rapid distribution of information originating from many sources, Traderji.com cannot determine the accuracy or legality of any information that may be uploaded to the forum. Opinions, advice and all other information expressed by participants in discussions are those of the author. You rely on such information at your own risk. You are urged to seek professional advice for specific, individual situations and not rely solely on advice or opinions given in the discussions. Since Traderji.com is an open and free discussion forum, any comments made by members of this forum in their posts reflect their own views and not of the owner or administrator of Traderji.com. Thus the owner/administrator indemnify themselves of all claims whatsoever and will not be liable or responsible for any members comments/views in this forum Traderji.com. Although we constantly delete all irrelevant content and/or SPAM, if you should find any objectionable or offensive posts made by members of this forum which you would like to bring to our notice for removal then please Contact Us.
 


Copyright © www.Traderji.com 2001 - , All rights reserved.

Recommended Websites - www.TradersEdgeIndia.com - www.TradingPicks.com - www.MasterOfTrading.com

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70