Description
EDIT Updated better filtering. Based on the Nightmare , This is more sensible version with some change of trend indication
the defaults I have set are for AUD/USD 5 min
See end of code for sound file mod , Build with net6
using cAlgo.API;
using cAlgo.API.Indicators;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = true, AutoRescale = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
[Cloud ("Macd", "Signal", Opacity = 1, FirstColor = "66FFFF00", SecondColor = "77AA00FF")]
[Cloud ("CX1", "CX2", Opacity = 1, FirstColor = "2200FF00", SecondColor = "33FF0000")]
public class A1T2 : Indicator
{
public DataSeries Source { get; set; }
[Parameter ("X Signal" , DefaultValue = XA.MACD, Group = "X Signal" ) ]
public XA XAX {get;set;}
public enum XA {MACD,MACDCX,CX,OFF}
[Parameter ("Bars" , DefaultValue = BS.ON, Group = "X Signal") ]
public BS BARS {get;set;}
public enum BS {ON,OFF}
[Parameter ("Dots" , DefaultValue = DO.ON, Group = "X Signal") ]
public DO DOTS {get;set;}
public enum DO {ON,OFF}
[Parameter ("Tone" , DefaultValue = TO.ON, Group = "X Signal") ]
public TO TONE {get;set;}
public enum TO {ON,OFF}
[Parameter ("Color Bars" , DefaultValue = CBS.ON, Group = "X Signal") ]
public CBS CBARS {get;set;}
public enum CBS {ON,Filtered,OFF}
[Parameter("P 1",Group = "Moving Average", DefaultValue = 8)]
public int P1 { get; set; }
[Parameter("P 2",Group = "Moving Average", DefaultValue = 32)]
public int P2 { get; set; }
[Parameter("P 3",Group = "Moving Average", DefaultValue = 96)]
public int P3 { get; set; }
[Parameter("CX 1",Group = "Moving Average", DefaultValue = 8)]
public int CX11 { get; set; }
[Parameter("CX 2",Group = "Moving Average", DefaultValue = 32)]
public int CX12 { get; set; }
[Parameter("ATR P 14",Group = "ATR Bands", DefaultValue = 8)]
public int ATRP { get; set; }
[Parameter("Band Width",Group = "ATR Bands", DefaultValue = 30)]
public int BW { get; set; }
[Parameter("ATR Noise 20 / Filtered",Group = "ATR Bands", DefaultValue = 30)]
public int ABX { get; set; }
[Parameter("RSI Periods 14",Group = "RSI", DefaultValue = 8)]
public int RSIP { get; set; }
[Parameter("RSI React 30 = 50 + 30 and 50 - 30, 0 = 50 ",Group = "RSI", DefaultValue = 5)]
public int RR { get; set; }
[Parameter("MACD Long 26" , DefaultValue = 32, Group = "MACD Cloud" )]
public int MDL { get; set; }
[Parameter("MACD Short 12" , DefaultValue = 8, Group = "MACD Cloud" )]
public int MDS { get; set; }
[Parameter("MACD Signal 9" , DefaultValue = 8, Group = "MACD Cloud" )]
public int MDP { get; set; }
[Parameter("MACD Scale" , DefaultValue = 3, Group = "MACD Cloud" )]
public int MD1 { get; set; }
[Parameter("MACD Cloud" , DefaultValue = MACDCloud.Yes, Group = "MACD Cloud" )]
public MACDCloud MACC { get; set; }
public enum MACDCloud {Yes,No}
[Output("MA1U", LineColor = "EE00CC77", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
public IndicatorDataSeries M1U { get; set; }
[Output("MA1D", LineColor = "EEFF7700", PlotType = PlotType.DiscontinuousLine, Thickness = 1)]
public IndicatorDataSeries M1D { get; set; }
[Output("MA2", LineColor = "99AA00FF", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries MA1 { get; set; }
[Output("MA3", LineColor = "66FFFF00", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries MA3 { get; set; }
[Output("CX1", LineColor = "01111111", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Cx1 { get; set; }
[Output("CX2", LineColor = "01111111", PlotType = PlotType.Line, Thickness = 1)]
public IndicatorDataSeries Cx2 { get; set; }
[Output("Up ATR cc" , LineColor = "6600FFBB" , PlotType = PlotType.DiscontinuousLine, Thickness = 1 )]
public IndicatorDataSeries UpATR1 { get; set; }
[Output("Dn ATR ff" , LineColor = "77FF7700" , PlotType = PlotType.DiscontinuousLine, Thickness = 1 )]
public IndicatorDataSeries DnATR1 { get; set; }
[Output("Up ATR 2 ee" , LineColor = "6600FFBB" , PlotType = PlotType.DiscontinuousLine, Thickness = 1 )]
public IndicatorDataSeries UpATR2 { get; set; }
[Output("Dn ATR 2 cc" , LineColor = "77FF7700" , PlotType = PlotType.DiscontinuousLine, Thickness = 1 )]
public IndicatorDataSeries DnATR2 { get; set; }
[Output("Macd" ,LineColor ="11111111")]
public IndicatorDataSeries Macd {get;set;}
[Output("Signal",LineColor ="11111111")]
public IndicatorDataSeries Signal {get;set;}
private MacdCrossOver MACDC;
MovingAverage MA;
MovingAverage X1;
MovingAverage X2;
MovingAverage X3;
MovingAverage CC1;
MovingAverage CC2;
AverageTrueRange ATR;
RelativeStrengthIndex RSI;
protected override void Initialize()
{
MA = Indicators.WellesWilderSmoothing(Bars.ClosePrices,14);
MACDC = Indicators.MacdCrossOver(MDL,MDS,MDP);
X1 = Indicators.MovingAverage(Source, P1, MovingAverageType.WilderSmoothing);
X2 = Indicators.MovingAverage(Source, P2, MovingAverageType.WilderSmoothing);
X3 = Indicators.MovingAverage(Source, P3, MovingAverageType.WilderSmoothing);
CC1 = Indicators.MovingAverage(Source, CX11, MovingAverageType.WilderSmoothing);
CC2 = Indicators.MovingAverage(Source, CX12, MovingAverageType.WilderSmoothing);
ATR = Indicators.AverageTrueRange (ATRP,MovingAverageType.Triangular);
RSI = Indicators.RelativeStrengthIndex (Source,RSIP);
}
public override void Calculate(int index)
{
if (index != Bars.Count - 1)
return;
{
var M1 = X1.Result.Last (1);
var M2 = X2.Result.Last (1);
var M3 = X1.Result.Last (2);
var C1 = CC1.Result.Last (1);
var C2 = CC2.Result.Last (1);
var C3 = CC1.Result.Last (2);
var C4 = CC2.Result.Last (2);
var EE = (Bars.HighPrices.Last(1) - Bars.LowPrices.Last(1)) ;
var EU = Bars.HighPrices[index] + EE*2;
var ED = Bars.LowPrices[index] - EE*2;
var B1 = Bars.ClosePrices.Last(1);
var A10 = ATR.Result.Last(1);
var AU1 = M2 + ((A10/10)*BW);
var AD1 = M2 - ((A10/10)*BW);
var AU2 = M2 + (((A10/10)*BW)*2);
var AD2 = M2 - (((A10/10)*BW)*2);
var A11 = ATR.Result.Last(0)*100000;
var A12 = ATR.Result.Last(1)*100000;
var R11 = RSI.Result.Last(0);
var R12 = RSI.Result.Last(1);
var R1U = 50 + RR;
var R1D = 50 - RR;
var X = MA.Result.Last(1);
var M = MACDC.MACD[index-1] * ((X*MD1)/X)+X;
var S = MACDC.Signal[index-1] * ((X*MD1)/X)+X;
var MACDL1 = MACDC.MACD.Last(0);
var MACDL2 = MACDC.MACD.Last(1);
var Signl1 = MACDC.Signal.Last(0);
var Signl2 = MACDC.Signal.Last(1);
Macd[index-1] = M;
Signal[index-1] = S;
MA1 [index-1] = X2 .Result[index-1];
MA3 [index-1] = X3 .Result[index-1];
Cx1 [index-1] = CC1 .Result[index];
Cx2 [index] = CC2 .Result[index];
DnATR1[index-1] = AD1;
UpATR1[index-1] = AU1;
UpATR2[index-1] = AU2;
DnATR2[index-1] = AD2;
{
if ( M1 > M3 )
M1U[index-1] = X1.Result[index];
if ( M1 < M3 )
M1D[index-1] = X1.Result[index];
if (CBARS==CBS.ON)
{
if ( B1 > M1 )
{
Chart.SetBarFillColor ( index-1 , "0100CC77" );
Chart.SetBarOutlineColor ( index-1 , "CC00CC77" );
}
if ( B1 < M1 )
{
Chart.SetBarFillColor ( index-1 , "01FF7700" );
Chart.SetBarOutlineColor ( index-1 , "DDFF7700" );
}
}
if (CBARS==CBS.Filtered)
{
if ( (B1 > M1) && ( A11 > ABX) )
{
Chart.SetBarFillColor ( index-1 , "0100CC77" );
Chart.SetBarOutlineColor ( index-1 , "CC00CC77" );
}
if ( (B1 < M1) && ( A11 > ABX) )
{
Chart.SetBarFillColor ( index-1 , "01FF7700" );
Chart.SetBarOutlineColor ( index-1 , "DDFF7700" );
}
}
}
if ( (XAX == XA.CX) && (A11>=ABX) && (A11 > A12) )
{
if ( (C1 > C2) && (C3 < C4) && (R11 > R1U) && (R11 > R12) )
{
if (BARS==BS.ON)
{
Chart.SetBarColor ( index-1 , "FF00FF00" );
}
if (DOTS==DO.ON)
{
Chart.DrawIcon ( " Up " + index , ChartIconType.Circle , index-1 , ED , "FF00FF00" );
}
if (TONE==TO.ON)
{
BeginInvokeOnMainThread(() =>
{Notifications.PlaySound(@"C:\Users\maxed\cAlgo Ding\DnDing.mp3");});
}
}
else if ( (C1 < C2) && (C3 > C4) && (R11 < R1D) && (R11 < R12) )
{
if (BARS==BS.ON)
{
Chart.SetBarColor ( index-1 , "FFFF3300" );
}
if (DOTS==DO.ON)
{
Chart.DrawIcon ( " Down " + index , ChartIconType.Circle , index-1 , EU , "FFFF3300" );
}
if (TONE==TO.ON)
{
BeginInvokeOnMainThread(() =>
{Notifications.PlaySound(@"C:\Users\maxed\cAlgo Ding\DnDing.mp3");});
}
}
}
if ( (XAX == XA.MACD) && (A11>=ABX) && (A11 > A12) )
{
if ( (MACDL2 < Signl2) && (MACDL1 > Signl1) && (R11 > R1U) && (R11 > R12) )
{
if (BARS==BS.ON)
{
Chart.SetBarColor ( index-1 , "FF00FF00" );
}
if (DOTS==DO.ON)
{
Chart.DrawIcon ( " Up " + index , ChartIconType.Circle , index-1 , ED , "FF00FF00" );
}
if (TONE==TO.ON)
{
BeginInvokeOnMainThread(() =>
{Notifications.PlaySound(@"C:\Users\maxed\cAlgo Ding\DnDing.mp3");});
}
}
else if ( (MACDL2 > Signl2) && (MACDL1 < Signl1) && (R11 < R1D) && (R11 < R12) )
{
if (BARS==BS.ON)
{
Chart.SetBarColor ( index-1 , "FFFF3300" );
}
if (DOTS==DO.ON)
{
Chart.DrawIcon ( " Down " + index , ChartIconType.Circle , index-1 , EU , "FFFF3300" );
}
if (TONE==TO.ON)
{
BeginInvokeOnMainThread(() =>
{Notifications.PlaySound(@"C:\Users\maxed\cAlgo Ding\DnDing.mp3");});
}
}
}
if ( (XAX == XA.MACDCX) && (A11>=ABX) && (A11 > A12) )
{
if ( (C1 > C2) && (MACDL2 < Signl2) && (MACDL1 > Signl1) && (R11 > R1U) )
{
if (BARS==BS.ON)
{
Chart.SetBarColor ( index-1 , "FF00FF00" );
}
if (DOTS==DO.ON)
{
Chart.DrawIcon ( " Up " + index , ChartIconType.Circle , index-1 , ED , "FF00FF00" );
}
if (TONE==TO.ON)
{
BeginInvokeOnMainThread(() =>
{Notifications.PlaySound(@"C:\Users\maxed\cAlgo Ding\DnDing.mp3");});
}
}
else if ( (C1 < C2) && (MACDL2 > Signl2) && (MACDL1 < Signl1) && (R11 < R1D) )
{
if (BARS==BS.ON)
{
Chart.SetBarColor ( index-1 , "FFFF3300" );
}
if (DOTS==DO.ON)
{
Chart.DrawIcon ( " Down " + index , ChartIconType.Circle , index-1 , EU , "FFFF3300" );
}
if (TONE==TO.ON)
{
BeginInvokeOnMainThread(() =>
{Notifications.PlaySound(@"C:\Users\maxed\cAlgo Ding\DnDing.mp3");});
}
}
} // Use for standard MS tone or make your own sound file eg; Audacity / Generate sine wave....
} // @"C:\Windows\Media\Windows Information Bar.wav"
}
}
}
VE
VEI5S6C4OUNT0
Joined on 06.12.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: A1T2.algo
- Rating: 5
- Installs: 557
- Modified: 13/12/2023 22:23
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
No comments found.