Topics
Replies

Andrelein
24 Jul 2024, 06:50 ( Updated at: 24 Jul 2024, 10:44 )

RE: Calculations With Symbol.PipValue

PanagiotisCharalampous said: 

Hi there,

The result of the method is units, which is what you need as an input for all the order methods of the API. There is no reason to convert it to lots and then back to units. But if you need to convert it to Lots, you can use the Symbol.VolumeToQuantity() method.

Best regards,

Panagiotis

 

Thank you very much for this information. It is well appreciated. I will try that function. I also noticed that I was very ignorant regarding the messagebox respond. It actually has an E-05 at the end of the number, which basically means 0,0000912. But for some reason I ignored that fact.

 

When I tried to use the result in form of units, the following error occured:

24/07/2024 07:10:09.957 | → Order OID0 is REJECTED with error "Order volume 54217.50 must be multiple of stepVolume=1000.00."

 

I solved this problem by converting it back and forth with Math.Round()

PosSizeUnits = Math.Round(SLEUR / (Symbol.PipValue * totalPips), 2);
PosSizeLot = Math.Round(Symbol.VolumeInUnitsToQuantity(PosSizeUnits), 2);
PosSizeUnits = Symbol.QuantityToVolumeInUnits(PosSizeLot);

 

But I noticed that depending on the symbol the order volume has to be multiple of different step volumes. The code above will not work for US30 for example.

24/07/2024 09:01:56.395 | → Order OID0 is REJECTED with error "Order volume 4.25 must be multiple of stepVolume=1.00."

 

I decided to solve this problem this way:

if (Symbol.Name != "US30")
{
   PosSizeUnits = Math.Round(SLEUR / (Symbol.PipValue * totalPips), 2);
   PosSizeLot = Math.Round(Symbol.VolumeInUnitsToQuantity(PosSizeUnits), 2);
   PosSizeUnits = Symbol.QuantityToVolumeInUnits(PosSizeLot);
}
else
{
   PosSizeUnits = Math.Round(SLEUR / (Symbol.PipValue * totalPips), 2);
   PosSizeLot = Math.Round(Symbol.VolumeInUnitsToQuantity(PosSizeUnits), 0);
   PosSizeUnits = Symbol.QuantityToVolumeInUnits(PosSizeLot);
}

 

A more clean and universal approach would be nice, but this temporary solution does work.

Best regards


@Andrelein