Oanda LotAmount in Trade Mode

Posted By: JayWilly

Oanda LotAmount in Trade Mode - 11/12/21 14:37

Has anyone come across an issue with the LotAmount when trading Index CFDs with Oanda?

Correct me if I am wrong on this as I have been banging my head against the wall for the past couple days trying to figure this out.

There is an issue with how LotAmount and Lots are treated when in Trade mode for Index CFDs with Oanda. There is no issue when trading currencies. The requested AssetList provided by Oanda is correct with all their Index CFDs having LotAmount = 0.1. See included AssetList. The PIPCost reflects CAD currency as I am in Canada.

In Train and Test modes, all the relevant calculated positions sizes and performance values are correct. The problem comes about in Trade mode. Zorro executes the number of Lots, which to Zorro, represents (Lots * LotAmount) number of contracts in position size. So a 5 Lots execution represents 0.5 Index contracts, 5 Lots * 0.1 LotAmount. But to Oanda, the number of Zorro Lots being transacted, 5 in this example, represents (5 / 0.1) = 50 contracts of 0.1 LotAmounts, which is 10 times more than what is intended.

As you can see from a current NAS100 position in the table below pulled from the Zorro HTML Trading Status page, the Risk calculation of -$237 does not make sense for 27 Lots of 0.1 LotAmounts with a Stop distance from Entry to Stop of (16187 – 16257) = -70 PIPS. Using the PIPCost from the AssetList above, the Risk calculation should be -$2,339 ((27/0.1) * 70 * 0.123762), as to Oanda, the 27 Lots is 270 contracts of 0.1 LotAmounts. The Profit calculation of $3,861 in the table makes sense. There is also the CN50 position of 4 Lots listed.


Trade ID Lots Entry Time Entry Price Stop Trail Target Risk Profit Pips
[NAS100/USD:Trend:S00035] 35 27 11/10/2021 01:00 16187 16070 16257 15914 14985 -237$ 3861$ 1149.6p
[CN50/USD:Trend:L00047] 47 4 11/10/2021 08:00 15398 15580 14860 15780 16124 -267$ 922$ 1862.3p



I looked at changing the PIPCost by using SET_PATCH to accommodate the issue but realized that by making this adjustment, there would be unintended consequences of how Zorro calculates position sizes as I use the Risk trade parameter. I could also calculate the adjusted Lot amounts within the script to be sent to Oanda for execution but that defeats the whole purpose of Zorro’s functionality.

Oanda made changes to their Index CFD sizing earlier this year reducing the minimum trade size (LotAmount) from 1 to 0.1, which may not have been adjusted in the Oanda API. This, therefore, could be a bug with the API.

Has anyone experienced this?

I am using Zorro version 2.40.9.

Thanks, Jay

Attached File
AssetsInd.csv  (129 downloads)
Attached File
Posted By: Petra

Re: Oanda LotAmount in Trade Mode - 11/12/21 16:14

If your lot amount is wrong, check with Oanda which lot amount you really have on your account, and enter it in your CSV file. Oanda MT4 and Oanda API can have different lot amounts for the same asset.
Posted By: MatPed

Re: Oanda LotAmount in Trade Mode - 11/13/21 17:03

I have the same issue. I have received no support from Oanda and little from Zorro. I am trying an updated AssetFix, I will share my findings if positive. Ciao
Posted By: Grant

Re: Oanda LotAmount in Trade Mode - 11/13/21 20:43

When this issue only occurs in trade mode, then you can use this condition to calculate a different lot size

Code
if(is(TRADEMODE))
{
Lots = ...;//Lots in trade mode
}
else
{
Lots = ...;//Lots in train or test mode
}


Hope this helps.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 11/14/21 05:19

I will use your suggestion this coming week Grant. Thanks very much.

I have a query out to Oanda support about this as per Petra's suggestion with regards to the issue being account specific settings on Oanda's end. Will report back when hear anything.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 11/30/21 06:14

After multiple conversations, I was finally able to get a firm answer on the issue with Oanda. The minimum trade size for Index CFDs is 0.1 units. The issue is that the Amount variable in Zorro is defined as an integer and this needs to move to being able to handle 1 decimal place. Oanda's v20 API interpretation of Lot = 2 and Amount = 2 are the same whereby the order/trade recognized by Oanda is 20 units of 0.1 Index values. Adjusting the AssetList CSV file for Zorro to recognize the size of 1 lot being 0.1 is not being interpreted the same by Oanda. Sending an order where Lots = 23 is not 2.3 units of the Index contracts, as Zorro currently interprets it with the adjustment in the AssetList CSV file, but it is 230 units of 0.1 Index units. Sending an order with the variable Amount = 2.3 results in the truncation of the decimal place since the Amount variable can only be an Integer, which makes the Amount = 2 and then becoming 20 units of 0.1 with Oanda. Same applies to the Lots variable when equals a decimal value.

