Jump to content

Exchange Blog Cryptocurrency Blog


All Pips



EMA cross + Stochastic


rockstar

Recommended Posts

Entry Strategy

1. In the 30 Minute Chart, the Stochastic should be bullish.

(That is, the fast stochastic line should have crossed over the slow line. It does not matter how long ago the crossover took place, it should just be above the slow line and should be going upwards).

2. In the 5 Minute Chart, the Stochastic should be bullish as well.

(Fast stochastic line should have crossed over the slow line and should be moving upwards. It should not be in overbought condition yet, that is, it should not have crossed 80 yet).

3. The 5 Period EMA crossed over the 13 Period EMA from below and moves upwards.

When all three conditions are met, we buy, placing stoploss at the low of the last bar or the bar to the left of the last bar, whichever is lower.

Stochastic Setting is 8,3,4 for this system.

Link to comment
Share on other sites

  • 5 months later...

I attempted to merge a couple strategies together to form this. It compiles, but I receive errors when trying to load the strategy. Keep in mind there may be some extra/unused code in here. Thanks for any help.

using System;
using System.Drawing;
//using Broker.StrategyLanguage.Function;
using Broker.StrategyLanguage.Function.BuiltIn;
using Broker.StrategyLanguage.Indicator;
using Fx2GoCommon;
namespace Broker.StrategyLanguage.Strategy {
public class EMACrossFullStochFilter : BaseStrategyAdvisor {
 public EMACrossFullStochFilter(object _ctx):base(_ctx){}

 //stochastic parameters
    
 private ISeries<Double> m_priceh;
   	private ISeries<Double> m_pricel;
   	private ISeries<Double> m_pricec;

 private ISeries<Double> m_price;

 private int m_fastlength = 4;

	private int m_slowlength = 100;
   	private int m_stochlength = 14;
   	private int m_smoothinglength1 = 3;
   	private int m_smoothinglength2 = 3;
   	private int m_smoothingtype = 1;
   	private double m_oversold = 20;
   	private double m_overbought = 80;

 private double m_shareorposition = 1;

 private double m_Stop_Amount = 110;
 
 private double m_Profit_Target_Amount = 150;

   	private Stochastic m_stochastic1;
 private Function.HeikinAshi HA;

 	private double m_value1;
   	private SeriesVar<Double> m_ofastk;
   	private SeriesVar<Double> m_ofastd;
   	private SeriesVar<Double> m_oslowk;
   	private SeriesVar<Double> m_oslowd;

 private SeriesVar<Double> m_fastema;

 private SeriesVar<Double> m_slowema;

 private XAverage m_average1;

 private XAverage m_average2;

 private AverageFC m_averagefc1;
  
 private AverageFC m_averagefc2;

 private double m_fastavg;
  
 private double m_medavg;

 private bool maabove;

   	private bool mabelow;

	private bool crossesabove;

	private bool crossesbelow;

 private IMarketOrder m_Order1;
     
 private IMarketOrder m_Order2;
  
 private IMarketOrder m_Order3;
     
 private IMarketOrder m_Order4;
     
   	private ISeries<Double> priceh{
       	get { return m_priceh; }
   	}
   	private ISeries<Double> pricel{
       	get { return m_pricel; }
   	}
   	private ISeries<Double> pricec{
       	get { return m_pricec; }
   	}
 private ISeries<Double> price{
      	get { return m_price; }}     
   	public double shareorposition{
      	get { return m_shareorposition; }
      	set { m_shareorposition = value; }
  	}

 //inputs

 [input]
  	public int fastlength{
      	get { return m_fastlength; }
      	set { m_fastlength = value; }
   	}
[input]
  	public int slowlength{
      	get { return m_slowlength; }
      	set { m_slowlength = value; }
   	}
   	[input]
   	public int stochlength{
       	get { return m_stochlength; }
       	set { m_stochlength = value; }
   	}
   	[input]
   	public int smoothinglength1{
       	get { return m_smoothinglength1; }
       	set { m_smoothinglength1 = value; }
   	}
   	[input]
   	public int smoothinglength2{
       	get { return m_smoothinglength2; }
       	set { m_smoothinglength2 = value; }
   	}
   	[input]
   	public int smoothingtype{
       	get { return m_smoothingtype; }
       	set { m_smoothingtype = value; }
   	}
   	[input]
   	public double oversold{
       	get { return m_oversold; }
       	set { m_oversold = value; }
   	}
  
   	[input]
   	public double overbought{
       	get { return m_overbought; }
       	set { m_overbought = value; }
   	}
 [input]
   	public double Stop_Amount{
      	get { return m_Stop_Amount; }
      	set { m_Stop_Amount = value; }
   	}
[input]
   	public double Profit_Target_Amount{
      	get { return m_Profit_Target_Amount; }
      	set { m_Profit_Target_Amount = value; }
   	}

