Category Trend  Published on 08/01/2023

Usain Bot - Day Trader

Description

NEW VERSION THIS BOT: https://ctrader.com/algos/show/4198

The most faster Bot for Day Trader

Indicators in Bot: RSI + ParabolicSAR + OBV
With Trailing Stop

Bot close positions if has been open for more than 2 hour.

Bot open new positions only between 6AM and 7PM (server hour).


using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;


namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SampleRSIRobot : Robot
{
[Parameter("Source")]
public DataSeries Source { get; set; }

[Parameter("Periods", DefaultValue = 14)]
public int Periods { get; set; }

[Parameter("ParabolicSAR Acceleration", DefaultValue = 0.02, MinValue = 0.01, MaxValue = 0.3)]
public double Acceleration { get; set; }

[Parameter("ParabolicSAR Maximum", DefaultValue = 0.2, MinValue = 0.01, MaxValue = 0.3)]
public double Maximum { get; set; }

[Parameter("OBV Periods", DefaultValue = 14)]
public int OBVPeriods { get; set; }

[Parameter("Trailing Stop (pips)", DefaultValue = 10, MinValue = 1)]
public int TrailingStop { get; set; }

[Parameter("Volume", DefaultValue = 1000, MinValue = 1000)]
public int Volume { get; set; }

private RelativeStrengthIndex rsi;
private ParabolicSAR parabolicSAR;
private OnBalanceVolume obv;

protected override void OnStart()

{
rsi = Indicators.RelativeStrengthIndex(Source, Periods);
parabolicSAR = Indicators.ParabolicSAR(Acceleration, Maximum);
obv = Indicators.OnBalanceVolume(Source);
}

protected override void OnTick()
{
var parabolicSARTrend = parabolicSAR.Result.Last(1);

DateTime currentTime = Server.Time;
double currentPrice = Symbol.Bid;
int currentHour = currentTime.Hour;

if (currentHour < 6 || currentHour >= 19)
{
    return;
}

foreach (var position in Positions)
{
    TimeSpan timeSinceOpen = currentTime - position.EntryTime;

    
    // Check if the position has been open for more than 2 hour
if (timeSinceOpen.TotalMinutes > 240)
{
    ClosePosition(position);
    continue;
}

if (position.TradeType == TradeType.Buy)
{
    var trailingStop = position.EntryPrice - Symbol.PipSize * TrailingStop;

    if (position.StopLoss == null || position.StopLoss < trailingStop)
    {
        ModifyPosition(position, trailingStop, position.TakeProfit);
    }
}
else if (position.TradeType == TradeType.Sell)
    {
        var trailingStop = position.EntryPrice + Symbol.PipSize * TrailingStop;

        if (position.StopLoss == null || position.StopLoss > trailingStop)
        {
            ModifyPosition(position, trailingStop,position.TakeProfit);
        }
    }
}
    
    if (rsi.Result.LastValue < 30 && parabolicSAR.Result.LastValue < currentPrice && obv.Result.LastValue > obv.Result.Last(2))
{
Close(TradeType.Sell);
Open(TradeType.Buy);
}
else if (rsi.Result.LastValue > 70 && parabolicSAR.Result.LastValue > currentPrice && obv.Result.LastValue < obv.Result.Last(2))
{
Close(TradeType.Buy);
Open(TradeType.Sell);
}
}
private void Close(TradeType tradeType)
{
    foreach (var position in Positions.FindAll("SampleRSI", SymbolName, tradeType))
ClosePosition(position);
}
private void Open(TradeType tradeType)
{
var position = Positions.Find("SampleRSI", SymbolName, tradeType);
if (position == null)
{
    //Print(StopLoss);
    var result = ExecuteMarketOrder(tradeType, SymbolName, Volume, "SampleRSI", stopLossPips: TrailingStop, takeProfitPips: null);



    if (result.IsSuccessful)
    {
        position = result.Position;
    }
}
}
}
}

WillBS's avatar
WillBS

Joined on 05.08.2021

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Usain Bot.algo
  • Rating: 0
  • Installs: 1404
  • Modified: 08/01/2023 18:15
Comments
Log in to add a comment.
CH
chau.00nguyenvan · 1 year ago

I was impressed by your writing. Your writing is impressive. I want to write like you.메이저카지노  I hope you can read my post and let me know what to modify. My writing is in I would like you to visit my blog. 

TA
tarij82039 · 1 year ago

If you're going to write a brief review of a topic, you should think about the opportunities you can use while choosing great material. And I utilize Essays on E-Commerce for this since I can discover a huge number of databases on any subject there, which is quite helpful for me when I need to prepare a job. Hence, I advise you to try it out if you want to use it frequently and enhance your skills because it will enable you to be better than the competition.

CT
ctid4797769 · 1 year ago

Which markets is it intended for and which timeframe, parameter settings?