As discussed before, when in Training and Testing modes, the calculations are accurate but in Trade mode, the orders are 10 times larger and Oanda does not recognize a Lot size being 0.1.

How can this be accommodated in either the Oanda API or Zorro?
Posted By: Petra

Re: Oanda LotAmount in Trade Mode - 11/30/21 09:46

The Amount variable is no integer. Maybe you confused it with Lots?

If LotAmount is 0.1 then 5 Lots is the same as 0.5 Amount.

Oanda lot sizes and other parameters depend on country and platform, so the included asset list could indeed be not suited for your account. Check your asset parameters with Oanda, then adapt your asset list as described on https://manual.zorro-project.com/account.htm. Do NOT use different lots in test and trade mode, this is a recipe for disaster. If in doubt, we also have an asset list setup service.
Posted By: Grant

Re: Oanda LotAmount in Trade Mode - 11/30/21 14:51

Originally Posted by Petra
Do NOT use different lots in test and trade mode, this is a recipe for disaster.


Oops, my bad.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 12/01/21 05:43

Thanks for the reply Petra.

The Lots variable is indeed an integer.

I agree with your LotAmount example. The only problem is that Oanda recognizes the 5 Lots as 5.0 Amount or 50 x 0.1, which is 10 times more than desired with LotAmount set as 0.1 in the AssetList table as provided in my initial Post above. Editing the AssetList does not matter as any integer value sent as Lots will be 10 times the expected amount. As it currently stands, I have to divide the Lots calculated by Zorro before the order is sent to Oanda by 10 and manage any resulting decimals by rounding up or down while using the suggested code by Grant above to distinguish when in TRADEMODE and TESTMODE for the Risk and Profit calculations to be correct. There will always be a discrepancy between the trade sizes calculated in Train /Test mode versus Trade mode unless I round the calculated amounts in Test/Train mode up to the next highest decimal place to match the behavior of what would happen in Trade mode. As you stated, using different lots in test and trade mode "is a recipe for disaster" but I understand where the issues are and have made accommodations for them.

The better option is to live with the fact that I cannot take advantage of the smaller sizes offered by Oanda and adjust the LotAmount in the AssetList table to 1 rather than 0.1 in order for the Profit and Risk calculations done by Zorro to be consistent in TRADEMODE and TESTMODE, which would match Oanda's calculations. This option would, unfortunately, require a much larger account to trade a diversified portfolio of assets to include most of the CFD Indices since the position sizes would be larger requiring more margin. I would also need to use the SET_PATCH brokerCommand to use my AssetList which should override what Oanda provides as the asset parameters.

The best option would be to edit the Oanda API to accommodate how the Oanda v20 API handles the reduced minimum CFD trade size to one decimal place they implemented earlier this year as this is a global change, not a country change, given one user from Italy had the same experience as mentioned by the user in a previous post.

Please let me know if this make sense and what can be done, if anything, to be able to accommodate the smaller CFD Index minimums offered by Oanda. Thanks.
Posted By: Petra

Re: Oanda LotAmount in Trade Mode - 12/01/21 10:12

If Oanda recognizes the 5 lots as 5 contracts, then the live lot amount was obviously 1, not 0.1. Change it to 1 in the asset list and make sure that the size is then correct in test and trade mode. And check also with Oanda why they told you it was 0.1 when in fact it was 1. Maybe your account was not yet updated to 0.1 or that server returned a wrong value.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 12/01/21 15:08

The server is returning the wrong LotAmount when using the Download script to update the AssetList parameters. What they are returning is the new minimum trade size. We are able to trade the smaller trade size if we can send an order with an amount using 1 decimal place.
Posted By: Petra

Re: Oanda LotAmount in Trade Mode - 12/03/21 13:41

That explains it then, you can use the SET_PATCH command to override the wrong lot amount by the server.
Posted By: MatPed

Re: Oanda LotAmount in Trade Mode - 12/08/21 06:27

I guess that should be stated in the manual that trading CFD with API is really dangerous. I can cofirm that margin requirements is 10 times higher than expected i.e. it's a bomb!

Is anybody trading CFD with MT4 and Oanda?
Posted By: jcl

Re: Oanda LotAmount in Trade Mode - 12/08/21 15:27

We do. That's one of our test configurations. We confirm that all is fine here with the margin. But we will of course add a warning in the manual and notify Oanda about the problem.

