Coding open on Tick
Forums › ProRealTime English forum › ProOrder support › Coding open on Tick
- This topic has 28 replies, 4 voices, and was last updated 4 weeks ago by
druby.
-
-
01/20/2025 at 3:48 PM #242864
When you are stopped out you can also use these:
Once BarsToWait=3
If StrategyProfit<>StrategyProfit[1] then
StartBar=BarIndex
EndIf
If NOT LongOnMarket and OpenTime=>085500 and (BarIndex-StartBar)>BarsToWait then
Buy….
1 user thanked author for this post.
01/20/2025 at 6:31 PM #242884This is my current code and in order to optimize it, I need to eliminate the amount of orders the system opens during chop times. However I seem unable to code this. This means that from the time we are stopped out until the next order is placed in the system. Thank you for your help!
I can’t get it to work with the suggested code.
BarIndex-TradeIndex>1
If LongOnMarket and (BarIndex-TradeIndex)>1 and Close > TradePrice then
This is my current code!
//Conditions to enter long or short at Europe Open
DefParam CumulateOrders=False
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 110000If OpenTime=085000 then
RangeHigh=High
RangeLow=Low
EndIfIf OpenTime=>085000 and OpenTime<090000 then
RangeHigh=max(RangeHigh,High)//Highest of Range
RangeLow=min(RangeLow,Low)//Lowest of Range
EndIfIf OpenTime=>085500 then
Buy 1 contract at RangeHigh+3*pipsize Stop
SellShort 1 contract at RangeLow-3*pipsize Stop
EndIf//Set Stop Loss
IF LongOnMarket THEN
SET STOP LOSS RangeLowENDIF
IF ShortOnMarket THEN
SET STOP LOSS RangeHighENDIF
GraphOnPrice RangeHigh as “RangeHigh”
GraphOnPrice RangeLow as “RangeLow”01/20/2025 at 7:10 PM #242887You can use the “BarsToWait” parameter to set how many “Bars” should be between two “Trades”…
I have adjusted the “Stop Loss” to the use of the “RangeLow” and “RangeHigh” price levels…
Trader Sab123456789101112131415161718192021222324252627282930//Conditions to enter long or short at Europe OpenDefParam CumulateOrders=FalseDEFPARAM FLATBEFORE = 090000DEFPARAM FLATAFTER = 110000If OpenTime=085000 thenRangeHigh=HighRangeLow=LowEndIfIf OpenTime=>085000 and OpenTime<090000 thenRangeHigh=max(RangeHigh,High)//Highest of RangeRangeLow=min(RangeLow,Low)//Lowest of RangeEndIfOnce BarsToWait=13If OpenTime=>085500 and (BarIndex-TradeIndex)>BarsToWait thenBuy 1 contract at RangeHigh+3*pipsize StopSellShort 1 contract at RangeLow-3*pipsize StopEndIf//Set Stop LossIF LongOnMarket THENSet STOP Price RangeLowElsIf ShortOnMarket THENSet STOP Price RangeHighENDIFGraphOnPrice RangeHigh as "RangeHigh"GraphOnPrice RangeLow as "RangeLow"1 user thanked author for this post.
01/20/2025 at 11:26 PM #242892Everytime I think I got the code to do what I want it, I find another mistake and I don’t know how I can eliminate it.
On Jan 16th (below screenshot)
090000 order executed at the right level, however it wasn’t closed at RangeLow but 20 points lower. I tried with the trailingstart = 0 but it doesn’t change the result.
093000 a short order was executed at the same level as the first order was stopped out. The system didn’t wait 4 bars before entering another trade again, nor did it open a trade once it touched RangeLow
It really drives me crazy that I don’t understand where the error lies.
Thank you again for your help. Most appreciated
01/21/2025 at 9:41 AM #242903The use of the “Stop Trailing” is incorrect. With this type of “trailing stop,” you can only specify how many points below the position price the trailing should start.
“Set Stop Trailing 20” will start trailing 20 points below the position price.
Lines 24 and 25 in the code are redundant when using this trailing stop.
Furthermore, when using “STOP” orders, there is a chance that the “pending” orders are both executed within the same bar, meaning that both RangeHigh and RangeLow are hit in the same bar…1 user thanked author for this post.
01/21/2025 at 10:24 AM #242904Thank you very much for the explanation of the trailing stop . So there is no way I can have the stop at RangeLow and trail it from there because it is a set level.
I would really appreciate if you could have a look at the below screenshot, where the trade was not opened at the right level at 093000. Where is the mistake there, as the trade should open at RangeLow and not 19 points lower.
01/21/2025 at 10:26 AM #24290501/21/2025 at 11:19 AM #242907One possible approach could be to calculate the number of points within the range (RangeHigh, RangeLow) immediately when determining the range:
RangePoints = (RangeHigh - RangeLow)
Then use these points for your trailing stop:
Set Stop Trailing RangePoints
This way, the trailing stop starts approximately at the fixed levels.I looked into the 09:30:00 trade but couldn’t identify what happened there either; perhaps it was still related to the incorrectly configured trailing stop…
Trader Sab V212345678910111213141516171819202122232425262728293031//Conditions to enter long or short at Europe OpenDefParam CumulateOrders=FalseDEFPARAM FLATBEFORE = 090000DEFPARAM FLATAFTER = 110000If OpenTime=085000 thenRangeHigh=HighRangeLow=LowEndIfIf OpenTime=>085000 and OpenTime<090000 thenRangeHigh=max(RangeHigh,High)//Highest of RangeRangeLow=min(RangeLow,Low)//Lowest of RangeRangePoints=(RangeHigh-RangeLow)EndIfOnce BarsToWait=4If OpenTime=>085500 and (BarIndex-TradeIndex)>BarsToWait thenBuy 1 contract at RangeHigh+3*pipsize StopSellShort 1 contract at RangeLow-3*pipsize StopEndIf//Set Stop LossIF LongOnMarket THENSet STOP Trailing RangePointsElsIf ShortOnMarket THENSet STOP Trailing RangePointsENDIFGraphOnPrice RangeHigh as "RangeHigh"GraphOnPrice RangeLow as "RangeLow"1 user thanked author for this post.
01/23/2025 at 11:52 AM #242980Good morning JS
I have been having troubles with other codes where I want the system to open at a set level. Codes with time based entries work well, however I can’t get a code working if I want a specific level to be executed. I appreciate your assistance, as I am at a loss.
Below is the backtest of your code. Unfortunately the system does not open the trade right at 9 am. It should have been a clean short.
Thank you very much for your time.
Best Regards
Sab
01/23/2025 at 12:30 PM #242992Hi Sab,
When I run a backtest on the latest code (Trader Sab V2), the “Short” position is executed correctly.
Something must have been adjusted in the latest version, right?
1 user thanked author for this post.
01/23/2025 at 6:43 PM #243032JS, I just copied your code.
What I don’t understand the trade 2 and 3, because they are opened nowhere near the range low. How can I eliminate this mistake?
Thanks alot.
01/23/2025 at 7:25 PM #243035There are situations with “STOP orders” that don’t work well, for example, when both stop orders are triggered in the same bar, you end up with both a “Long” and a “Short” position at the same time. The backtest module cannot handle this because, according to the rules, opposing positions are not allowed to occur/exist…
Everything after opening the position involves “Trailing,” so the standard trailing stop probably doesn’t work optimally in combination with the “Stop orders”… an alternative is a custom trailing stop… I think there will always be situations here that you (code-wise) cannot control…
1 user thanked author for this post.
01/24/2025 at 10:06 PM #243080I will over the weekend work on it and keep you posted. Most appreciate your insights!
1 user thanked author for this post.
01/25/2025 at 2:07 AM #243082I proposed an addition to the code, after the DEFPARAM statements:
once RangeHigh = undefined
once RangeLow = undefinedMy reasoning for this, mainly to do with the use of GRAPHONPRICE with the RangeHigh and RangeLow variables, and the auto y-axis PRICE scale.
A back-test code has a default of DEFPARAM PRELOADBARS = 1000, which would be, BARINDEX 0 to 999.
These preload-bars are not shown in the chart, so the first chart bar, in this case, would be BARINDEX = 1000.
When a variable is used in the code, it is defined with a default value = 0, from BARINDEX = 0.
In this codes, it’s most likely going to be a later bar before the condition is true, to set both RANGEHigh and RANGELow to the High and Low values for the first time.
Therefore, both Range variables will be zero from bar 0, till the true condition bar, where the values jump to the High and Low values, for the first time.
GRAPHONPRICE works similarly to RETURN, in an INDICATOR code, in terms of a variable triggering the auto y-scale if its the highest and/or lowest value displayed in the chart frame.
This means that, if the variable(s) jump from zero in the visible chart range, to the price level, the scale will adjust to include the price range from this zero value, squashing the price candles in the process.
The additional lines, hold off defining the Range variable’s until there set to the first time high and low values, which will be in the same price range of the candles.
This avoids the extreme zero value and this low value overriding the lowest value displayed in the chart by the candles, and having to manually re-scale in that zone
After, the Range variables have been set for the first time, they maybe adjusted by the next bar, or set to new values on next true condition, never return to zero.
If, first trigger falls in preload- bars area, this may not be a problem, however, if re-back-testing and looking at first trigger zone it can be a hassle if the chart needs manually re-scaling.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on