Description
Derived from "How to Make a Living Trading Foreign Exchange" by Courtney D. Smith
This is a trend following, long term system, so scalpers may leave now.
This robot uses simple indicators to show when it is safe to buy, safe to sell or just stay out of the market
They are:
1. Today's close is less than the 10-day moving average of the close.
2. Today's 10-day moving average is less than the 10-day moving average 10 days ago.
3. Today's close is less than the close of 40 days ago.
Utilizing the NNFX money management of ATR and 2% risk.
Feel free to use it at your own risk.
If anyone has a Ctrader indicator that can show this it would be appreciated.
Learned by watching NNFX Bot on Youtube.
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 EP9-Best time to trade
[Robot(TimeZone = TimeZones.EasternStandardTime, AccessRights = AccessRights.None)]
public class Template : Robot
{
//Create Parameters EP10-Functions and Parameters
[Parameter("Risk %", DefaultValue = 0.02)]
public double RiskPct { get; set; }
//Create indicator variables EP5-ATR
private AverageTrueRange atr;
public string botName;
private MovingAverage hma10;
protected override void OnStart()
{
//Get Name of Bot and Currency pair of current instance EP15-Deploy
botName = GetType().ToString();
botName = botName.Substring(botName.LastIndexOf('.') + 1) + "_" + SymbolName;
//Load indicators on start up EP5-ATR
atr = Indicators.AverageTrueRange(14, MovingAverageType.Exponential);
hma10 = Indicators.MovingAverage(Bars.ClosePrices, 10, MovingAverageType.Hull);
}
protected override void OnTick()
{
// Put your core logic here EP7-MACD and EP8-Custom Indicators
var price = Bars.ClosePrices;
var hmasmall = hma10.Result.Last(0);
var hma10daysago = hma10.Result.Last(10);
var Price40daysago = Bars.ClosePrices.Last(40);
//check for entry signal
if (price.Last(0) < hmasmall & hmasmall < hma10daysago & price.Last(0) < Price40daysago)
Open(TradeType.Buy, "Conqueror");
else if (price.Last(0) > hmasmall & hmasmall > hma10daysago & price.Last(0) > Price40daysago)
Open(TradeType.Sell, "Conqueror");
}
//Function for opening a new trade - EP10-Functions and Parameters
private void Open(TradeType tradeType, string Label)
{
//Calculate trade amount based on ATR - EP6-Money Management
var ATR = Math.Round(atr.Result.Last(0) / Symbol.PipSize, 0);
var TradeAmount = (Account.Equity * RiskPct) / (1.5 * ATR);
// * Symbol.PipValue);
TradeAmount = Symbol.NormalizeVolumeInUnits(TradeAmount, RoundingMode.Down);
//Check there's no existing position before entering a trade
var position = Positions.Find(Label, SymbolName);
//Set trade entry time - EP9-Best time to trade
if (position == null)
// & Server.Time.Hour == 16 & Server.Time.Minute == 29)
ExecuteMarketOrder(tradeType, SymbolName, TradeAmount, Label, 1.5 * ATR, ATR);
}
//Function for closing trades - EP10-Functions and Parameters
private void Close(TradeType tradeType, string Label)
{
foreach (var position in Positions.FindAll(Label, SymbolName, tradeType))
ClosePosition(position);
}
}
}
evgrinaus
Joined on 13.11.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Conqueror.algo
- Rating: 5
- Installs: 2472
- Modified: 13/10/2021 09:54