This is a little snippet if you want to automatically have different settings for when you are running a backtest or running live trading.
I used this for example to change order type to Market Order by default when backtesting. Other potential uses can be changing an order amount or changing some values that rely on info from INSIDE the candle (which is not available in the backtest).
Important Limitation: the snippet only takes into account the very first 2 update cycles,
which means if you first run this as a backtest and THEN start live trading, it will NOT update this_is_a_simulation status.
This snippet only works reliably for the scripts with EnableHighSpeedUpdates() mode enabled, it may not work well without it.
To make use of this, use logic like “if this_is_a_simulation == true then / settings to be changed / end”.
Note that this snippet needs to be inserted BELOW the initial setting, so that it can overwrite the setting.
Note that all the variables used inside this snippet are not valid outside the snippet, since they are local (but of course you can change that),
except for the boolean this_is_a_simulation variable.
If you script requires to know whether it’s a backtest or live trading BEFORE it makes it’s first move (like send a trading signal), then
add a line if ghibli > 3 to that first action. Basically the snippet needs to run 2 update cycles before it knows for sure if this is a simulation or not.
— DISCLAIMER: you should read the code of the snippet and understand how it works,
— the author takes no responsibility for any losses that may occur from either
— the user not implementing the snippet properly nor for the snippet not working as expected.