AminHP / gym-mtsim

A general-purpose, flexible, and easy-to-use simulator alongside an OpenAI Gym trading environment for MetaTrader 5 trading platform (Approved by OpenAI Gym)
MIT License
428 stars 107 forks source link

Set lots(volume) #41

Open AnggonoUtomo opened 1 year ago

AnggonoUtomo commented 1 year ago

how do i set the maximum lots?

wayneadams commented 1 year ago

You could update the volume_max property on the respective symbol_info stored in the DATA_DIR's pickle files. But that seems brittle.

I think you could also do something like this:

  1. Extend MtSimulator into a new class
  2. Include a new parameter, say max_lot_size
  3. Overwrite _check_volume() (see here) with a new function that uses the new parameter and throws a ValueError when appropriate

But, I'm pretty new to this package, so there are probably better ways to do this :)

wayneadams commented 1 year ago

Actually, instead of going to the DATA_DIR, you can just update the volume_max property by accessing symbols_info directly on a MtSimulator instance. Do this after loading data.

For example:

sim = MtSimulator(
    unit='USD',
    balance=10000.,
    leverage=100.,
    stop_out_level=0.2,
    hedge=True,
    symbols_filename=FOREX_DATA_PATH
)

if not sim.load_symbols(FOREX_DATA_PATH):
    sim.download_data(
        symbols=["EURUSD"],
        time_range=(from_dt, to_dt),
        timeframe=Timeframe.M1
    )
    sim.save_symbols(FOREX_DATA_PATH)

new_max_volume = 42.0
sim.symbols_info["EURUSD"].volume_max = new_max_volume
AnggonoUtomo commented 1 year ago

Let's to try, thanks Wayne....