However, you should anyway get a warning at strategy start when the margin deviates from the asset list. Did you get it?
Posted By: MatPed

Re: Oanda LotAmount in Trade Mode - 12/08/21 18:07

I tried in real several asset file and I received Lot warnings or picost warnings. Nothing regarding margin.
Trades are 10 times bigger than expected i.e. with only one losing trade you can vaporize your account.
I Have been lucky because my trade was positive and I manually close it.
I imagine what could happen with people trading Zx systems with Oanda...
I wrote to Oanda support, Zorro support and several post on this forum regarding the issue because I guess it should be addressed as priority one.
Posted By: MegaTanker

Re: Oanda LotAmount in Trade Mode - 12/08/21 19:56

Well I guess this explains why Z12 opens such huge index positions. I thought it was just due to the accumulate setting since the account has such low capital. It's actually up now compared to before the recent correction, but the drawdown was pretty nasty since it held a bunch of long index positions as it happened. Definitely could have blown up some accounts with tighter capital though and I'll pause this for now.

The Zorro window prints Long 1 for SPX500, Oanda receives this as one whole SPX500 contract, instead of 1 LotAmount, which is 0.1

Can this not be fixed with an update to the Oanda plugin?
Posted By: Petra

Re: Oanda LotAmount in Trade Mode - 12/08/21 20:42

Are you are using the oanda plugin? I thought it was the mt4 plugin?
Posted By: MegaTanker

Re: Oanda LotAmount in Trade Mode - 12/08/21 21:02

I am using the Oanda plugin directly, yes. No mt4/mt5.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 12/09/21 01:18

I have a question out to their support for a couple days now about the fact that when a request is made about Lot Amount and Pip Cost, it is pushing back the incorrect values as discussed previously based upon the actual execution behavior. I updated the AssetList and using the Set_Patch broker command to use my values for the Lot size as being 1 rather than 0.1 and adjusting the Pip Cost 10 times higher. Will see how that works out. Will report back when I hear something from Oanda.

This is with the Oanda plugin directly. I do not know the behavior for MT4 nor MT5.
Posted By: MegaTanker

Re: Oanda LotAmount in Trade Mode - 12/09/21 08:18

If the issue is with the Zorro Oanda plugin, then their support will be very confused. You mentioned in your first post that Oanda made this change from LotAmount 1 to 0.1 not too long ago, is it possible that this capability simply wasn't updated in the Oanda plugin?
Posted By: jcl

Re: Oanda LotAmount in Trade Mode - 12/09/21 12:45

Oanda cannot update the Oanda plugin, nor would that help with a wrong lot amount. They must update the lot amount in their API.

If it only happens with a direct connection, that would explain why some people have that problem and others not. We'll check if we get also the wrong lot amount here, and will then contact Oanda for solving the problem. Please stay tuned.
Posted By: jcl

Re: Oanda LotAmount in Trade Mode - 12/10/21 09:34

Ok, it seems that the problem is more complicated. The lot amount was in fact correct, but the the order units were changed from lots to contracts. Therefore the too large size,.

Please download a new Oanda plugin here: https://opserver.de/down/Oanda.zip

Please let me know if the problem still happens with that plugin.
Posted By: MatPed

Re: Oanda LotAmount in Trade Mode - 12/12/21 11:00

I will re-start the TS next January and report any issues will arise. Will the new plugin be included in the 2.44 upcoming release. Will it be "compatible" with the new Oanda Asset list just announced with the same version?

Thank you
Posted By: MegaTanker

Re: Oanda LotAmount in Trade Mode - 12/13/21 07:41

Looks good, just saw my script opened 1 Lot which now is 0.1 contracts on Oanda.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 12/14/21 03:19

Thanks for the fix JCL. I can confirm that it rectifies the issue for Index CFDs but there is now an issue with the FX amounts.

The fix is impacting the order sizes for FX transactions. An example is an order for 10,000 Lots of USDCAD, where 1 Lot = 1, is now only transacting 1,000 USDCAD, 10 times less. The fix seems to have been applied across all products traded on Oanda rather than only the Index CFDs.

This is having unintended consequences with open positions which flips directions, close out long and then go short for example. Zorro now thinks my outstanding position sizes are 10 times smaller. Close orders are less than the actual open positions which are then followed by an order to open a new position in the opposite direction which results in Error 75 because my original position was never completely closed.

Can you have a look at the fix with the Oanda plugin and address this situation?
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 12/14/21 12:56

Now also getting another error message from Oanda:

