From b2383373dd5778493a2a13ac38cadeafd9c76a49 Mon Sep 17 00:00:00 2001 From: Rose Heart Date: Tue, 14 May 2024 23:35:17 +0000 Subject: [PATCH] Fixed bug where FIFO regulation were not being honored with Flip action. Changes to be committed: modified: Base/OANDA-PlaceOrder --- Base/OANDA-PlaceOrder | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Base/OANDA-PlaceOrder b/Base/OANDA-PlaceOrder index 9c5aa13..0806d23 100755 --- a/Base/OANDA-PlaceOrder +++ b/Base/OANDA-PlaceOrder @@ -99,6 +99,7 @@ def LowestLotSize(relay,asset,units,step): else: sign=1 + relay.JRLog.Write(f'EnforceFIFO: next unit size is {nextSize*sign}') return nextSize*sign # Find highest lot size @@ -283,18 +284,6 @@ def main(): if AlreadyBought(relay,relay.Order['Asset'],ticker['Bid'],devPips): relay.JRLog.Error("Deviation", f"{relay.Order['Deviation']}: Required condition not met") - # Check and manage FIFO rule - if 'EnforceFIFO' in relay.Active or 'EnforceFIFO' in relay.Order: - if 'Step' in relay.Order: - step=int(relay.Order['Step']) - else: - step=1 - - if relay.Order['Action']=='buy': - amount=LowestLotSize(relay,relay.Order['Asset'],amount,step) - elif 'Ticket' in relay.Order: - amount=GetTicket(relay,relay.Order['Asset'],relay.Order['Ticket'],amount) - # Figure limit order pricing, minimum cost is ignored as limit orders can be # anything. @@ -356,6 +345,18 @@ def main(): # Make ure units is in range of what we actually hold amount=units + # Check and manage FIFO rule + if 'EnforceFIFO' in relay.Active or 'EnforceFIFO' in relay.Order: + if 'Step' in relay.Order: + step=int(relay.Order['Step']) + else: + step=1 + + if relay.Order['Action']=='buy': + amount=LowestLotSize(relay,relay.Order['Asset'],amount,step) + elif 'Ticket' in relay.Order: + amount=GetTicket(relay,relay.Order['Asset'],relay.Order['Ticket'],amount) + # Determine trade action and carry it out if type(amount) is int: