Warning! This section will be deprecated on February 1st 2025. Please move all your Indicators to the cTrader Store catalogue.
Description
This indicator draws Spread on the chart in pips and shows the current spread and min / max.
Spread is the difference between the bid and the ask price of the symbol.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = false, AccessRights = AccessRights.None)]
public class Spread : Indicator
{
[Output("Spread Min", Color = Colors.Red)]
public IndicatorDataSeries SpreadResultMin { get; set; }
[Output("Spread Max", Color = Colors.Blue)]
public IndicatorDataSeries SpreadResultMax { get; set; }
private double maxSpread;
private double minSpread;
private double maxS;
private double minS;
private DateTime mk;
protected override void Initialize()
{
var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
minSpread = spread;
minS = spread;
ChartObjects.DrawText("c", "vk.com/i_fri", StaticPosition.BottomLeft, Colors.Gray);
}
public override void Calculate(int index)
{
var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
DateTime mk2 = MarketSeries.OpenTime[index];
if (spread > maxSpread)
maxSpread = spread;
else if (spread < minSpread)
minSpread = spread;
if (maxS < maxSpread)
maxS = maxSpread;
if (minS > minSpread)
minS = minSpread;
if (mk != mk2)
{
mk = mk2;
maxSpread = spread;
minSpread = spread;
}
SpreadResultMax[index] = maxSpread;
SpreadResultMin[index] = minSpread;
string text = string.Format("Spread {0} Min / Max : {1} / {2}", spread, minS, maxS);
ChartObjects.DrawText("spread", "\t\t" + text, StaticPosition.TopLeft, Colors.White);
}
}
}
andiinet
Joined on 18.02.2016
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Spread Monitor.algo
- Rating: 5
- Installs: 7169
- Modified: 13/10/2021 09:54
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.
Thanks.