 protected override void Construct() {
  // TODO : create all members here
  m_average1 = new XAverage(this);
  m_average2 = new XAverage(this);
  m_fastema = new SeriesVar<Double>(this);
  m_slowema = new SeriesVar<Double>(this);
  m_stochastic1 = new Stochastic(this);
       	m_ofastk = new SeriesVar<Double>(this);
       	m_ofastd = new SeriesVar<Double>(this);
       	m_oslowk = new SeriesVar<Double>(this);
       	m_oslowd = new SeriesVar<Double>(this);
  m_averagefc1 = new AverageFC(this);
       	m_averagefc2 = new AverageFC(this);
  m_Order1 = OrdersFactory.CreateMarketNextBar(new OrdersCreateParams(Lots.Default, "StochRun-L", OrderAction.Buy));
       	m_Order2 =
          	OrdersFactory.CreateMarketNextBar(new OrdersCreateParams(Lots.Default, "StochRun-S", OrderAction.SellShort));
 	m_Order3 =
          	OrdersFactory.CreateMarketNextBar(new OrdersCreateParams(Lots.Default, "StochRun-LC", OrderAction.Sell));
 	m_Order4 =
          	OrdersFactory.CreateMarketNextBar(new OrdersCreateParams(Lots.Default, "StochRun-SC", OrderAction.BuyToCover));
  }
 protected override void Initialize() {
  // TODO : assign inputs here
  m_average1.price = price;
 	m_average2.price = price;
       	m_average1.length = new Serie---pression<Int32>(delegate { return fastlength; });
       	m_average2.length = new Serie---pression<Int32>(delegate { return slowlength; });
  m_priceh = Bars.High;
       	m_pricel = Bars.Low;
       	m_pricec = Bars.Close;
  m_price = Bars.Close;
       	m_stochastic1.priceh = priceh;
       	m_stochastic1.pricel = pricel;
       	m_stochastic1.pricec = pricec;
       	m_stochastic1.stochlength = new Serie---pression<Int32>(delegate { return stochlength; });
       	m_stochastic1.length1 = new Serie---pression<Int32>(delegate { return smoothinglength1; });
       	m_stochastic1.length2 = new Serie---pression<Int32>(delegate { return smoothinglength2; });
       	m_stochastic1.smoothingtype = new Serie---pression<Int32>(delegate { return smoothingtype; });
       	m_stochastic1.ofastk = m_ofastk;
       	m_stochastic1.ofastd = m_ofastd;
       	m_stochastic1.oslowk = m_oslowk;
       	m_stochastic1.oslowd = m_oslowd;
       	m_value1 = default(double);
       	m_ofastk.DefaultValue = 0;
       	m_ofastd.DefaultValue = 0;
       	m_oslowk.DefaultValue = 0;
       	m_oslowd.DefaultValue = 0;
  m_fastema.DefaultValue = 0;
  m_slowema.DefaultValue = 0;
  crossesabove = false;
  	crossesbelow = false;
  Output.Clear();
 
	if(fastlength > 0 && slowlength > 0){
m_averagefc1.price = price;
m_averagefc1.length = new Serie---pression<Int32>(delegate { return fastlength; });
m_averagefc2.price = price;
m_averagefc2.length = new Serie---pression<Int32>(delegate { return slowlength; });
m_fastavg = 0;
m_medavg = 0;
	}
 }
 protected override void Execute(){
  if(fastlength > 0 && slowlength > 0){
m_fastavg = m_averagefc1[0];
m_medavg = m_averagefc2[0];
maabove = Functions.DoubleGreater(m_fastavg, m_medavg);
mabelow = Functions.DoubleGreater(m_medavg, m_fastavg);
  }
  else{
maabove = true;
mabelow = true;
  }
      	m_value1 = m_stochastic1[0];
	m_fastema.Value = m_average1[0];
      	m_slowema.Value = m_average2[0];
 
      	crossesabove = (((Functions.DoubleGreater(Bars.CurrentBar, 2) && (Functions.CrossesOver(this, m_fastema, m_slowema))
           	&& Functions.DoubleLess(m_oslowk.Value, overbought))));
  if (crossesabove){
              	m_Order1.Generate();}  
       	crossesbelow = (((Functions.DoubleGreater(Bars.CurrentBar, 2) && (Functions.CrossesUnder(this, m_fastema, m_slowema))
           	&& Functions.DoubleGreater(m_oslowk.Value, oversold))));
  if (crossesbelow){
  	m_Order2.Generate();}  
 if ((shareorposition == 1)){
          	CurSpecOrdersMode = SpecOrdersMode.perLot;
      	}
      	else{
          	CurSpecOrdersMode = SpecOrdersMode.perPosition;
      	}
      	if (Functions.DoubleGreater(Profit_Target_Amount, 0)){
          	GenerateProfitTarget(Profit_Target_Amount*Bars.Info.PointValue*10);
      	}
      	if (Functions.DoubleGreater(Stop_Amount, 0)){
          	GenerateStopLoss(Stop_Amount*Bars.Info.PointValue*10);
      	}
 }
}
}

Link to comment
Share on other sites

  • 1 year later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...