Trade FOREX with FXCM

  • Award-Winning Platform
  • 24/7 Customer Support
  • Trade Directly on Charts
  • Free $50K Practice Account
Register


Results 1 to 14 of 14
  1. #1
    Lucas Izidoro is offline Member
    Join Date
    Oct 2010
    Posts
    151

    INDICATOR ENTRY/EXIT - Bollinger Bands Strategy

    This strategy seeks to capitalize on overbought and/or oversold market conditions. These conditions are determined by the Bollinger Band indicator’s dynamic support (lower band) and resistance (upper band) lines.

    External Inputs and Default Values: You will be able to change these parameters at any time prior to activating the strategy through the inputs window.

    Bollinger Bands Settings
    Length = 20
    Number of standard deviations up = 2
    Number of standard deviations down = 2

    Lots = default standard lot of the account (1k for micro accounts, 10k for standard accounts)
    Limit = 0
    Stop = 0
    SSL = False
    Port = 25
    Trailing Stop = 0
    Email Alert = False

    Buying logic

    A signal to create an entry order to buy is generated at the lower Bollinger band price when a bar’s close value crosses over the lower Bollinger band.

    Selling Logic

    A signal to create an entry order to sell is generated at the upper Bollinger band price when a bar’s close value crosses under the upper Bollinger band.

    The buying and selling logic are exemplified below. BBandSE denotes a sell entry order, and BBandLE denotes a buy entry order.



    Exit Logic Long
    The strategy will automatically place a stop loss and/or take profit however many pips away from the lower band value entry price as specified by the trader.

    For example:
    If trading the GBP/JPY, and the price of the lower band is 127.089 and the limit value is set to 25 pips, then the take profit would be created at 127.089 + .25 = 127.339

    Trailing Stop
    If a trailing stop is added by the trader, the stop value will be changed dynamically for every bearish market movement.

    Exit Logic Short

    The strategy will automatically place a stop loss and/or take profit however many pips away from the upper band value entry price as specified by the trader.

    For example:
    If trading the GBP/JPY, and the price of the upper band is 134.357 and the limit value is set to 25 pips, then the take profit would be created at 134.357 - .25 = 134.107

    Trailing Stop
    If a trailing stop is added by the trader, the stop value will be changed dynamically for every bearish market movement.

    Code:
    using System;
    using Broker.StrategyLanguage.Function;
    namespace Broker.StrategyLanguage.Strategy
    {
    	public class BollingerBands : BaseStrategyAdvisor
    	{
    		private ISeries<Double> m_bollingerprice;
    		private ISeries<Double> m_testpricelband;
    		private ISeries<Double> m_testpriceuband;
    		private int m_length = 20;
    		private int m_numdevsup = 2;
    		private int m_numdevsdn = 2;
    		private BollingerBand m_bollingerband1;
    		private BollingerBand m_bollingerband2;
    		private bool m_condition1;
    		private SeriesVar<Double> m_lowerband;
    		private SeriesVar<Double> m_higherband;
    		private double m_TP0;
    		private double m_SL0;
    		private double m_TP1;
    		private double m_SL1;
    		private double m_price0, m_price1;
    		private IPriceOrder m_Order0;
    		private IPriceOrder m_Order0_TP;
    		private IPriceOrder m_Order0_SL;
    		private IPriceOrder m_Order1;
    		private IPriceOrder m_Order1_TP;
    		private IPriceOrder m_Order1_SL;
    		private Function.SSLEMail m_SSLEmail;
    		private bool Email_lock = true;
    		public BollingerBands(object ctx) :
    			base(ctx) {}
    		private ISeries<Double> bollingerprice{
    			get { return m_bollingerprice; }
    		}
    		private ISeries<Double> testpricelband{
    			get { return m_testpricelband; }
    		}
    		private ISeries<Double> testpriceuband{
    			get { return m_testpriceuband; }
    		}
    		[Input]
    		public int length{
    			get { return m_length; }
    			set { m_length = value; }
    		}
    		[Input]
    		public int numdevsup{
    			get { return m_numdevsup; }
    			set { m_numdevsup = value; }
    		}
    		[Input]
    		public int numdevsdn{
    			get { return m_numdevsdn; }
    			set { m_numdevsdn = value; }
    		}
    		
    		private int m_Limit = 0;
    		[Input]
    		public int Limit
    		{
    			get{return m_Limit;}
    			set{m_Limit=value;}
    		}
    
    		private int m_Stop = 0;
    		[Input]
    		public int Stop
    		{
    			get{return m_Stop;}
    			set{m_Stop=value;}
    		}
    		
    		private string m_Username = "";
    		[Input]
    		public string Username
    		{
    			get{return m_Username;}
    			set{m_Username=value;}
    		}
    
    		private string m_Password = "";
    		[Input]
    		public string Password
    		{
    			get{return m_Password;}
    			set{m_Password=value;}
    		}
    
    		private string m_Smtp = "";
    		[Input]
    		public string Smtp
    		{
    			get{return m_Smtp;}
    			set{m_Smtp=value;}
    		}
    
    		private string m_From = "";
    		[Input]
    		public string From
    		{
    			get{return m_From;}
    			set{m_From=value;}
    		}
    
    		private string m_To = "";
    		[Input]
    		public string To
    		{
    			get{return m_To;}
    			set{m_To=value;}
    		}
    
    		private bool m_UseSSL = false;
    		[Input]
    		public bool UseSSL
    		{
    			get{return m_UseSSL;}
    			set{m_UseSSL=value;}
    		}
    
    		private int m_Port = 25;
    		[Input]
    		public int Port
    		{
    			get{return m_Port;}
    			set{m_Port=value;}
    		}
    		
    		private int m_TrailingStop = 0;
    		[Input]
    		public int TrailingStop
    		{
    			get{return m_TrailingStop;}
    			set{m_TrailingStop=value;}
    		}
    		
    		private bool m_EmailAlert = false;
    		[Input]
    		public bool EmailAlert
    		{
    			get{return m_EmailAlert;}
    			set{m_EmailAlert=value;}
    		}
    		
    		protected override void Construct(){
    			m_SSLEmail = new Function.SSLEMail(this);
    			m_bollingerband1 = new BollingerBand(this);
    			m_bollingerband2 = new BollingerBand(this);
    			m_lowerband = new SeriesVar<Double>(this);
    			m_higherband = new SeriesVar<Double>(this); 
    			m_Order0 = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandLE", OrderAction.Buy));
    			m_Order0_TP = OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "BBandLE_TP", OrderAction.Sell));
    			m_Order0_SL = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandLE_SL", OrderAction.Sell));
    			m_Order1 = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandSE", OrderAction.SellShort));
    			m_Order1_TP = OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "BBandSE_TP", OrderAction.BuyToCover));
    			m_Order1_SL = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandSE_SL", OrderAction.BuyToCover));
    		}
    		protected override void Initialize(){
    			m_bollingerprice = Bars.Close;
    			m_testpricelband = Bars.Close;
    			m_testpriceuband = Bars.Close;
    			m_bollingerband1.price = bollingerprice;
    			m_bollingerband1.length = new Serie---pression<Int32>(delegate { return length; });
    			m_bollingerband1.numdevs = new Serie---pression<Int32>(delegate { return (-1*numdevsdn); });
    			m_bollingerband2.price = bollingerprice;
    			m_bollingerband2.length = new Serie---pression<Int32>(delegate { return length; });
    			m_bollingerband2.numdevs = new Serie---pression<Int32>(delegate { return numdevsup; });
    			m_condition1 = default(bool);
    			m_lowerband.DefaultValue = 0;
    			m_higherband.DefaultValue = 0;
    			
    			m_SSLEmail.Username = Username;		//Initializing email function
    			m_SSLEmail.Password = Password;
    			m_SSLEmail.SMTP = Smtp;
    			m_SSLEmail.From = From;
    			m_SSLEmail.To = To;
    			m_SSLEmail.UseSSL = UseSSL;
    			m_SSLEmail.Port = Port;
    		}
    		protected override void Destroy() {}
    		protected override void Execute() {
    			if(Bars.Status == BarStatus.Close)
    				Email_lock = true;
    			
    			CheckTrailingStop();
    			CheckExitLogic();
    			
    			m_lowerband.Value = m_bollingerband1[0];
    
    			m_condition1 = (Functions.DoubleGreater(Bars.CurrentBar, 1) &&
    							Functions.CrossesOver(this, testpricelband, m_lowerband));
    			if (m_condition1){
    				m_price0 = m_lowerband.Value;
    				if(Limit > 0) m_TP0 = m_price0 + Limit * Point;	else m_TP0 = 0;
    				if(Stop > 0) m_SL0 = m_price0 - Stop * Point;	else m_SL0 = 0;
    				if(m_EmailAlert == true && Email_lock == true) {
    					m_SSLEmail.Subject = "Order0";
    					m_SSLEmail.Message = "Order0 is traded at Price " + m_price0;
    					m_SSLEmail.Call();
    					Email_lock = false;
    				}
    				m_Order0.Generate(m_price0);
    			}
    			m_higherband.Value = m_bollingerband2[0];
    			m_condition1 = (Functions.DoubleGreater(Bars.CurrentBar, 1) &&
    							Functions.CrossesUnder(this, testpriceuband, m_higherband));
    			if (m_condition1){
    				m_price1 = m_higherband.Value;
    				if(Limit > 0) m_TP1 = m_price1 - Limit * Point;	else m_TP1 = 0;
    				if(Stop > 0) m_SL1 = m_price1 + Stop * Point;	else m_SL1 = 0;
    				if(m_EmailAlert == true && Email_lock == true) {
    					m_SSLEmail.Subject = "Order1";
    					m_SSLEmail.Message = "Order1 is traded at Price " + m_price1;
    					m_SSLEmail.Call();
    					Email_lock = false;
    				}
    				m_Order1.Generate(m_price1);
    			}
    		}
    		
    		private void CheckExitLogic() {
    			if(StrategyInfo.MarketPosition == 0) return;
    			if(StrategyInfo.MarketPosition > 0) {
    				if(m_TP0 > 0)
    					m_Order0_TP.Generate(m_TP0);
    				if(m_SL0 > 0)
    					m_Order0_SL.Generate(m_SL0);
    			}
    			if(StrategyInfo.MarketPosition < 0) {
    				if(m_TP1 > 0)
    					m_Order1_TP.Generate(m_TP1);
    				if(m_SL1 > 0)
    					m_Order1_SL.Generate(m_SL1);
    			}
    		}
    		
    		private void CheckTrailingStop() {
    			if(m_TrailingStop == 0) return;
    			if(StrategyInfo.MarketPosition > 0) {
    				if(m_SL0 >0 && (Bars.Close[0] - m_SL0) > (Stop + m_TrailingStop) * Point)
    					m_SL0 = Bars.Close[0] - Stop * Point;
    			}
    			if(StrategyInfo.MarketPosition < 0) {
    				if(m_SL1 > 0 && (m_SL1 - Bars.Close[0]) > (Stop + m_TrailingStop) * Point)
    					m_SL1 = Bars.Close[0] + Stop * Point;
    			}
    		}
    		
    		private double Point    //Returns the point value
    		{
    			get{
    				if(Bars.Point < 0.01)
    				{
    					return(Bars.Point * 10);
    				}
    				else                        
    				{
    					return Bars.Point;
    				}
    			}
    		}
    	}
    }
    รูปขนาดเล็ก รูปขนาดเล็ก INDICATOR ENTRY/EXIT - Bollinger Bands Strategy-bollingerbands.jpg  

    ไฟล์แนบข้อความ ไฟล์แนบข้อความ
    Last edited by Lucas Izidoro; 12-08-2010 at 02:04 PM.

  2. #2
    Cool66 is offline Member
    Join Date
    Nov 2009
    Posts
    16
    Blog Entries
    1

    Unhappy Custom Strategy Advisor

    After importing and compiling Custom Strategy advisor the following error message appears;

    "The type or namespace name 'SSLEMail' does not exist in the namespace 'Broker.StrategyLanguage.Function' (are you missing an assembly reference?) "CustomStrategy" [Strategy] Ln 18"

    Any advice on this issue?

    Thanks

    Sorry, but I have just found your earlier post to download the SSLEmail file
    Last edited by Cool66; 11-08-2010 at 08:42 PM.

  3. #3
    Lucas Izidoro is offline Member
    Join Date
    Oct 2010
    Posts
    151
    I'm glad you were able to find the function.

    For user convenience, I have included the SSLEMail Function within the fxd file attached. I will do the same for future strategies that are posted.
    Last edited by Lucas Izidoro; 11-09-2010 at 09:51 AM.

  4. #4
    Gustavo FX is offline Member
    Join Date
    Jul 2010
    Posts
    18

    bollinger bands

    Hello Lukas is possible to enter a not integer standar deviations number ??
    as example 2.5?
    Regards
    Gustavo


    Quote Originally Posted by Lucas Izidoro View Post
    This strategy seeks to capitalize on overbought and/or oversold market conditions. These conditions are determined by the Bollinger Band indicator’s dynamic support (lower band) and resistance (upper band) lines.

    External Inputs and Default Values: You will be able to change these parameters at any time prior to activating the strategy through the inputs window.

    Bollinger Bands Settings
    Length = 20
    Number of standard deviations up = 2
    Number of standard deviations down = 2

    Lots = default standard lot of the account (1k for micro accounts, 10k for standard accounts)
    Limit = 0
    Stop = 0
    SSL = False
    Port = 25
    Trailing Stop = 0
    Email Alert = False

    Buying logic

    A signal to create an entry order to buy is generated at the lower Bollinger band price when a bar’s close value crosses over the lower Bollinger band.

    Selling Logic

    A signal to create an entry order to sell is generated at the upper Bollinger band price when a bar’s close value crosses under the upper Bollinger band.

    The buying and selling logic are exemplified below. BBandSE denotes a sell entry order, and BBandLE denotes a buy entry order.



    Exit Logic Long
    The strategy will automatically place a stop loss and/or take profit however many pips away from the lower band value entry price as specified by the trader.

    For example:
    If trading the GBP/JPY, and the price of the lower band is 127.089 and the limit value is set to 25 pips, then the take profit would be created at 127.089 + .25 = 127.339

    Trailing Stop
    If a trailing stop is added by the trader, the stop value will be changed dynamically for every bearish market movement.

    Exit Logic Short

    The strategy will automatically place a stop loss and/or take profit however many pips away from the upper band value entry price as specified by the trader.

    For example:
    If trading the GBP/JPY, and the price of the upper band is 134.357 and the limit value is set to 25 pips, then the take profit would be created at 134.357 - .25 = 134.107

    Trailing Stop
    If a trailing stop is added by the trader, the stop value will be changed dynamically for every bearish market movement.

    Code:
    using System;
    using Broker.StrategyLanguage.Function;
    namespace Broker.StrategyLanguage.Strategy
    {
    	public class BollingerBands : BaseStrategyAdvisor
    	{
    		private ISeries<Double> m_bollingerprice;
    		private ISeries<Double> m_testpricelband;
    		private ISeries<Double> m_testpriceuband;
    		private int m_length = 20;
    		private int m_numdevsup = 2;
    		private int m_numdevsdn = 2;
    		private BollingerBand m_bollingerband1;
    		private BollingerBand m_bollingerband2;
    		private bool m_condition1;
    		private SeriesVar<Double> m_lowerband;
    		private SeriesVar<Double> m_higherband;
    		private double m_TP0;
    		private double m_SL0;
    		private double m_TP1;
    		private double m_SL1;
    		private double m_price0, m_price1;
    		private IPriceOrder m_Order0;
    		private IPriceOrder m_Order0_TP;
    		private IPriceOrder m_Order0_SL;
    		private IPriceOrder m_Order1;
    		private IPriceOrder m_Order1_TP;
    		private IPriceOrder m_Order1_SL;
    		private Function.SSLEMail m_SSLEmail;
    		private bool Email_lock = true;
    		public BollingerBands(object ctx) :
    			base(ctx) {}
    		private ISeries<Double> bollingerprice{
    			get { return m_bollingerprice; }
    		}
    		private ISeries<Double> testpricelband{
    			get { return m_testpricelband; }
    		}
    		private ISeries<Double> testpriceuband{
    			get { return m_testpriceuband; }
    		}
    		[Input]
    		public int length{
    			get { return m_length; }
    			set { m_length = value; }
    		}
    		[Input]
    		public int numdevsup{
    			get { return m_numdevsup; }
    			set { m_numdevsup = value; }
    		}
    		[Input]
    		public int numdevsdn{
    			get { return m_numdevsdn; }
    			set { m_numdevsdn = value; }
    		}
    		
    		private int m_Limit = 0;
    		[Input]
    		public int Limit
    		{
    			get{return m_Limit;}
    			set{m_Limit=value;}
    		}
    
    		private int m_Stop = 0;
    		[Input]
    		public int Stop
    		{
    			get{return m_Stop;}
    			set{m_Stop=value;}
    		}
    		
    		private string m_Username = "";
    		[Input]
    		public string Username
    		{
    			get{return m_Username;}
    			set{m_Username=value;}
    		}
    
    		private string m_Password = "";
    		[Input]
    		public string Password
    		{
    			get{return m_Password;}
    			set{m_Password=value;}
    		}
    
    		private string m_Smtp = "";
    		[Input]
    		public string Smtp
    		{
    			get{return m_Smtp;}
    			set{m_Smtp=value;}
    		}
    
    		private string m_From = "";
    		[Input]
    		public string From
    		{
    			get{return m_From;}
    			set{m_From=value;}
    		}
    
    		private string m_To = "";
    		[Input]
    		public string To
    		{
    			get{return m_To;}
    			set{m_To=value;}
    		}
    
    		private bool m_UseSSL = false;
    		[Input]
    		public bool UseSSL
    		{
    			get{return m_UseSSL;}
    			set{m_UseSSL=value;}
    		}
    
    		private int m_Port = 25;
    		[Input]
    		public int Port
    		{
    			get{return m_Port;}
    			set{m_Port=value;}
    		}
    		
    		private int m_TrailingStop = 0;
    		[Input]
    		public int TrailingStop
    		{
    			get{return m_TrailingStop;}
    			set{m_TrailingStop=value;}
    		}
    		
    		private bool m_EmailAlert = false;
    		[Input]
    		public bool EmailAlert
    		{
    			get{return m_EmailAlert;}
    			set{m_EmailAlert=value;}
    		}
    		
    		protected override void Construct(){
    			m_SSLEmail = new Function.SSLEMail(this);
    			m_bollingerband1 = new BollingerBand(this);
    			m_bollingerband2 = new BollingerBand(this);
    			m_lowerband = new SeriesVar<Double>(this);
    			m_higherband = new SeriesVar<Double>(this); 
    			m_Order0 = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandLE", OrderAction.Buy));
    			m_Order0_TP = OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "BBandLE_TP", OrderAction.Sell));
    			m_Order0_SL = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandLE_SL", OrderAction.Sell));
    			m_Order1 = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandSE", OrderAction.SellShort));
    			m_Order1_TP = OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "BBandSE_TP", OrderAction.BuyToCover));
    			m_Order1_SL = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandSE_SL", OrderAction.BuyToCover));
    		}
    		protected override void Initialize(){
    			m_bollingerprice = Bars.Close;
    			m_testpricelband = Bars.Close;
    			m_testpriceuband = Bars.Close;
    			m_bollingerband1.price = bollingerprice;
    			m_bollingerband1.length = new Serie---pression<Int32>(delegate { return length; });
    			m_bollingerband1.numdevs = new Serie---pression<Int32>(delegate { return (-1*numdevsdn); });
    			m_bollingerband2.price = bollingerprice;
    			m_bollingerband2.length = new Serie---pression<Int32>(delegate { return length; });
    			m_bollingerband2.numdevs = new Serie---pression<Int32>(delegate { return numdevsup; });
    			m_condition1 = default(bool);
    			m_lowerband.DefaultValue = 0;
    			m_higherband.DefaultValue = 0;
    			
    			m_SSLEmail.Username = Username;		//Initializing email function
    			m_SSLEmail.Password = Password;
    			m_SSLEmail.SMTP = Smtp;
    			m_SSLEmail.From = From;
    			m_SSLEmail.To = To;
    			m_SSLEmail.UseSSL = UseSSL;
    			m_SSLEmail.Port = Port;
    		}
    		protected override void Destroy() {}
    		protected override void Execute() {
    			if(Bars.Status == BarStatus.Close)
    				Email_lock = true;
    			
    			CheckTrailingStop();
    			CheckExitLogic();
    			
    			m_lowerband.Value = m_bollingerband1[0];
    
    			m_condition1 = (Functions.DoubleGreater(Bars.CurrentBar, 1) &&
    							Functions.CrossesOver(this, testpricelband, m_lowerband));
    			if (m_condition1){
    				m_price0 = m_lowerband.Value;
    				if(Limit > 0) m_TP0 = m_price0 + Limit * Point;	else m_TP0 = 0;
    				if(Stop > 0) m_SL0 = m_price0 - Stop * Point;	else m_SL0 = 0;
    				if(m_EmailAlert == true && Email_lock == true) {
    					m_SSLEmail.Subject = "Order0";
    					m_SSLEmail.Message = "Order0 is traded at Price " + m_price0;
    					m_SSLEmail.Call();
    					Email_lock = false;
    				}
    				m_Order0.Generate(m_price0);
    			}
    			m_higherband.Value = m_bollingerband2[0];
    			m_condition1 = (Functions.DoubleGreater(Bars.CurrentBar, 1) &&
    							Functions.CrossesUnder(this, testpriceuband, m_higherband));
    			if (m_condition1){
    				m_price1 = m_higherband.Value;
    				if(Limit > 0) m_TP1 = m_price1 - Limit * Point;	else m_TP1 = 0;
    				if(Stop > 0) m_SL1 = m_price1 + Stop * Point;	else m_SL1 = 0;
    				if(m_EmailAlert == true && Email_lock == true) {
    					m_SSLEmail.Subject = "Order1";
    					m_SSLEmail.Message = "Order1 is traded at Price " + m_price1;
    					m_SSLEmail.Call();
    					Email_lock = false;
    				}
    				m_Order1.Generate(m_price1);
    			}
    		}
    		
    		private void CheckExitLogic() {
    			if(StrategyInfo.MarketPosition == 0) return;
    			if(StrategyInfo.MarketPosition > 0) {
    				if(m_TP0 > 0)
    					m_Order0_TP.Generate(m_TP0);
    				if(m_SL0 > 0)
    					m_Order0_SL.Generate(m_SL0);
    			}
    			if(StrategyInfo.MarketPosition < 0) {
    				if(m_TP1 > 0)
    					m_Order1_TP.Generate(m_TP1);
    				if(m_SL1 > 0)
    					m_Order1_SL.Generate(m_SL1);
    			}
    		}
    		
    		private void CheckTrailingStop() {
    			if(m_TrailingStop == 0) return;
    			if(StrategyInfo.MarketPosition > 0) {
    				if(m_SL0 >0 && (Bars.Close[0] - m_SL0) > (Stop + m_TrailingStop) * Point)
    					m_SL0 = Bars.Close[0] - Stop * Point;
    			}
    			if(StrategyInfo.MarketPosition < 0) {
    				if(m_SL1 > 0 && (m_SL1 - Bars.Close[0]) > (Stop + m_TrailingStop) * Point)
    					m_SL1 = Bars.Close[0] + Stop * Point;
    			}
    		}
    		
    		private double Point    //Returns the point value
    		{
    			get{
    				if(Bars.Point < 0.01)
    				{
    					return(Bars.Point * 10);
    				}
    				else                        
    				{
    					return Bars.Point;
    				}
    			}
    		}
    	}
    }

  5. #5
    Cool66 is offline Member
    Join Date
    Nov 2009
    Posts
    16
    Blog Entries
    1

    INDICATOR ENTRY/EXIT - Bollinger Bands Strategy

    The trailing stop input string, when set in the strategy advisor format objects window, does not seem to activate according to the backtest results and chart displayed signals.

    What haven't I done correctly? Do I need to and or what do I need to edit in this strategy in the SLE?

    Note: Is that a "typo" in the strategy description where it states in the Exit Logic Long, trailing stop paragraph. Should that read ... "for every bullish market movement"?

  6. #6
    jdavis is offline FXCM Automated Platform Specialist
    Join Date
    Jan 2010
    Posts
    818
    Quote Originally Posted by Gustavo FX View Post
    Hello Lukas is possible to enter a not integer standar deviations number ??
    as example 2.5?
    Regards
    Gustavo
    Hi Gustavo,
    The attached FXD file contains an indicator, strategy and function that will allow for fractional standard deviations.

    -jd
    ไฟล์แนบข้อความ ไฟล์แนบข้อความ
    API Team

  7. #7
    jdavis is offline FXCM Automated Platform Specialist
    Join Date
    Jan 2010
    Posts
    818
    Quote Originally Posted by Cool66 View Post
    The trailing stop input string, when set in the strategy advisor format objects window, does not seem to activate according to the backtest results and chart displayed signals.

    What haven't I done correctly? Do I need to and or what do I need to edit in this strategy in the SLE?

    Note: Is that a "typo" in the strategy description where it states in the Exit Logic Long, trailing stop paragraph. Should that read ... "for every bullish market movement"?
    This issue with the trailing stop is currently being reviewed by the development team.

    -jd
    API Team

  8. #8
    jamesk is offline Member
    Join Date
    Aug 2010
    Posts
    123
    Before I begin may I say how delighted I am with FXCM's ‘Trading Station’ and ‘Strategy Trader’ – I’ve used many other platforms and brokers, but have stayed with these the longest and see no reason for changing as long as they remain the best. Keep up the good work! I’ve worked with software for more years than most and this is the best ever in my long experience.

    Your Bollinger Band STea (Strategy Advisor/Expert Advisor) is simple and elegant. I like it the best and use it every day to generate signals on a 5minute chart of GBPUSD. I expect it has very broad application, but currently prefer to focus on one currency pair and timescale, whilst watching the FTSE/UK100 closely.

    Your Bollinger Band STea works really well when the price moves sideways in a regular rhythm. However, even small trends mean that quite large negative positions have to be tolerated before a relatively small profit is achieved. The worst case being when the rule has generated an order in one direction and the price ‘walks’ or ‘runs’, the band in the opposite direction. And, a simple Stop Loss is counter-productive.

    Are there any simple changes to your Bollinger Band STea that would improve performance and benefit your clients? I think so. May I suggest a couple of enhancements which backtesting and optimisation would prove or disprove. The beauty of ‘Strategy Trader’ is that you can have an idea and test it thoroughly if you are competent in C#, which sadly I’m not.

    There are two main problems that need addressing:
    1) "When a buy signal is generated", the price generally continues to fall before turning up.
    2) "When a buy signal is generated", the price continues to fall for a very, very long time before turning up (‘riding the bands’).
    And, vice versa, of course. Always, vice versa.

    Solutions:
    1) When a 'buy signal' is generated, the STea should wait (parameter driven), until the price closes above the down trendline generated by FXCM’s indicator ‘Trendlinesautomatic’. This should be an [Input] option ‘Yes/No’ to enable testing and comparison of results.


    2) 'Riding/Running/Walking/whatever the bands' means that we are in a serious trend. Suppose the trend is up: as it started we got a ‘sell’ signal, which is very common and very unfortunate as we usually have to wait a very, very long time before we get a ‘buy’ signal and a huge loss.

    Meanwhile there has been many repeat ‘sell’ signals which have been ignored since we are in a ‘sell’ position. Maybe after two or three such signals (10 to 12 are common), we could reverse our position since we recognise the trend.
    Again, this is only a theory which FXCM-ST would prove or disprove through optimisation.

    Your comments are welcome. Please.

    JamesK

  9. #9
    James Stanley's Avatar
    James Stanley is offline Moderator
    Join Date
    Aug 2010
    Posts
    453
    Quote Originally Posted by jamesk View Post
    Before I begin may I say how delighted I am with FXCM's ‘Trading Station’ and ‘Strategy Trader’ – I’ve used many other platforms and brokers, but have stayed with these the longest and see no reason for changing as long as they remain the best. Keep up the good work! I’ve worked with software for more years than most and this is the best ever in my long experience.

    Your Bollinger Band STea (Strategy Advisor/Expert Advisor) is simple and elegant. I like it the best and use it every day to generate signals on a 5minute chart of GBPUSD. I expect it has very broad application, but currently prefer to focus on one currency pair and timescale, whilst watching the FTSE/UK100 closely.

    Your Bollinger Band STea works really well when the price moves sideways in a regular rhythm. However, even small trends mean that quite large negative positions have to be tolerated before a relatively small profit is achieved. The worst case being when the rule has generated an order in one direction and the price ‘walks’ or ‘runs’, the band in the opposite direction. And, a simple Stop Loss is counter-productive.

    Are there any simple changes to your Bollinger Band STea that would improve performance and benefit your clients? I think so. May I suggest a couple of enhancements which backtesting and optimisation would prove or disprove. The beauty of ‘Strategy Trader’ is that you can have an idea and test it thoroughly if you are competent in C#, which sadly I’m not.

    There are two main problems that need addressing:
    1) "When a buy signal is generated", the price generally continues to fall before turning up.
    2) "When a buy signal is generated", the price continues to fall for a very, very long time before turning up (‘riding the bands’).
    And, vice versa, of course. Always, vice versa.

    Solutions:
    1) When a 'buy signal' is generated, the STea should wait (parameter driven), until the price closes above the down trendline generated by FXCM’s indicator ‘Trendlinesautomatic’. This should be an [Input] option ‘Yes/No’ to enable testing and comparison of results.


    2) 'Riding/Running/Walking/whatever the bands' means that we are in a serious trend. Suppose the trend is up: as it started we got a ‘sell’ signal, which is very common and very unfortunate as we usually have to wait a very, very long time before we get a ‘buy’ signal and a huge loss.

    Meanwhile there has been many repeat ‘sell’ signals which have been ignored since we are in a ‘sell’ position. Maybe after two or three such signals (10 to 12 are common), we could reverse our position since we recognise the trend.
    Again, this is only a theory which FXCM-ST would prove or disprove through optimisation.

    Your comments are welcome. Please.

    JamesK
    Hello James -

    welcome to the forums.

    You can certainly input a request for a modification of this strategy in the 'Coding requests,' thread.


    That way - it will be seen by FXCM programmers and they can assist in getting that code modified/created.

    You can navigate there directly from the link below:

    Strategy Coding Requests - DailyFX Forex Forum | FX Forum
    DailyFX PLUS Trading Course

    FREE for all LIVE FXCM CLIENTS

  10. #10
    bruce9 is offline Member
    Join Date
    Feb 2012
    Posts
    5

    bollinger band

    i found the "bollingerband fractal deviations" avery good strategy for automated trading.I believe that better results can be if instead of buy / sell upon conditions established, respectively, placing orders to buy / sell to passing the bar top / bottom.
    someone can change the strategy by entering these characteristics?
    Thank you.

  11. #11
    wisefxtrader is offline Member
    Join Date
    Sep 2009
    Posts
    13
    Hello !

    I wonder can you replace from moving average to weight moving line in this Bollinger band Indicator and strategy ?

    If so please send me new file I can test it in Strategy Trader.

    Thanks

    Marc

    Quote Originally Posted by Lucas Izidoro View Post
    This strategy seeks to capitalize on overbought and/or oversold market conditions. These conditions are determined by the Bollinger Band indicator’s dynamic support (lower band) and resistance (upper band) lines.

    External Inputs and Default Values: You will be able to change these parameters at any time prior to activating the strategy through the inputs window.

    Bollinger Bands Settings
    Length = 20
    Number of standard deviations up = 2
    Number of standard deviations down = 2

    Lots = default standard lot of the account (1k for micro accounts, 10k for standard accounts)
    Limit = 0
    Stop = 0
    SSL = False
    Port = 25
    Trailing Stop = 0
    Email Alert = False

    Buying logic

    A signal to create an entry order to buy is generated at the lower Bollinger band price when a bar’s close value crosses over the lower Bollinger band.

    Selling Logic

    A signal to create an entry order to sell is generated at the upper Bollinger band price when a bar’s close value crosses under the upper Bollinger band.

    The buying and selling logic are exemplified below. BBandSE denotes a sell entry order, and BBandLE denotes a buy entry order.



    Exit Logic Long
    The strategy will automatically place a stop loss and/or take profit however many pips away from the lower band value entry price as specified by the trader.

    For example:
    If trading the GBP/JPY, and the price of the lower band is 127.089 and the limit value is set to 25 pips, then the take profit would be created at 127.089 + .25 = 127.339

    Trailing Stop
    If a trailing stop is added by the trader, the stop value will be changed dynamically for every bearish market movement.

    Exit Logic Short

    The strategy will automatically place a stop loss and/or take profit however many pips away from the upper band value entry price as specified by the trader.

    For example:
    If trading the GBP/JPY, and the price of the upper band is 134.357 and the limit value is set to 25 pips, then the take profit would be created at 134.357 - .25 = 134.107

    Trailing Stop
    If a trailing stop is added by the trader, the stop value will be changed dynamically for every bearish market movement.

    Code:
    using System;
    using Broker.StrategyLanguage.Function;
    namespace Broker.StrategyLanguage.Strategy
    {
    	public class BollingerBands : BaseStrategyAdvisor
    	{
    		private ISeries<Double> m_bollingerprice;
    		private ISeries<Double> m_testpricelband;
    		private ISeries<Double> m_testpriceuband;
    		private int m_length = 20;
    		private int m_numdevsup = 2;
    		private int m_numdevsdn = 2;
    		private BollingerBand m_bollingerband1;
    		private BollingerBand m_bollingerband2;
    		private bool m_condition1;
    		private SeriesVar<Double> m_lowerband;
    		private SeriesVar<Double> m_higherband;
    		private double m_TP0;
    		private double m_SL0;
    		private double m_TP1;
    		private double m_SL1;
    		private double m_price0, m_price1;
    		private IPriceOrder m_Order0;
    		private IPriceOrder m_Order0_TP;
    		private IPriceOrder m_Order0_SL;
    		private IPriceOrder m_Order1;
    		private IPriceOrder m_Order1_TP;
    		private IPriceOrder m_Order1_SL;
    		private Function.SSLEMail m_SSLEmail;
    		private bool Email_lock = true;
    		public BollingerBands(object ctx) :
    			base(ctx) {}
    		private ISeries<Double> bollingerprice{
    			get { return m_bollingerprice; }
    		}
    		private ISeries<Double> testpricelband{
    			get { return m_testpricelband; }
    		}
    		private ISeries<Double> testpriceuband{
    			get { return m_testpriceuband; }
    		}
    		[Input]
    		public int length{
    			get { return m_length; }
    			set { m_length = value; }
    		}
    		[Input]
    		public int numdevsup{
    			get { return m_numdevsup; }
    			set { m_numdevsup = value; }
    		}
    		[Input]
    		public int numdevsdn{
    			get { return m_numdevsdn; }
    			set { m_numdevsdn = value; }
    		}
    		
    		private int m_Limit = 0;
    		[Input]
    		public int Limit
    		{
    			get{return m_Limit;}
    			set{m_Limit=value;}
    		}
    
    		private int m_Stop = 0;
    		[Input]
    		public int Stop
    		{
    			get{return m_Stop;}
    			set{m_Stop=value;}
    		}
    		
    		private string m_Username = "";
    		[Input]
    		public string Username
    		{
    			get{return m_Username;}
    			set{m_Username=value;}
    		}
    
    		private string m_Password = "";
    		[Input]
    		public string Password
    		{
    			get{return m_Password;}
    			set{m_Password=value;}
    		}
    
    		private string m_Smtp = "";
    		[Input]
    		public string Smtp
    		{
    			get{return m_Smtp;}
    			set{m_Smtp=value;}
    		}
    
    		private string m_From = "";
    		[Input]
    		public string From
    		{
    			get{return m_From;}
    			set{m_From=value;}
    		}
    
    		private string m_To = "";
    		[Input]
    		public string To
    		{
    			get{return m_To;}
    			set{m_To=value;}
    		}
    
    		private bool m_UseSSL = false;
    		[Input]
    		public bool UseSSL
    		{
    			get{return m_UseSSL;}
    			set{m_UseSSL=value;}
    		}
    
    		private int m_Port = 25;
    		[Input]
    		public int Port
    		{
    			get{return m_Port;}
    			set{m_Port=value;}
    		}
    		
    		private int m_TrailingStop = 0;
    		[Input]
    		public int TrailingStop
    		{
    			get{return m_TrailingStop;}
    			set{m_TrailingStop=value;}
    		}
    		
    		private bool m_EmailAlert = false;
    		[Input]
    		public bool EmailAlert
    		{
    			get{return m_EmailAlert;}
    			set{m_EmailAlert=value;}
    		}
    		
    		protected override void Construct(){
    			m_SSLEmail = new Function.SSLEMail(this);
    			m_bollingerband1 = new BollingerBand(this);
    			m_bollingerband2 = new BollingerBand(this);
    			m_lowerband = new SeriesVar<Double>(this);
    			m_higherband = new SeriesVar<Double>(this); 
    			m_Order0 = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandLE", OrderAction.Buy));
    			m_Order0_TP = OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "BBandLE_TP", OrderAction.Sell));
    			m_Order0_SL = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandLE_SL", OrderAction.Sell));
    			m_Order1 = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandSE", OrderAction.SellShort));
    			m_Order1_TP = OrdersFactory.CreateLimit(new OrdersCreateParams(Lots.Default, "BBandSE_TP", OrderAction.BuyToCover));
    			m_Order1_SL = OrdersFactory.CreateStop(new OrdersCreateParams(Lots.Default, "BBandSE_SL", OrderAction.BuyToCover));
    		}
    		protected override void Initialize(){
    			m_bollingerprice = Bars.Close;
    			m_testpricelband = Bars.Close;
    			m_testpriceuband = Bars.Close;
    			m_bollingerband1.price = bollingerprice;
    			m_bollingerband1.length = new Serie---pression<Int32>(delegate { return length; });
    			m_bollingerband1.numdevs = new Serie---pression<Int32>(delegate { return (-1*numdevsdn); });
    			m_bollingerband2.price = bollingerprice;
    			m_bollingerband2.length = new Serie---pression<Int32>(delegate { return length; });
    			m_bollingerband2.numdevs = new Serie---pression<Int32>(delegate { return numdevsup; });
    			m_condition1 = default(bool);
    			m_lowerband.DefaultValue = 0;
    			m_higherband.DefaultValue = 0;
    			
    			m_SSLEmail.Username = Username;		//Initializing email function
    			m_SSLEmail.Password = Password;
    			m_SSLEmail.SMTP = Smtp;
    			m_SSLEmail.From = From;
    			m_SSLEmail.To = To;
    			m_SSLEmail.UseSSL = UseSSL;
    			m_SSLEmail.Port = Port;
    		}
    		protected override void Destroy() {}
    		protected override void Execute() {
    			if(Bars.Status == BarStatus.Close)
    				Email_lock = true;
    			
    			CheckTrailingStop();
    			CheckExitLogic();
    			
    			m_lowerband.Value = m_bollingerband1[0];
    
    			m_condition1 = (Functions.DoubleGreater(Bars.CurrentBar, 1) &&
    							Functions.CrossesOver(this, testpricelband, m_lowerband));
    			if (m_condition1){
    				m_price0 = m_lowerband.Value;
    				if(Limit > 0) m_TP0 = m_price0 + Limit * Point;	else m_TP0 = 0;
    				if(Stop > 0) m_SL0 = m_price0 - Stop * Point;	else m_SL0 = 0;
    				if(m_EmailAlert == true && Email_lock == true) {
    					m_SSLEmail.Subject = "Order0";
    					m_SSLEmail.Message = "Order0 is traded at Price " + m_price0;
    					m_SSLEmail.Call();
    					Email_lock = false;
    				}
    				m_Order0.Generate(m_price0);
    			}
    			m_higherband.Value = m_bollingerband2[0];
    			m_condition1 = (Functions.DoubleGreater(Bars.CurrentBar, 1) &&
    							Functions.CrossesUnder(this, testpriceuband, m_higherband));
    			if (m_condition1){
    				m_price1 = m_higherband.Value;
    				if(Limit > 0) m_TP1 = m_price1 - Limit * Point;	else m_TP1 = 0;
    				if(Stop > 0) m_SL1 = m_price1 + Stop * Point;	else m_SL1 = 0;
    				if(m_EmailAlert == true && Email_lock == true) {
    					m_SSLEmail.Subject = "Order1";
    					m_SSLEmail.Message = "Order1 is traded at Price " + m_price1;
    					m_SSLEmail.Call();
    					Email_lock = false;
    				}
    				m_Order1.Generate(m_price1);
    			}
    		}
    		
    		private void CheckExitLogic() {
    			if(StrategyInfo.MarketPosition == 0) return;
    			if(StrategyInfo.MarketPosition > 0) {
    				if(m_TP0 > 0)
    					m_Order0_TP.Generate(m_TP0);
    				if(m_SL0 > 0)
    					m_Order0_SL.Generate(m_SL0);
    			}
    			if(StrategyInfo.MarketPosition < 0) {
    				if(m_TP1 > 0)
    					m_Order1_TP.Generate(m_TP1);
    				if(m_SL1 > 0)
    					m_Order1_SL.Generate(m_SL1);
    			}
    		}
    		
    		private void CheckTrailingStop() {
    			if(m_TrailingStop == 0) return;
    			if(StrategyInfo.MarketPosition > 0) {
    				if(m_SL0 >0 && (Bars.Close[0] - m_SL0) > (Stop + m_TrailingStop) * Point)
    					m_SL0 = Bars.Close[0] - Stop * Point;
    			}
    			if(StrategyInfo.MarketPosition < 0) {
    				if(m_SL1 > 0 && (m_SL1 - Bars.Close[0]) > (Stop + m_TrailingStop) * Point)
    					m_SL1 = Bars.Close[0] + Stop * Point;
    			}
    		}
    		
    		private double Point    //Returns the point value
    		{
    			get{
    				if(Bars.Point < 0.01)
    				{
    					return(Bars.Point * 10);
    				}
    				else                        
    				{
    					return Bars.Point;
    				}
    			}
    		}
    	}
    }

  12. #12
    jimmylmh is offline FXCM Automated Platform Specialist
    Join Date
    Dec 2010
    Posts
    964
    Hi wisefxtrader,

    As far as I know about this strategy, it is using the built-in BollingerBand function to calculate the bollingerband values, and the built-in BollingerBand function is using Average (simple average) as the computing method. You might want to modify the built-in BollingerBand function code to accomplish this.

    Please try to use WAverage function instead of Average function in the BollingerBand function code. (Replacing "Average" with WAverage)

    If you are not sure how to modify the code, you might want to request for our programming service, please learn more the service at Strategy Trader, Forex Program, Automated Trading | FXCM

    Regards,
    Jimmy

  13. #13
    bruce9 is offline Member
    Join Date
    Feb 2012
    Posts
    5

    create a new bollinger band system

    Can someone help me to build this strategy system?
    INDICATOR ENTRY/EXIT - Bollinger Bands Strategy

    This strategy seeks to capitalize on overbought and/or oversold market conditions. These conditions are determined by the Bollinger Band indicator’s dynamic support (lower band) and resistance (upper band) lines.

    External Inputs and Default Values: You will be able to change these parameters at any time prior to activating the strategy through the inputs window.

    Bollinger Bands Settings
    Length = 8
    Number of standard deviations up = 1
    Number of standard deviations down = 1

    Lots = default standard lot of the account (1k for micro accounts, 10k for standard accounts)
    Limit = 0
    Stop = 0
    SSL = False
    Port = 25
    Trailing Stop = 0
    Email Alert = False

    Buying logic
    A signal to create an stop order at to buy the high of current bar is generated at:
    • Close>open
    • Close<Bollinger bands bottom
    • Open<Bollinger bands bottom

    Selling Logic
    A signal to create an limit order to sell at the low of current bar is generated at :
    • Close<open
    • Close>Bollinger bands top
    • Open>Bollinger bands top

    Exit Logic Long
    The strategy will automatically place a stop loss and/or take profit .

    Exit Logic Short
    The strategy will automatically place a stop loss and/or take profit



    I am especially interested in how to create limit and stop order....

    thank you very much

  14. #14
    val567 is offline Registered User
    Join Date
    Aug 2013
    Posts
    2
    Hey I really like this strategy idea, but I am not a programmer. I don't know what to do with raw posted code like that. Can you compile the code into 1 or 2 of your favorite versions of the strategy as a .lua file and post it here or post it on fxcodebase and post a link to that here so that I can download it and try it out?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.