Combining 2 indicators + alert - futures io
futures io futures trading



Combining 2 indicators + alert


Discussion in EasyLanguage Programming

Updated
    1. trending_up 624 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Combining 2 indicators + alert

(login for full post details)
  #1 (permalink)
Antwerp
 
 
Posts: 454 since Jun 2016

I am trying to make 2 indicators in to 1 indicator so i can get an alert/drawing when both indicators do what they need to do.

I need an alert when the RSI crosses a certain level (i managed to get this working).
Now i would like to include an MA cross over to this indicator.

So the sell alert would be needed when for example RSI crosses below XX (RSI level) AND fast MA crosses below slow MA.
Or when RSI crosses over XX (RSI level) AND fast MA crosses over slow MA.

As you can see in this screenshot, the modified RSI is working fine and the alerts are showing at the correct crossing.



What i need to include is the MA cross. So far this is the code i got:

 
Code
using System;
using System.Drawing;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
    public class RSICUSTOMAGAINandMAalmost : IndicatorObject
	{
		
        private Function.RSI m_rsi1;

        private VariableSeries<Double> m_myrsi;

        private IPlotObject Plot1;

        private IPlotObject Plot2;

        private IPlotObject Plot3;
		
		private IPlotObject Plot4;
		
		private IPlotObject Plot5;

        public RSICUSTOMAGAINandMAalmost(object ctx) :
            base(ctx){
            overbcolor = Color.Red;
            overscolor = Color.Cyan;
            overbought = 80;
            oversold = 20;
            length = 19;
				
        }
				
	[SameAsSymbol(true)]
    public class Mov_Avg_2_Lines : IndicatorObject
    {
        private AverageFC m_averagefc1;

        private AverageFC m_averagefc2;

        private VariableSeries<Double> m_fastavg;

        private VariableSeries<Double> m_slowavg;

        private IPlotObject Plot1;

        private IPlotObject Plot2;

        public Mov_Avg_2_Lines(object ctx) :
            base(ctx){
            slowlength = 60;
            fastlength = 40;
				
        }
			
		private ISeries<double> price { get; set; }

        [Input]
        public int length { get; set; }

        [Input]
        public double oversold { get; set; }

        [Input]
        public double overbought { get; set; }

        [Input]
        public Color overscolor { get; set; }

        [Input]
        public Color overbcolor { get; set; }
		
		[Input]
        public int fastlength { get; set; }

        [Input]
        public int slowlength { get; set; }

        [Input]
        public int displace { get; set; }

        protected override void Create(){
            m_rsi1 = new Function.RSI(this);
            m_myrsi = new VariableSeries<Double>(this);
            Plot1 =
                AddPlot(new PlotAttributes("RSI", 0, Color.Silver,
                                           Color.Empty, 0, 0, true));
            Plot2 =
                AddPlot(new PlotAttributes("OverBot", 0, Color.Green,
                                           Color.Empty, 0, 0, true));
            Plot3 =
                AddPlot(new PlotAttributes("OverSld", 0, Color.Green,
                                           Color.Empty, 0, 0, true));
			m_averagefc1 = new AverageFC(this);
            m_averagefc2 = new AverageFC(this);
            m_fastavg = new VariableSeries<Double>(this);
            m_slowavg = new VariableSeries<Double>(this);
            Plot4 =
                AddPlot(new PlotAttributes("FastAvg", 0, Color.Yellow,
                                           Color.Empty, 0, 0, true));
            Plot5 =
                AddPlot(new PlotAttributes("SlowAvg", 0, Color.Magenta,
                                           Color.Empty, 0, 0, true));
        }

        protected override void StartCalc(){
            m_rsi1.price = Bars.Close;
            m_rsi1.length = length;
			price = Bars.Close;
            m_averagefc1.price = price;
            m_averagefc1.length = fastlength;
            m_averagefc2.price = price;
            m_averagefc2.length = slowlength;
        }


        protected override void CalcBar(){
            m_myrsi.Value = m_rsi1[0];
			m_fastavg.Value = m_averagefc1[0];
            m_slowavg.Value = m_averagefc2[0];
            Plot1.Set(0, m_myrsi.Value);
            Plot2.Set(0, overbought);
            Plot3.Set(0, oversold);
			Plot4.Set(0, slowlength);
			Plot5.Set(0, fastlength);
            if (this.CrossesOver(m_myrsi, 25)&&(this.CrossesOver(m_averagefc1, m_averagefc2))){
                Alerts.Alert("Indicator indicating BUY");
				IArrowObject arrowData1 = DrwArrow.Create(new ChartPoint(Bars.CurrentBar, BarsOfData(1).Low[1]), false);
				arrowData1.Size = 5;
				arrowData1.Color = Color.White; 
				
            }
            else{
                if (this.CrossesUnder(m_myrsi, 75)&&(this.CrossesUnder(m_averagefc1, m_averagefc2))){
                    Alerts.Alert("Indicator indicating SELL");
					IArrowObject arrowData1 = DrwArrow.Create(new ChartPoint(Bars.CurrentBar, BarsOfData(1).High[1]), true);
					arrowData1.Size = 5;
					arrowData1.Color = Color.White;
                }
            }
        }
    }
}
	}
