Description
This is a simple Moving average cross over stratigy with Wilder Smoothing
It is set to increase/decrease lot size depending on account
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class WildX : Robot
{
[Parameter("Open Day", Group = "When", DefaultValue = DayOfWeek.Sunday)]
public DayOfWeek OD { get; set; }
[Parameter("Close Day", Group = "When", DefaultValue = DayOfWeek.Saturday)]
public DayOfWeek CD { get; set; }
[Parameter("Start Hour", Group = "When", DefaultValue = 5, Step = 1)]
public double SR { get; set; }
[Parameter("Stop Hour", Group = "When", DefaultValue = 15, Step = 1)]
public double SP { get; set; }
[Parameter("Per Account", Group = "What", DefaultValue = 1, MinValue = 1, Step = 1)]
public double Q { get; set; }
[Parameter("Stop Loss ", Group = "What", DefaultValue = 58, Step = 1)]
public int SL { get; set; }
[Parameter("Take Profit", Group = "What", DefaultValue = 78, Step = 1)]
public int TP { get; set; }
[Parameter("Fast Periods", Group = "How", DefaultValue = 7, Step = 1)]
public int FPs { get; set; }
[Parameter("Slow Periods", Group = "How", DefaultValue = 14, Step = 1)]
public int SPs { get; set; }
public DataSeries Source { get; set; }
private MovingAverage fastMa;
private MovingAverage slowMa;
private const string lab = "WildX";
protected override void OnStart()
{
fastMa = Indicators.MovingAverage(Bars.ClosePrices, FPs, MovingAverageType.WilderSmoothing);
slowMa = Indicators.MovingAverage(Bars.HighPrices, SPs, MovingAverageType.WilderSmoothing);
}
protected override void OnBar()
{
var bPP = Positions.Find(lab, SymbolName, TradeType.Buy);
var sPP = Positions.Find(lab, SymbolName, TradeType.Sell);
var cFMa = fastMa.Result.Last(0);
var cSMa = slowMa.Result.Last(0);
var pFMa = fastMa.Result.Last(1);
var pSMa = slowMa.Result.Last(1);
var DAY = Server.Time.DayOfWeek;
var TIMENOW = Server.Time.TimeOfDay.TotalHours;
if (DAY > OD && DAY < CD)
{
if (TIMENOW > SR && TIMENOW < SP)
{
if (pSMa > pFMa && cFMa > cSMa && bPP == null)
{
if (sPP != null)
ClosePosition(sPP);
ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits, lab, SL, TP);
}
else if (pSMa < pFMa && cFMa < cSMa && sPP == null)
{
if (bPP != null)
ClosePosition(bPP);
ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, lab, SL, TP);
}
}
}
}
private double VolumeInUnits
{
get
{
return Symbol.NormalizeVolumeInUnits(Q * Account.Balance, RoundingMode.Down);
}
}
}
}
VEI5S6C4OUNT0
Joined on 06.12.2022
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: WildX.algo
- Rating: 0
- Installs: 569
- Modified: 16/08/2023 01:03