Repeat a cycle in my bot
Repeat a cycle in my bot
12 Aug 2022, 12:37
Hi, I need a little help.
This is my bot code.
It executes a market order live depending on the cross of the two SMAs.
Once the TP or SL is reached, the bot should reopen a new live position by double-checking the cross of the two SMAs.
In practice, start from the beginning.
How can I place this order? Anyone help me by editing my code and entering the code to repeat the loop? Many thanks in advance.
CODE:
using System;
using System.Collections.Generic;
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 Cesare_bot : Robot
{
private TradeType Direction = TradeType.Buy;
[Parameter("SMA1 Period" )]
public int PeriodsSma1 { get; set; }
[Parameter("SMA2 Period" )]
public int PeriodsSma2 { get; set; }
[Parameter("SMA Source")]
public DataSeries Source { get; set; }
private SimpleMovingAverage _sma1 { get; set; }
private SimpleMovingAverage _sma2 { get; set; }
protected override void OnStart()
{
_sma1 = Indicators.SimpleMovingAverage(Source, PeriodsSma1);
_sma2 = Indicators.SimpleMovingAverage(Source, PeriodsSma2);
Print("Decimal ", Symbol.Digits);
if (_sma1.Result.LastValue > _sma2.Result.LastValue)
{
Direction = TradeType.Buy;
}
else
{
Direction = TradeType.Sell;
}
ExecuteMarketOrder(Direction, SymbolName, Symbol.QuantityToVolumeInUnits(0.03), "CesareLive", 1.5, 1.5);
}
}
}
PanagiotisCharalampous
12 Aug 2022, 12:54
Hi DAX_scalper,
You don't need to create any loop. What you need to do is
This way your bot will place trades on every cross.
Best Regards,
Panagiotis
Join us on Telegram and Facebook
@PanagiotisCharalampous