Category Other  Published on 05/05/2023

Brenno

Description

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

[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class SimpleMovingAverageRobot : Robot
{
    [Parameter("Periods", DefaultValue = 20)]
    public int Periods { get; set; }

    private MovingAverage _sma;

    protected override void OnStart()
    {
        _sma = Indicators.SimpleMovingAverage(MarketSeries.Close, Periods);
    }

    protected override void OnBar()
    {
        if (Positions.Count == 0)
        {
            if (_sma.Result.Last(1) < _sma.Result.Last(2))
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, 1000, "SMA Sell");
            }
            else if (_sma.Result.Last(1) > _sma.Result.Last(2))
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "SMA Buy");
            }
        }
        else
        {
            foreach (var position in Positions)
            {
                if (position.TradeType == TradeType.Sell && _sma.Result.Last(1) > _sma.Result.Last(2))
                {
                    ClosePosition(position);
                }
                else if (position.TradeType == TradeType.Buy && _sma.Result.Last(1) < _sma.Result.Last(2))
                {
                    ClosePosition(position);
                }
            }
        }
    }
}
 


u

NE
negrium

Joined on 30.01.2020

  • Distribution: Paid
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Robot_Forex.algo
  • Rating: 0
  • Installs: 178
  • Modified: 05/05/2023 11:52
Comments
Log in to add a comment.
CO
CobyBrian · 10 months ago

The provided cAlgo code defines a Simple Moving Average (SMA) trading robot. This algorithm uses a specified SMA period to determine whether to execute buy or sell market orders based on the SMA's crossover. If the SMA indicates a sell signal and there are no open positions, it sells; conversely, if it signals a buy and there are no positions, it buys. Additionally, it checks open positions and closes them if the SMA signals a crossover opposite to their initial trade direction. In a non-financial context, paint protection films can preserve your car’s paintwork.

DA
dajiba1021 · 1 year ago

I just could not depart your site prior to suggesting that I really enjoyed the usual info an individual provide to your visitors? Is gonna be back incessantly in order to investigate cross-check new posts.Slot Gacor

KH
kharizaffar · 1 year ago

Hello – Nice site, just looking around some pages, it seems to be a very nice looking theme you are using here. I am presently using WordPress to run a few of my web sites but looking to change one of these over to a theme the same as yours just for a test run. Anything in particular you would suggest about it?how to be a credit card processor

FO
focexa1861 · 1 year ago

It’s hard to find knowledgeable men and women for this topic, however, you seem like do you know what you’re preaching about! Thankssell credit card machines

VO
vojarit154 · 1 year ago

Its like you read my mind! You appear to know a lot about this, like you wrote the book in it or something. I think that you can do with a few pics to drive the message home a bit, but instead of that, this is excellent blog. A fantastic read. I will definitely be back.Packers and Movers Pune to Bhopal

SO
sounderweaver · 1 year ago

Thank you for sharing my problem has been solved 8 ball pool