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
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
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
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
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
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
Thank you for sharing my problem has been solved 8 ball pool
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.