Hi, my bot opens positions with different volume, but it shouldn't do that. When i for instance select 10 lots per trade, it opens postions with a volume varing from 1 till 10 lots. However in the automate and journal tab volume is not varying, but in the history tab it does. See screenshots below. Any idea how to fix this? This happens with forward testing, and not with backtesting.
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.FullAccess)]
public class NewcBot : Robot
{
[Parameter(DefaultValue = 52)]
public int EnvelopePeriod { get; set; }
[Parameter(DefaultValue = 0.101)]
public double BandDistance { get; set; }
[Parameter("Source")]
public DataSeries Source { get; set; }
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 10, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
[Parameter("Periodpricema", DefaultValue = 2)]
public int Periodsprice { get; set; }
[Parameter("TP", DefaultValue = 2)]
public int TP { get; set; }
[Parameter("SL", DefaultValue = 10000)]
public int SL { get; set; }
private ExponentialMovingAverage emaprice;
private EnvelopeChannels envelopeChannels;
protected override void OnStart()
{
emaprice = Indicators.ExponentialMovingAverage(Source, Periodsprice);
envelopeChannels = Indicators.GetIndicator<EnvelopeChannels>(EnvelopePeriod, BandDistance, MovingAverageType.Simple);
}
protected override void OnBar()
{
var currentPriceMa = emaprice.Result.Last(1);
var previousPriceMa = emaprice.Result.Last(2);
var channelup = envelopeChannels.ChannelUp.Last(1);
var prevchannelup = envelopeChannels.ChannelUp.Last(2);
var channeldown = envelopeChannels.ChannelLow.Last(1);
var prevchanneldown = envelopeChannels.ChannelLow.Last(1);
var longPosition = Positions.Find("Buy", SymbolName, TradeType.Buy);
var shortPosition = Positions.Find("Sell", SymbolName, TradeType.Sell);
{
//Buy Entry
if (prevchannelup > previousPriceMa && channelup < currentPriceMa)
{
if (shortPosition != null)
ClosePosition(shortPosition);
{
if(Positions.Count == 0)
ExecuteMarketOrder(TradeType.Buy, SymbolName, VolumeInUnits,"Buy", SL, TP);
}
}
if(prevchannelup < previousPriceMa && channelup > currentPriceMa && longPosition != null)
ClosePosition(longPosition);
//Sell Entry
else if (prevchanneldown < previousPriceMa && channeldown > currentPriceMa)
{
if (longPosition != null)
ClosePosition(longPosition);
{
if(Positions.Count == 0)
ExecuteMarketOrder(TradeType.Sell, SymbolName, VolumeInUnits, "Sell",SL,TP);
}
}
if (prevchanneldown > previousPriceMa && channeldown < currentPriceMa && shortPosition != null)
ClosePosition(shortPosition);
}
}
private double VolumeInUnits
{
get { return Symbol.QuantityToVolumeInUnits(Quantity); }
}
}
}