Error

 MS Support #1 Posted : Friday, July 28, 2017 10:38:22 PM(UTC) Quote Multi-Quote Rank: Advanced MemberGroups: Moderators, Registered, Registered Users, SubscribersJoined: 10/8/2010(UTC)Posts: 1,383Thanks: 29 timesWas thanked: 105 time(s) in 102 post(s) Domenico D'Errico's article, “Detecting Swings”, presented a four trading strategies for swing trading. Below are the MetaStock formulas for these strategies: Strategy 1 (Pivot High-Low): Buy Long formula: Code:``````el:= Ref(H, -1) > Max( H, Ref(H, -2)); es:= Ref(L, -1) < Min( L, Ref(L, -2)); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = 1 and Ref( ltrade <= 0, -1)`````` Sell formula: Code:``````el:= Ref(H, -1) > Max( H, Ref(H, -2)); es:= Ref(L, -1) < Min( L, Ref(L, -2)); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = -1`````` Sell Short formula: Code:``````el:= Ref(H, -1) > Max( H, Ref(H, -2)); es:= Ref(L, -1) < Min( L, Ref(L, -2)); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = 1 and Ref( strade <= 0, -1)`````` Buy to Cover formula: Code:``````el:= Ref(H, -1) > Max( H, Ref(H, -2)); es:= Ref(L, -1) < Min( L, Ref(L, -2)); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = -1`````` Strategy 2 (Bollinger Bands): Buy Long formula: Code:``````el:= Cross( C, BBandBot(C, 20, S, 2)); es:= Cross( BBandTop(C, 20, S, 2), C); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = 1 and Ref( ltrade <= 0, -1)`````` Sell formula: Code:``````el:= Cross( C, BBandBot(C, 20, S, 2)); es:= Cross( BBandTop(C, 20, S, 2), C); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = -1`````` Sell Short formula: Code:``````el:= Cross( C, BBandBot(C, 20, S, 2)); es:= Cross( BBandTop(C, 20, S, 2), C); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = 1 and Ref( strade <= 0, -1)`````` Buy to Cover formula: Code:``````el:= Cross( C, BBandBot(C, 20, S, 2)); es:= Cross( BBandTop(C, 20, S, 2), C); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = -1`````` Strategy 3 (RSI Cross): Buy Long formula: Code:``````el:= Cross( RSI(5), 40); es:= Cross( 60, RSI(5)); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = 1 and Ref( ltrade <= 0, -1)`````` Sell formula: Code:``````el:= Cross( RSI(5), 40); es:= Cross( 60, RSI(5)); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = -1`````` Sell Short formula: Code:``````el:= Cross( RSI(5), 40); es:= Cross( 60, RSI(5)); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = 1 and Ref( strade <= 0, -1)`````` Buy to Cover formula: Code:``````el:= Cross( RSI(5), 40); es:= Cross( 60, RSI(5)); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = -1`````` Strategy 4 (RSI & higher Low / lower High): Buy Long formula: Code:``````el:= RSI(5) < 40 AND L > Ref(L, -1); es:= RSI(5) > 60 AND H < Ref(H, -1); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = 1 and Ref( ltrade <= 0, -1)`````` Sell formula: Code:``````el:= RSI(5) < 40 AND L > Ref(L, -1); es:= RSI(5) > 60 AND H < Ref(H, -1); ltrade:= If(PREV<=0, If(el, 1, 0),If(es OR (BarsSince(PREV<=0)>=4), -1, PREV)); ltrade = -1`````` Sell Short formula: Code:``````el:= RSI(5) < 40 AND L > Ref(L, -1); es:= RSI(5) > 60 AND H < Ref(H, -1); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = 1 and Ref( strade <= 0, -1)`````` Buy to Cover formula: Code:``````el:= RSI(5) < 40 AND L > Ref(L, -1); es:= RSI(5) > 60 AND H < Ref(H, -1); strade:= If(PREV<=0, If(es, 1, 0),If(el OR (BarsSince(PREV<=0)>=4), -1, PREV)); strade = -1``````