Description
This is an indicator for the traders who trades PATI (Price Action Trader Institute) criteria. Plus, position size calculator.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class PATI : Indicator
{
//-----------PARAMETER---------------------------
[Parameter("Initial Account Balance", DefaultValue = 10000)]
public double IAB { get; set; }
[Parameter("Stop Loss Risk (%)", DefaultValue = 0.5)]
public double stopLossRiskPercent { get; set; }
[Parameter(DefaultValue = 0)]
public double AsiaOpen { get; set; }
[Parameter(DefaultValue = 6)]
public double AsiaClose { get; set; }
[Parameter("Position Size Calculator", DefaultValue = 1)]
public bool info { get; set; }
public double pipsrisk;
public double max;
public double min;
protected override void Initialize()
{
}
public override void Calculate(int index)
{
DisplayInfo();
// Max and Min of Previous Day
DateTime today = MarketSeries.OpenTime[index].Date;
DateTime tomorrow = today.AddDays(1);
DateTime aftertomorrow = today.AddDays(2);
DateTime monday = today.AddDays(3);
DateTime tuesday = today.AddDays(4);
double high = MarketSeries.High.LastValue;
double low = MarketSeries.Low.LastValue;
for (int i = MarketSeries.Close.Count - 1; i > 0; i--)
{
if (MarketSeries.OpenTime[i].Date < today)
break;
high = Math.Max(high, MarketSeries.High[i]);
low = Math.Min(low, MarketSeries.Low[i]);
}
ChartObjects.DrawLine("high " + tomorrow, tomorrow, high, aftertomorrow, high, Colors.Cyan, 1, LineStyle.DotsRare);
ChartObjects.DrawLine("low " + tomorrow, tomorrow, low, aftertomorrow, low, Colors.Cyan, 1, LineStyle.DotsRare);
if (today.DayOfWeek == DayOfWeek.Friday)
{
ChartObjects.DrawLine("high " + monday, monday, high, tuesday, high, Colors.Cyan, 1, LineStyle.DotsRare);
ChartObjects.DrawLine("low " + monday, monday, low, tuesday, low, Colors.Cyan, 1, LineStyle.DotsRare);
}
// Max and Min of Asia Session
DateTime asiaopen = MarketSeries.OpenTime[index].Date.AddHours(AsiaOpen);
DateTime asiaclose = MarketSeries.OpenTime[index].Date.AddHours(AsiaClose);
if ((MarketSeries.OpenTime[index].Hour >= AsiaOpen & MarketSeries.OpenTime[index].Hour < AsiaClose) || (MarketSeries.OpenTime[index].Hour == AsiaClose & MarketSeries.OpenTime[index].Minute == 0))
{
if (MarketSeries.OpenTime[index].Hour == AsiaOpen & MarketSeries.OpenTime[index].Minute == 0)
{
max = MarketSeries.High.LastValue;
min = MarketSeries.Low.LastValue;
}
else
{
if (MarketSeries.High.LastValue > max)
max = MarketSeries.High.LastValue;
if (MarketSeries.Low.LastValue < min)
min = MarketSeries.Low.LastValue;
}
}
if (MarketSeries.OpenTime[index].Hour == AsiaClose & MarketSeries.OpenTime[index].Minute == 0)
{
ChartObjects.DrawLine("Max" + max, asiaopen, max, asiaclose, max, Colors.Gray);
ChartObjects.DrawLine("Min" + max, asiaopen, min, asiaclose, min, Colors.Gray);
double range = Math.Round((max - min) / Symbol.PipSize, 2);
string Range = "R= " + string.Format("{0}", range);
ChartObjects.DrawText("Range" + index, Range, index, min, VerticalAlignment.Bottom, HorizontalAlignment.Left, Colors.White);
}
}
// Position Size Calculator
private void DisplayInfo()
{
string price = "" + MarketSeries.Close.LastValue;
ChartObjects.DrawText("Price", price, StaticPosition.TopLeft, Colors.Green);
var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
string text = string.Format("{0}", spread);
ChartObjects.DrawText("Label", "\n" + "Spread:" + "\n" + "SL:", StaticPosition.TopLeft, Colors.White);
if (spread <= 1)
ChartObjects.DrawText("spread", "\n" + "\t" + text, StaticPosition.TopLeft, Colors.Green);
if (spread > 1 & spread <= 3)
ChartObjects.DrawText("spread", "\n" + "\t" + text, StaticPosition.TopLeft, Colors.Yellow);
if (spread > 3)
ChartObjects.DrawText("spread", "\n" + "\t" + text, StaticPosition.TopLeft, Colors.Red);
string pair = MarketSeries.SymbolCode;
if (pair == "EURUSD" || pair == "USDCHF" || pair == "EURGBP")
{
pipsrisk = 8;
}
if (pair == "EURJPY" || pair == "GBPUSD" || pair == "AUDUSD" || pair == "USDJPY" || pair == "USDCAD" || pair == "NZDUSD")
{
pipsrisk = 10;
}
if (pair == "GBPJPY" || pair == "AUDJPY" || pair == "CADJPY")
{
pipsrisk = 12;
}
double costPerPip = (double)((int)(Symbol.PipValue * 10000000)) / 100;
string size = "" + Math.Round((IAB * stopLossRiskPercent / 100) / (pipsrisk * costPerPip), 2);
ChartObjects.DrawText("Pipsrisk", "\n" + "\n" + "\t" + pipsrisk, StaticPosition.TopLeft, Colors.Gray);
if (info == true)
{
ChartObjects.DrawText("Size", "\n" + "\n" + "\n" + "Size:", StaticPosition.TopLeft, Colors.White);
ChartObjects.DrawText("Position Size", "\n" + "\n" + "\n" + "\t" + size, StaticPosition.TopLeft, Colors.Gray);
}
}
}
}
BigDeal
Joined on 03.12.2015
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: PATI.algo
- Rating: 0
- Installs: 3379
- 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.
Hi, Adding individual color change function possible?