"market_order_reject","rejectreason":"units_precision_exceeded","instrument":"eur_nok","timeinforce":"fok","positionfill":"reduce_only","reason":"trade_close","tradeclose":{"units":"5045.900000","tradeid":"464"}},"relatedtransactionids":["623"],"lasttransactionid":"623","errormessage":"the units specified contain more precision than is allowed for the order's instrument","errorcode":"units_precision_exceeded"}
Error 075 [EUR/NOK:Trend:S00464] - close attempt 2, 50459@10.27 at 10:00:02

Decimal places not permitted for currency orders. Decimals only permitted for Index CFD because of the change earlier this year to lower minimums.
Posted By: jcl

Re: Oanda LotAmount in Trade Mode - 12/14/21 13:02

I'm not getting that problem here, so let's find out what it is.

- Make sure that you have the latest Zorro version 2.44.4, the release candidate.
- Select your Oanda demo account and run the TradeTest script. Open and close some positions. If the problem then still happens, please post the log.
- If the problem only happens with your script, but not with TradeTest, please contact Support. They will then look into your script and try to reproduce the problem.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 12/14/21 15:30

I upgraded to the latest version 2.44.4 and ran the TradeTest script. All tests out fine.

Now running my script. Will see what happens.
Posted By: JayWilly

Re: Oanda LotAmount in Trade Mode - 12/15/21 14:15

I can confirm that everything is finally working as should be now. The updated Oanda plugin was conflicting with the older Zorro version 2.30.

Thanks for all your help jcl!
Posted By: MegaTanker

Re: Oanda LotAmount in Trade Mode - 12/21/21 18:49

I thought the issue was resolved but maybe it isn't?
With the new Oanda.dll, I reset the z12 instance I have running after getting the same error JayWilly reports above "the units specified contain more precision than is allowed for the order's instrument". I closed all trades and restarted everything, assuming this was happening with trades that were opened with the old plugin. But now it's happening with trades that were opened with the new plugin, too...

Code
!close: {"orderrejecttransaction":{"id":"x","accountid":"x","userid":x,"batchid":"x","requestid":"x","time":"2021-12-21t16:11:24.943373510z","type":"market_order_reject","rejectreason":"units_precision_exceeded","instrument":"gbp_usd","timeinforce":"fok","positionfill":"reduce_only","reason":"trade_close","tradeclose":{"units":"91.100000","tradeid":"478"}},"relatedtransactionids":["498"],"lasttransactionid":"498","errormessage":"the units specified contain more precision than is allowed for the order's instrument","errorcode":"units_precision_exceeded"}
[GBP/USD:NET:S00478] - can't close at attempt 0, 911@1.32409  at 16:11:22


Zorro tries to close 91.1 units. The open position is 911 units. The log also correctly prints that 911 Lots are supposed to be closed. But the order comes out wrong. This is with the new Oanda.dll posted in this thread, I made sure. And since this is a Z system, I can't fix this in the code. Version 2.40

Edit: Just want to add that the same instance managed to correctly close a USD/CAD position before that. Whatever that means.
Posted By: Petra

Re: Oanda LotAmount in Trade Mode - 12/22/21 13:08

I believe you need 2.44. At least in the bug list the problem is listed as "fixed in 2.44".
Posted By: MegaTanker

Re: Oanda LotAmount in Trade Mode - 12/22/21 13:47

That may be the case. When I last looked, the 2.44 was still in beta, so no Z-strat support. But if the Oanda.dll was the only thing changed to address this issue, it may not make a difference.
Posted By: Gheo

Re: Oanda LotAmount in Trade Mode - 12/22/22 21:17

I am curious if you were able to resolve this LotAmount issue with Oanda V20?

at present I am getting the desired position size of 0.01 when back testing but when I tried running it on my demo account the orders are being rejected with the following code.

Code
[500: Thu 22-12-22 20:56] (1.05994)
!order: {"orderrejecttransaction":{"id":"7","accountid":"***-***-********-***","userid":24221766,"batchid":"7","requestid":"25026195017760562","time":"2022-12-22t20:56:00.546953827z","type":"market_order_reject","rejectreason":"units_precision_exceeded","instrument":"eur_usd","units":"0.010000","timeinforce":"fok","positionfill":"default","reason":"client_order"},"relatedtransactionids":["7"],"lasttransactionid":"7","errormessage":"the units specified contain more precision than is allowed for the order's instrument","errorcode":"units_precision_exceeded"}
Warning 075 (EUR/USD::L) - can't open 1@1.0599 at 20:56:00AvgOpen=0.021853 SumOpen=2.119769 Counter=97


I have read all the posts on this subject that I could find as full lot positions would destroy my risk management and would like to take advantage of fractional lots.

If I misconstrue terms please help me learn, I've only been at this for a few months and am learning as best I can.
Thank you.
© 2024 lite-C Forums