Not able to increase the volume by the amount by some factor
Created at 06 Jan 2023, 17:55
AS
Not able to increase the volume by the amount by some factor
06 Jan 2023, 17:55
I'm trying to multiply the Volume for next trade by dividing the factor obtained by ratio of last net loss and a user defined value. But it doesn't seem to increase the volume it just uses the _mult value as 1 always. Can someone provide me the alternative code or any solution.
[Parameter("Average Trade Price (amt)", Group = "Volume", DefaultValue = 2, MinValue = 0.01, Step = 0.01)]
public double Invest {get;set;}
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.01, MinValue = 0.01, Step = 0.01)]
public double Quantity {get;set;}
private double _mult=1;
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed;
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
var position = args.Position;
if (position.NetProfit < 0)
{
_mult = Math.Abs((position.NetProfit)/Invest);
}
else
{
_mult = 1;
}
}
protected override void OnTick()
{
var volumeInUnits = (Symbol.QuantityToVolumeInUnits(Math.Round((Quantity*_mult), 2,
MidpointRounding.AwayFromZero)));
ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, "Long",SL,TP);
}
firemyst
09 Jan 2023, 03:47
RE:
ashish.sah.np said:
First question: is
ever true?
Eg, have any of the positions ever had a NetProfit in the code? If so, how do you know? I don't see any logging, and don't know if you've run it with VS to have a breakpoint there to see.
@firemyst