0% found this document useful (0 votes)
522 views

Crash Bot Tested

The document describes a Donchian Channel trading bot for a cryptocurrency trading platform. The bot uses Donchian Channels and moving averages to identify entry points for buy and sell orders based on the asset closing above or below the Donchian Channel levels. It contains parameters for configuration of the strategy around timeframes for trading, position sizing, take profits and stop losses.

Uploaded by

Sadiq Bako
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
522 views

Crash Bot Tested

The document describes a Donchian Channel trading bot for a cryptocurrency trading platform. The bot uses Donchian Channels and moving averages to identify entry points for buy and sell orders based on the asset closing above or below the Donchian Channel levels. It contains parameters for configuration of the strategy around timeframes for trading, position sizing, take profits and stop losses.

Uploaded by

Sadiq Bako
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

using System;

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class DonchianChannelBot : Robot
{
private DateTime _startTime;
private DateTime _stopTime;
private int _tradesExecuted = 0;

[Parameter("Start Hour", DefaultValue = 10.0)]


public double StartTime { get; set; }

[Parameter("Stop Hour", DefaultValue = 12.0)]


public double StopTime { get; set; }

[Parameter("Donchian Periods", DefaultValue = 20)]


public int DonchianPeriods { get; set; }

[Parameter("Lot Size", DefaultValue = 0.1)]


public double LotSize { get; set; }

[Parameter("Pips Offset", DefaultValue = 20)]


public double PipsOffset { get; set; }

[Parameter("Take Profit", Group = "Protection", DefaultValue = 1)]


public int TakeProfit { get; set; }

[Parameter("Stop Loss", Group = "Protection", DefaultValue = 0)]


public int StopLoss { get; set; }
[Parameter("Max Trades", DefaultValue = 10)]
public int MaxTrades { get; set; }

public string InstanceName { get; set; }

private DonchianChannel donchianChannel;


private MovingAverage sma;
private int lastBullishIndex = -1;
private int lastBearishIndex = -1;

protected override void OnStart()


{
_startTime = Server.Time.Date.AddHours(StartTime);
_stopTime = Server.Time.Date.AddHours(StopTime);

Print("Start Time {0},", _startTime);


Print("Stop Time {0},", _stopTime);

donchianChannel = Indicators.DonchianChannel(MarketSeries,
DonchianPeriods);
}

protected override void OnBar()


{
if (Trade.IsExecuting)
return;

var currentHours = Server.Time.TimeOfDay.TotalHours;


bool tradeTime = StartTime < StopTime
? currentHours > StartTime && currentHours < StopTime
: currentHours < StopTime || currentHours > StartTime;

if (!tradeTime)
return;

int index = MarketSeries.Close.Count - 1;

if (index < DonchianPeriods + 1|| _tradesExecuted >= MaxTrades)


return;

// Check if previous candle was bullish


bool isPrevCandleBearish = MarketSeries.Open.Last(2) >
MarketSeries.Close.Last(2);
// Check if current candle closes bearish
bool isCurrentCandleBullish = MarketSeries.Close.Last(1) >
MarketSeries.Open.Last(1);
// Check if previous candle was bearish
bool isPrevCandleBullish = MarketSeries.Close.Last(2) >
MarketSeries.Open.Last(2);
// Check if current candle closes bullish
bool isCurrentCandleBearish = MarketSeries.Close.Last(1) <
MarketSeries.Open.Last(1);

int prevIndex = index - 1;

for (int i = prevIndex; i >= 0; i--)


{
if (MarketSeries.Close[i] < donchianChannel.Middle[i] ||
MarketSeries.Close[i] < donchianChannel.Bottom[i])
{
lastBearishIndex = i;
break;
}
else if (MarketSeries.Close[i] > donchianChannel.Middle[i] ||
MarketSeries.Close[i] > donchianChannel.Top[i])
{
lastBullishIndex = i;
break;
}
}

if (Positions.Count <= 0 && lastBearishIndex != -1 &&


isPrevCandleBearish && isCurrentCandleBullish && MarketSeries.Close.Last(1) >
MarketSeries.Close[lastBearishIndex])
{
Print("Conditions met for Sell Order!");

long volume = Symbol.QuantityToVolume(LotSize);


double entryPrice = Symbol.Ask + PipsOffset * Symbol.PipSize;
DateTime expiration = Server.Time.AddMinutes(55);
PlaceStopOrder(TradeType.Buy, Symbol, volume, entryPrice,
InstanceName, StopLoss, TakeProfit, expiration);
lastBullishIndex = -1; // Reset lastBullishIndex after placing the
sell order
_tradesExecuted++; // Increment trades executed
}

}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy