Skip to content

Commit

Permalink
fix tv long/short signal
Browse files Browse the repository at this point in the history
  • Loading branch information
51bitquant committed Jul 23, 2022
1 parent cdfc66b commit 6f192c0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
11 changes: 9 additions & 2 deletions howtrader/app/tradingview/strategies/BestLimitTVStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,20 @@ def on_signal(self, signal: dict) -> None:
volume = round_to(Decimal(str(v)), self.contract.min_volume)

volume = abs(volume)
self.traded_volume = Decimal("0")

if action == 'long':
self.target_volume = volume
if self.pos < 0:
self.target_volume = volume + abs(self.pos)
else:
self.target_volume = volume
self.direction = Direction.LONG

elif action == 'short':
self.target_volume = volume
if self.pos > 0:
self.target_volume = volume + self.pos
else:
self.target_volume = volume
self.direction = Direction.SHORT

elif action == 'exit':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def on_signal(self, signal: dict) -> None:
volume = round_to(Decimal(str(v)), self.contract.min_volume)

volume = abs(volume)
self.traded_volume = Decimal("0")

if action == 'long':
if self.pos >= self.contract.min_volume:
Expand Down
14 changes: 11 additions & 3 deletions howtrader/app/tradingview/strategies/SimpleTVStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def on_tick(self, tick: TickData) -> None:

self.timer_count += 1

if self.timer_count < 10:
if self.timer_count < 3:
return None

self.timer_count = 0
Expand Down Expand Up @@ -140,13 +140,21 @@ def on_signal(self, signal: dict) -> None:
volume = round_to(Decimal(str(v)), self.contract.min_volume)

volume = abs(volume)
self.traded_volume = Decimal("0")

if action == 'long':
self.target_volume = volume
if self.pos < 0:
self.target_volume = volume + abs(self.pos)
else:
self.target_volume = volume
self.direction = Direction.LONG

elif action == 'short':
self.target_volume = volume
if self.pos > 0:
self.target_volume = volume + self.pos
else:
self.target_volume = volume

self.direction = Direction.SHORT

elif action == 'exit':
Expand Down
11 changes: 9 additions & 2 deletions howtrader/app/tradingview/strategies/TwapTVStrategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,20 @@ def on_signal(self, signal: dict) -> None:
self.every_order_volume = round_to(self.every_order_volume, self.contract.min_volume)
# if received new signal, reset the timer_count & total_count
self.timer_count = 0
self.traded_volume = Decimal("0")

if action == 'long':
self.target_volume = volume
if self.pos < 0:
self.target_volume = volume + abs(self.pos)
else:
self.target_volume = volume
self.direction = Direction.LONG

elif action == 'short':
self.target_volume = volume
if self.pos > 0:
self.target_volume = volume + self.pos
else:
self.target_volume = volume
self.direction = Direction.SHORT

elif action == 'exit':
Expand Down

0 comments on commit 6f192c0

Please sign in to comment.