FX31337 / FX-BT-Scripts

:page_facing_up: Useful scripts for backtesting.
MIT License
34 stars 39 forks source link

UnboundLocalError: local variable 'uniBar' referenced before assignment [$15 awarded] #45

Closed kenorb closed 8 years ago

kenorb commented 8 years ago

File: convert_csv_to_mt.py

This build shows the error:

Converting the 5m timeframe
[INFO] Trying to read data from /dev/stdin...
Traceback (most recent call last):
  File "/home/travis/.wine/drive_c/Program Files (x86)/MetaTrader 4/history/downloads/scripts/convert_csv_to_mt.py", line 415, in <module>
    HST574(CSV(args.inputFile), outputPath, timeframe, symbol)
  File "/home/travis/.wine/drive_c/Program Files (x86)/MetaTrader 4/history/downloads/scripts/convert_csv_to_mt.py", line 203, in __init__
    bars += self._packUniBar(uniBar)
UnboundLocalError: local variable 'uniBar' referenced before assignment

This could be related to the recent changes.

--- The **[$15 bounty](https://www.bountysource.com/issues/32293012-unboundlocalerror-local-variable-unibar-referenced-before-assignment?utm_campaign=plugin&utm_content=tracker%2F20487492&utm_medium=issues&utm_source=github)** on this issue has been claimed at [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F20487492&utm_medium=issues&utm_source=github).
LemonBoy commented 8 years ago

Nope, both in 1 and 2 you've introduced the same error probably after copy-pasting that section of code over. I don't know the format exactly but if it's a paste mishap I think the last line should just be deleted.

kenorb commented 8 years ago

The build fails now with:

Traceback (most recent call last):
  File "/home/travis/.wine/drive_c/Program Files (x86)/MetaTrader 4/history/downloads/scripts/convert_csv_to_mt.py", line 416, in <module>
    FXT(CSV(args.inputFile), outputPath, timeframe, server, symbol, spread)
  File "/home/travis/.wine/drive_c/Program Files (x86)/MetaTrader 4/history/downloads/scripts/convert_csv_to_mt.py", line 256, in __init__
    header += pack('<i', int(firstUniBar['barTimestamp']))                          # Modelling start date - date of the first tick.
TypeError: 'NoneType' object is not subscriptable

Not sure if that's related. Corrected CI tests (#50) which weren't failing before, because data conversion didn't happen.

LemonBoy commented 8 years ago

The error is similar to the one fixed in the commit but completely different :) As you can see in [1] it's possible that firstUniBar isn't ever initialized if there are no ticks, and this happens because of #25

[1] https://github.com/FX31337/FX-BT-Scripts/blob/master/convert_csv_to_mt.py#L230,L244