However as you can see in the screenshot below, the required MA is shown in the indicator window and not at the chart itself. The purple line should be the slow MA and the yellow line should be the fast MA.



Any help would be appreciated.

Since i have almost 0 coding experience i am glad i made it this far, however it would be extremely helpful if someone could explain me that last bit, i know i could get a programmer to do this for me in probably a few minutes, however i would like to understand this code myself so i can make some changes in the future if required.

Thanks in advance!

Reply With Quote

Can you help answer these questions
from other members on futures io?
Can the Magnet Tool Affect Chart Orders In Overcharts Ha …
Platforms and Indicators
Webinar: Finding your own way in trading w/Adam Grimes
The Elite Circle
NT8 indicator to simulate a Funding Evaluation where to …
NinjaTrader
OFA (Order Flow Analytics) Licence
NinjaTrader
Short Interest Ratio indicator?
ThinkOrSwim
 
 
(login for full post details)
  #3 (permalink)
Antwerp
 
 
Posts: 454 since Jun 2016


This is the original code from the modified RSI indicator which gives an alert when the RSI crosses a certain level.

 
Code
using System;
using System.Drawing;

namespace PowerLanguage.Indicator
{
    public class RSICUSTOMAGAIN : IndicatorObject
    {
        private Function.RSI m_rsi1;

        private VariableSeries<Double> m_myrsi;

        private IPlotObject Plot1;

        private IPlotObject Plot2;

        private IPlotObject Plot3;

        public RSICUSTOMAGAIN(object ctx) :
            base(ctx){
            overbcolor = Color.Red;
            overscolor = Color.Cyan;
            overbought = 80;
            oversold = 20;
            length = 19;
        }

        [Input]
        public int length { get; set; }

        [Input]
        public double oversold { get; set; }

        [Input]
        public double overbought { get; set; }

        [Input]
        public Color overscolor { get; set; }

        [Input]
        public Color overbcolor { get; set; }

        protected override void Create(){
            m_rsi1 = new Function.RSI(this);
            m_myrsi = new VariableSeries<Double>(this);
            Plot1 =
                AddPlot(new PlotAttributes("RSI", 0, Color.Silver,
                                           Color.Empty, 0, 0, true));
            Plot2 =
                AddPlot(new PlotAttributes("OverBot", 0, Color.Green,
                                           Color.Empty, 0, 0, true));
            Plot3 =
                AddPlot(new PlotAttributes("OverSld", 0, Color.Green,
                                           Color.Empty, 0, 0, true));
        }

        protected override void StartCalc(){
            m_rsi1.price = Bars.Close;
            m_rsi1.length = length;
        }


        protected override void CalcBar(){
            m_myrsi.Value = m_rsi1[0];
            Plot1.Set(0, m_myrsi.Value);
            Plot2.Set(0, overbought);
            Plot3.Set(0, oversold);
            if (this.CrossesOver(m_myrsi, 25)){
                Alerts.Alert("Indicator indicating BUY");
				IArrowObject arrowData1 = DrwArrow.Create(new ChartPoint(Bars.CurrentBar, BarsOfData(1).Low[1]), false);
				arrowData1.Size = 5;
				arrowData1.Color = Color.White; 
				
            }
            else{
                if (this.CrossesUnder(m_myrsi, 75)){
                    Alerts.Alert("Indicator indicating SELL");
					IArrowObject arrowData1 = DrwArrow.Create(new ChartPoint(Bars.CurrentBar, BarsOfData(1).High[1]), true);
					arrowData1.Size = 5;
					arrowData1.Color = Color.White;
                }
            }
        }
    }
}
So this one is working as i want it to, now i would like to add an MA cross to this (for example for the buy signal fast MA over slow MA), so i get an alert once both indicators are giving a predefined alert so i get just 1 alert/drawing instead of 2.

Reply With Quote
 
(login for full post details)
  #4 (permalink)
Antwerp
 
 
Posts: 454 since Jun 2016

Nobody?

If this isn't possible a way to combine 2 alerts in to one would also be helpful.

So instead of receiving 2 alerts (1 if the RSI crosses over a certain level and 1 when MA crosses), i would like to get just one alert when both conditions are met.

Reply With Quote
 
(login for full post details)
  #5 (permalink)
 
 
Posts: 2,230 since Apr 2013
Thanks: 409 given, 1,471 received

RDK91,

you can not combine alerts from separate studies into just one alert. To achieve that you will have to combine both into one code. The built-in Mov_Avg_Crossover should get you going and you can use parts from it and add them to your code.

Regards,

ABCTG


RDK91 View Post
Nobody?

If this isn't possible a way to combine 2 alerts in to one would also be helpful.

So instead of receiving 2 alerts (1 if the RSI crosses over a certain level and 1 when MA crosses), i would like to get just one alert when both conditions are met.


Follow me on Twitter Reply With Quote
The following user says Thank You to ABCTG for this post:


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Combining 2 indicators + alert


Last Updated on January 28, 2020


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts