JSParticipant
Senior
When I use your code in “live demo,” the first position opens…?
JSParticipant
Senior
In this case, opening a position on the first bar in combination with an indicator only works when the “PreLoadBars” are equal to the indicator’s period…
So here, PreLoadBars=36…
<span class=”bbp-author-name”>stalba</span> it appears that PreLoadbars = 36 is critical if ‘NOT onMarket’ is used. You use period of 36 in your SuperTrend, hence PreLoadbars = 36 is critical I guess.
Or it appears you could miss out ‘NOT onMarket’ and use PreLoadbars = 100 / whatever … as I posted above … unless anyone has good reason not to do this??
EDIT/ PS
I saw JS last post after I posted mine.
Seems to work now, like you both said either with “36 bars + NOT ONMARKET” or e.g. “100 Bars without NOT ONMARKET”, but I guess if 36 bars are enough, I’d go with the “NOT ONMARKET” version. Next, I will test it with a 1-day timeframe – thanks! 🙏🏼
Without trying the code : I bet you that this is because the code has ran several times in live before the PreLoadBars have passed. Thus, have those at 100 and the code will be run 100 times and EntryFlag has turned 1 long gone …
The catch here is that during the PreLoadBars stage the ProOrder commands are NOT executed. Thus no Buy and no Sell or anything.
Years ago I reported this as a severe bug. I myself don’t notice any more that this is still present. Because see below …
PreLoadBars = 1000
PreLoadBarsSet = 1000 // Set this redundantly to the line above.
[...]
[...]
If BarIndex > PreloadBarsSet then
[...] // All of your code here - especially the code which determines and does trading.
endif
… which is what I apply always since.
During Backtesting this is applied differently by PRT, because there the code is NOT run during the PreLoadBars stage.
What is below for on Lines 4 and 5?
[…]
[…]
Apologies @PeterSt but are you saying the feature of having to wait for 1000 preloadbars (in this case) before anything is executed by an auto-trader – can be managed (overcome) by the code you’ve kindly shared.
I feel I’m missing the devil in the detail a little and you’re not saying that entirely but that’s how it’s reading to me (the uninitiated)
PreLoadBarsSet = 1000
and
If BarIndex > PreloadBarsSet then
I have seen you post this before where preloads have been discussed.
Seeking a little clarity here, if this is the case and how it relates to backtest, demo and live.
I think what you said was in the context of this – specific – discussion, where the OP was not seeing triggers for reasons X and how that relates to bars elapsed with respect to preloads and indicator code employed. Your code simply eliminates erroneous triggers and perhaps outcomes given the dataset hasn’t reached required size.
Bit of a waffle there, pls correct if I’ve borked it …
What is below for on Lines 4 and 5?
[…]
[…]
That would typically be the calculation of MACDs and all that *require* the preloaded bars (or else them preloaded bars would be in vain 🙂 ).
I think what you said was in the context of this – specific – discussion, where the OP was not seeing triggers for reasons X and how that relates to bars elapsed with respect to preloads and indicator code employed. Your code simply eliminates erroneous triggers and perhaps outcomes given the dataset hasn’t reached required size.
Bit of a waffle there, pls correct if I’ve borked it …
I hope we’re on the same terms with :
A lot can be done in the code with setting flags etc. etc. etc., that code assuming that a Buy at Market (etc.) would have done so. Thus :
Once IAmIn = 0 // Mind the Once.
If MyBuyCon = 1 then
Buy x Shares at Market // This will not execute when the preloadbars (say 1000) are executed and the code is called a 1000 times.
IAmIn = 1 // This is totally unreliable now for the next iteration.
endif
Sadly, in Backtest this can not be noticed and all goes fine.
Please beware : I never use(d) Demo, so I cannot tell whether Demo will show the same behavior as I have testified (towards PRT) for Live. But I assume it is the same, and with that the cause for the off behavior shown in this thread. GraHal actually showcased it accidentally (in any event well done !).
Hi again,
I’ve been testing several strategies on different instruments over the last two days, but on a 1-day timeframe (which is my goal here), no positions are being opened. One strategy got canceled with a message from PRT suggesting to increase the PreLoadBars. I set it to 10000, but still no positions opened on the next candle. I’ve tested these same systems on 1-minute and 5-minute timeframes, and they worked perfectly. Does anyone know what might be causing the issue with the 1-day timeframe?
One of the codes I’ve tested (with MBTC) is this one:
// Set code parameters
DEFPARAM CumulateOrders = False // Prevents multiple entries
DEFPARAM PreLoadBars = 10000
PreLoadBarsSet = 10000 // Set this redundantly to the line above
ONCE EntryFlag = 0 // Initialization for one-time entry
superTrendValue = SuperTrend[5.4,36]
IF BarIndex > PreloadBarsSet THEN
// Check if there is no position at the start and EntryFlag is 0
IF NOT ONMARKET AND EntryFlag = 0 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Long Conditions
IF NOT LONGONMARKET and close CROSSES OVER superTrendValue THEN
BUY 1 CONTRACT AT MARKET // Long Entry
EntryFlag = 1 // Set the flag to avoid re-triggering
ELSIF LONGONMARKET and close CROSSES UNDER superTrendValue THEN
SELL AT MARKET // Long Exit
EntryFlag = 1 // Set the flag to avoid re-triggering
ENDIF
// Short Conditions
IF NOT SHORTONMARKET AND close CROSSES UNDER superTrendValue THEN
SELLSHORT 1 CONTRACT AT MARKET // Short Entry
EntryFlag = 1 // Set the flag to avoid re-triggering
ELSIF SHORTONMARKET and close CROSSES OVER superTrendValue THEN
EXITSHORT AT MARKET // Short Exit
EntryFlag = 1 // Set the flag to avoid re-triggering
ENDIF
ENDIF
Make sure the asset / instrument selected has a data history exceeding 10K days.
Thanks Roberto! So after all, this is no solution for an auto trading system with futures, as the history for PreLoadBars is never sufficient after you’ve rolled into a new contract? 🥲
Well, although technically you are correct I suppose, functionally it would be “wrong” to anticipate such history on a future ?
I will admit, this gets me thinking.
Interesting ?
Yes, I’m honestly a bit lost here — as I find it hard to believe that no one else is using a trading system for futures… from what I understand, the PreLoadBars are necessary for any kind of indicator to work properly, right? I’ve developed a few systems over the past couple of months that showed promising results, but now they won’t work in ProOrder futures auto trading.