Trade not being entered
Forums › ProRealTime English forum › ProOrder support › Trade not being entered
- This topic has 10 replies, 5 voices, and was last updated 1 month ago by
PeterSt.
-
-
09/16/2025 at 6:56 PM #250955
Hi guys, probably really stupid but – Why is this code not entering a trade? i’m using a daily chart of US Tech 100:
DEFPARAM CumulateOrders = true
once initialTrade = 0
IF initialTrade = 0 THEN
BUY 1 CONTRACT AT MARKET
initialTrade = 1
ENDIF09/16/2025 at 7:31 PM #250959It’s weird, you can use this version, though:
12345678DEFPARAM CumulateOrders = falseonce initialTrade = 0if onmarket theninitialTrade = 1endifIF initialTrade = 0 THENBUY 1 CONTRACT AT MARKETENDIF1 user thanked author for this post.
09/16/2025 at 8:45 PM #25096309/17/2025 at 7:13 AM #250974The problem is that the backtester loads and performs calculations even before the first candle is seen. This causes the initialTrade variable to already be equal to 1 when the backtesting starts.
12345678910DEFPARAM CumulateOrders = trueonce initialTrade = 0IF initialTrade = 0 THENBUY 1 CONTRACT AT MARKETinitialTrade = 1ENDIFgraph initialTradeWhy does Roberto’s code work? Basically because initialTrade changes state only when the first buy is executed, and that actually happens on the first visible candle.
1 user thanked author for this post.
09/17/2025 at 2:34 PM #251045You could also set “preloadbars” to 1000, for example, and not do any calculation of buy/sell trigger variables before bar No. 1000.
This solves the problem that normally, all variables will be calculated beginning from bar 1.
DEFPARAM preloadbars = 1000
DEFPARAM CumulateOrders = true
once initialTrade = 0
IF initialTrade = 0 and barindex > 1000 THEN
BUY 1 CONTRACT AT MARKET
initialTrade = 1
ENDIF2 users thanked author for this post.
09/17/2025 at 2:52 PM #251046I just checked in demo mode : we need to say “if barindex >= 1000”, not “if barindex > 1000”
DEFPARAM preloadbars = 1000
DEFPARAM CumulateOrders = true
once initialTrade = 0
IF initialTrade = 0 and barindex >= 1000 THEN
BUY 1 CONTRACT AT MARKET
initialTrade = 1
ENDIF09/17/2025 at 3:06 PM #251047@XORANDNOT has the best solution sofar. But the real solution encapsulates the whole code for its logic in that If. Thus, see 1st screenshot and assume that PreLoadBars was made equal to DefParamPreloadbars (which in itself is also a must to be obtained), then in the 2nd screenshot you see the very end of the program.
Do it like this and you simply cannot make mistakes, but notice that above this main If only ONCE commands are allowed.
1 user thanked author for this post.
09/17/2025 at 3:33 PM #251051As I said, you need to say :
If barindex >= preloadedbars then
If you say
If barindex > preloadedbars then
no position will be opened in the first bar of the really started system.
1 user thanked author for this post.
09/17/2025 at 4:46 PM #251056Yes, I understand that. But I don’t see where that matters ? To my understanding :
In my case I set PreLoadBars to 100, just because it requires that command or else nothing works as intended. I could also have made that 99 or 101 or 50 or 200. Even if you have bars of 1 day, it still does not matter that I can see. True, it would require one more day to preload with 100 and your system starting at day 101 for real. But this is only virtual and nothing starts later. Really all what happens is that one more bar/day is loaded ahead of the sequence of bars.
What one should use the PreLoadBars for is the knowledge of averages and all which require x bars to calculate. Thus, using an average of 100 on 2 bars really does not work. Do you need 100 bars for that ? then the system should start at bar 101 or else it is not complete. Maybe on bar 100 … but this is all not important.
Superfluously : if the time is now 17:22:01 and PreloadBars is 100 or 50 or 200 etc. and I start the system *now* and it goes Long immediately, then with a TF of 1 minute at 17:23 it will have taken a position.
Would this be a backtest, then I can imagine that with 1M bars you will lose 100 (or 101 etc.) bars of precious backtest data. This is not important, right ?So now I am curious what you mean ? 🙂
09/17/2025 at 6:12 PM #251064It matters when you start a system on any timescale. For example, in a 1 hour chart, no position will be opened at the beginning of the bar after you started the system, but only one hour later, at the second bar. The same for any other timescale.
“if the time is now 17:22:01 and PreloadBars is 100 or 50 or 200 etc. and I start the system *now* ” —– it will NOT go Long immediately, but at 17:24 at the earliest, in case you write ” barindex > preloadbars “.
It will go long at 17:23 when you write ” barindex >= preloadbars ”
Does not sound logical, but it is so. Just try it out in demo, in a 10 second chart, for example.
1 user thanked author for this post.
09/17/2025 at 6:34 PM #251066 -
AuthorPosts
Find exclusive trading pro-tools on 