NG
Topics
19 Jan 2021, 17:31
903
1
06 Jan 2021, 18:16
1411
12
13 Apr 2020, 11:09
1567
2
22 Feb 2020, 05:44
1913
1
17 Dec 2018, 18:43
1307
2
01 Dec 2018, 18:10
2111
6
22 Nov 2018, 03:11
1629
10
26 Oct 2018, 04:19
1
1281
1
25 Oct 2018, 08:16
1277
1
24 Oct 2018, 13:06
1367
2
Replies
nguyendan81985
26 Oct 2018, 05:20
RE:
matt_graham_92@hotmail.com said:
Does anyone know where I can download a cbot for instance #2 mentioned above.. price close above ema, auto(bot) long, till price close below ema, auto(bot) close long, and then takes the short?
just copy and paste. hihi
@nguyendan81985
nguyendan81985
24 Oct 2018, 13:19
my coding as below, but it is not working.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class CCIROBOT : Robot
{
[Parameter(DefaultValue = 14)]
public int cciPeriod { get; set; }
[Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
private CommodityChannelIndex cci;
private const string name = "CCIROBOT";
protected override void OnStart()
{
cci = Indicators.CommodityChannelIndex(cciPeriod);
}
protected override void OnBar()
{
var longPos = Positions.Find(name, Symbol, TradeType.Buy);
var shortPos = Positions.Find(name, Symbol, TradeType.Sell);
if ((cci.Result.HasCrossedAbove(0.0, 1) && longPos == null))
{
if (shortPos != null)
{
ClosePosition(shortPos);
ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, name);
}
Print("Open Buy");
{
if (cci.Result.HasCrossedBelow(100.0, 1) && longPos != null)
ClosePosition(longPos);
Print("Closed Buy");
}
}
else if ((cci.Result.HasCrossedAbove(0.0, 1) && longPos == null))
{
if (longPos != null)
{
ClosePosition(longPos);
ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, name);
}
Print("Open Sell");
{
if (cci.Result.HasCrossedAbove(-100.0, 1) && shortPos != null)
ClosePosition(longPos);
Print("Closed Sell");
}
}
}
private long VolumeInUnits
{
get { return Symbol.QuantityToVolume(Quantity); }
}
}
}
@nguyendan81985
nguyendan81985
26 Oct 2018, 05:23
RE:
Panagiotis Charalampous said:
hi Panagiotis,
could you give me one example like: the last close price cross above EMA34 then Buy position, and last price cross below EMA34 then Sell position
thanks
@nguyendan81985