NexusFi: Find Your Edge


Home Menu

 





Combining 2 indicators + alert


Discussion in EasyLanguage Programming

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




 
Search this Thread

Combining 2 indicators + alert

  #1 (permalink)
 RDK91 
Antwerp
 
Posts: 455 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 NexusFi?
Exit Strategy
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Futures True Range Report
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
ZombieSqueeze
Platforms and Indicators
 
  #3 (permalink)
 RDK91 
Antwerp
 
Posts: 455 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
  #4 (permalink)
 RDK91 
Antwerp
 
Posts: 455 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
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,431 since Apr 2013
Thanks Given: 481
Thanks Received: 1,623

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
Thanked by:




Last Updated on January 28, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts