An update for this algorithm is currently pending moderation. Please revisit this page shortly to access the algorithm's latest version.
Description
Inspired by: https://www.tradingview.com/script/ECuloL0o-Larry-Williams-Large-Trade-Index-LWTI-Loxx/
Thanks to @YesOrNot for heavly contributing to the indicator.
The source code is integrated in the .algo file.
AI
aintDatCap
Joined on 12.09.2023
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Larry Williams Large Trading Index.algo
- Rating: 5
- Installs: 851
- Modified: 14/09/2023 07:29
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.
AI
@YesOrNot sadly the source code still needs to be reviewed.
Here's the code:
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None)]
public class LarryWilliamsLargeTradingIndex : Indicator
{
[Parameter(DefaultValue = 8)]
public int Period { get; set; }
[Output("BullishValue", LineColor = "Green", IsHistogram = true, Thickness = 2)]
public IndicatorDataSeries BullishValue { get; set; }
[Output("BearishValue", LineColor = "D4FE0000", IsHistogram = true, Thickness = 2)]
public IndicatorDataSeries BearishValue { get; set; }
[Output("Middle", LineColor = "FF737373", Thickness=1, LineStyle = LineStyle.Dots)]
public IndicatorDataSeries Middle { get; set; }
private MovingAverage movingAverage;
private AverageTrueRange averageTrueRange;
protected override void Initialize()
{
//System.Diagnostics.Debugger.Launch();
IndicatorDataSeries ma = CreateDataSeries();
for(int i = 0; i < Bars.ClosePrices.Count; i++)
{
if (i < Period)
ma[i] = Bars.ClosePrices[i];
else
ma[i] = Bars.ClosePrices[i] - Bars.ClosePrices[i - Period];
}
movingAverage = Indicators.SimpleMovingAverage(ma, Period);
averageTrueRange = Indicators.AverageTrueRange(Period, MovingAverageType.Exponential);
}
public override void Calculate(int index)
{
// Calculate value at specified index
//var ma = (Bars.ClosePrices.LastValue - Bars.ClosePrices[index - Period]);
var atr = averageTrueRange.Result[index];
double result = movingAverage.Result[index] / atr * 50;
if (result < 0)
{
BearishValue[index] = result;
BullishValue[index] = double.NaN;
}
else
{
BullishValue[index] = result;
BearishValue[index] = double.NaN;
}
Middle[index] = 0;
}
}
}
YE
Source code ?
Have A Nice day.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo
{
[Indicator(AccessRights = AccessRights.None)]
public class LarryWilliamsLargeTradingIndex : Indicator
{
[Parameter(DefaultValue = 8)]
public int Period { get; set; }
[Parameter(DefaultValue = 8)]
public MovingAverageType MaType { get; set; }
[Output("NoValue", LineColor = "Gray", IsHistogram = false, PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
public IndicatorDataSeries NoValue { get; set; }
[Output("BullishValue", LineColor = "Green", IsHistogram = false, PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
public IndicatorDataSeries BullishValue { get; set; }
[Output("BearishValue", LineColor = "Red", IsHistogram = false, PlotType = PlotType.DiscontinuousLine, Thickness = 2)]
public IndicatorDataSeries BearishValue { get; set; }
[Output("Middle", LineColor = "FF737373", Thickness = 1, LineStyle = LineStyle.Dots)]
public IndicatorDataSeries Middle { get; set; }
private MovingAverage ma1;
private MovingAverage ma2;
private AverageTrueRange averageTrueRange;
private IndicatorDataSeries resMa;
private IndicatorDataSeries atr;
private IndicatorDataSeries sourceMa;
protected override void Initialize()
{
sourceMa = CreateDataSeries();
atr = CreateDataSeries();
resMa = CreateDataSeries();
ma1 = Indicators.MovingAverage(sourceMa, Period, MaType);
averageTrueRange = Indicators.AverageTrueRange(Period, MaType);
}
public override void Calculate(int index)
{
// Level
Middle[index] = 50;
// Source of calculation ma
sourceMa[index] = Bars.ClosePrices.Last(0) - Bars.ClosePrices.Last(Period);
// calculation ATR
atr[index] = averageTrueRange.Result[index];
//LarryWilliams Calculation
resMa[index] = ma1.Result[index] / atr[index] * 50 + 50;
//Output
NoValue[index] = resMa[index];
BearishValue[index] = resMa[index] < 50 ? resMa[index] : double.NaN;
BullishValue[index] = resMa[index] > 50 ? resMa[index] : double.NaN;
// Repaint Calculation UNCOMMENT FOR SEE (The color is make in function of < or > 50, It's juste a coloration of previous)
if (resMa[index] > 50)
{
BullishValue[index] = resMa[index];
if (resMa[index - 1] < 50)
BullishValue[index - 1] = resMa[index - 1];
BearishValue[index] = double.NaN;
}
if (resMa[index] < 50)
{
BearishValue[index] = resMa[index];
if (resMa[index - 1] > 50)
BearishValue[index - 1] = resMa[index - 1];
BullishValue[index] = double.NaN;
}
}
}
}