Description
Using the Bill Williams Awesome Indicator, Hull MA, and ATR combined with Renko to give good results.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots
{
//Set time zone to Eastern Standard Time Best time to trade
[Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
public class AOBot : Robot
{
//Functions and Parameters
[Parameter("Risk %", DefaultValue = 0.02)]
public double RiskPct { get; set; }
[Parameter("MA Periods", DefaultValue = 200)]
public int MAPeriods { get; set; }
[Parameter("MA Type", DefaultValue = MovingAverageType.Hull)]
public int MAType { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 3)]
public int SL { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 3)]
public int TP { get; set; }
//Create indicator variables
private AverageTrueRange atr;
private MovingAverage ma;
public AwesomeOscillator AO;
protected override void OnStart()
{
//Load indicators on start up EP5-ATR
atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
ma = Indicators.MovingAverage(Bars.MedianPrices, MAPeriods, MovingAverageType.Hull);
AO = Indicators.AwesomeOscillator();
}
protected override void OnTick()
{
// Put your core logic here and Custom Indicators
var Baseline = ma.Result.Last(0);
var lastValue = AO.Result.Last(0);
var prevValue = AO.Result.Last(1);
// Check Entry signal
if (lastValue > prevValue & Symbol.Bid > Baseline)
{
Open(TradeType.Buy, "AO Long");
Close(TradeType.Sell, "AO Short");
}
else if (lastValue < prevValue & Symbol.Bid < Baseline)
{
Open(TradeType.Sell, "AO Short");
Close(TradeType.Buy, "AO Long");
}
}
//Function for opening a new trade
private void Open(TradeType tradeType, string Label)
{
//Calculate trade amount based on ATR
var ATR = atr.Result.Last(0) / Symbol.PipSize;
var TradeAmount = (Account.Equity * RiskPct) / (1.5 * ATR * Symbol.PipValue);
TradeAmount = Symbol.NormalizeVolumeInUnits(TradeAmount, RoundingMode.Down);
ATR = Symbol.NormalizeVolumeInUnits(ATR, RoundingMode.Down);
//Check there's no existing position before entering a trade
var position = Positions.Find(Label, SymbolName);
if (position == null)
{
ExecuteMarketOrder(tradeType, SymbolName, TradeAmount, Label, SL, TP);
}
}
//Function for closing trades
private void Close(TradeType tradeType, string Label)
{
foreach (var position in Positions.FindAll(Label, SymbolName, tradeType))
ClosePosition(position);
}
}
}
EV
evgrinaus
Joined on 13.11.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: AO Bot.algo
- Rating: 0
- Installs: 2673
- Modified: 13/10/2021 09:54
Warning! Running cBots downloaded from this section may lead to financial losses. Use them at your own risk.
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.