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 3 weeks ago by
druby.
-
-
01/17/2025 at 7:06 PM #242737
Hallo all
I like to code a strategy that take the 8.50 to 9.00 candles as a range and then executes a long above the range high or a short below the range low. I how can I give the code the to execute at the break of the range high or low? I have been trying but with no luck. Thank you for your help, really appreciate it!
I got this code but no trades are executed
// Definition of code parameters
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 120000DEFPARAM CumulateOrders = False // Cumulating positions deactivated
//Long Conditions
IF Time = 085500 THEN
SignalHigh = max(high, high[1])
SignalLow = min(low, low[1])
ENDIF//Define the breatout Conditions
LongCondition = (open > SignalHigh and time >= 090000)
ShortCondition = (open < SignalLow and time >= 090000)TradeLong = 0
TradeShort = 0IF Time = 090000 and open= SignalHigh THEN
BUY 1 CONTRACT AT MARKET
ENDIF//Set Stop-Loss
SET STOP TRAILING 2001/17/2025 at 7:23 PM #242738Change to below and you should get some trades?
123IF LongCondition THENBUY 1 CONTRACT AT MARKETENDIF1 user thanked author for this post.
01/18/2025 at 10:58 AM #242746Good morning
Thank you for your reply. Unfortunately if I code this way, the trade will only be opened at 090500, instead at 090000. it will not open a position at the range high.
My idea is that the system opens a long position at the range high +3 pips, or a short position at the range low +3 pips. And I like the system only to have 1 go at either side, meaning once long and once short.
On Jan 17th the trade was only executed at 091000, which in this case would not have had a great influence on the price, however
On Jan 16th the trade was executed at 090500 as a buy entry despite the fact that it should have been a short position from 21375. I don’t understand what is wrong in the code that the system opens a long position despite the fact that we are below the Range low.
How can I program that trades are only openend at the RangeLow or RangeHigh +3 pips?
I truly appreciate your assistance, as I am at a loss.
Thank you
01/18/2025 at 12:04 PM #242749the trade will only be opened at 090500, instead at 090000. it will not open a position at the range high.
Close needs time to get to / past the range high.I have read your last post 3 times and there seems to be too many restrictions on what you expect price to do and when?
Price cannot be made to do what we want at exactly the time we want.
Please state as brief as possible what Algo2 in my next post is not doing that you would like it to do?
01/18/2025 at 12:06 PM #24275012345678910111213141516171819202122232425// Definition of code parametersDEFPARAM FLATBEFORE = 090000DEFPARAM FLATAFTER = 120000DEFPARAM CumulateOrders = False // Cumulating positions deactivated//Long ConditionsIF Time = 085500 THENSignalHigh = HighSignalLow = LowENDIF//Define the breatout ConditionsLongCondition = (Close > SignalHigh+3*pipsize and time >= 090000)ShortCondition = (Close < SignalLow-3*pipsize and time >= 090000)IF LongCondition THENBUY 1 CONTRACT AT MARKETSET STOP pTRAILING 80*pipsize //20*pipsizeENDIFIf ShortCondition THENSellShort 1 Contract at MarketSET STOP pTRAILING 90*pipsize //20*pipsizeENDIF01/18/2025 at 5:12 PM #242777I think what is meant here is to first determine the range and then open the position exactly (title:Open on Tick) on the “RangeMax” and “RangeLow”…
When the range should consist of the first two five-minute bars (08:50-08:55 and 08:55-09:00)…
Open on Tick123456789101112131415161718192021DefParam CumulateOrders=FalseDEFPARAM FLATBEFORE = 090000DEFPARAM FLATAFTER = 120000If OpenTime=085000 thenRangeHigh=HighRangeLow=LowEndIfIf OpenTime=>085000 and OpenTime<090000 thenRangeHigh=max(RangeHigh,High)//Highest of RangeRangeLow=min(RangeLow,Low)//Lowest of RangeEndIfIf OpenTime=>085500 thenBuy 1 contract at RangeHigh+3*pipsize StopSellShort 1 contract at RangeLow-3*pipsize StopEndIfGraphOnPrice RangeHigh as "RangeHigh"GraphOnPrice RangeLow as "RangeLow"3 users thanked author for this post.
01/18/2025 at 5:35 PM #242787Thank you so much for your help. I let the code run on a 2 min chart and got the much better results.
How can I code that at a set level for example SignalHigh a buy order is set and at the SignalLow the Stop Loss?
Just for my understanding. PRT can not open a position on a 5 min candle at the beginning of the candle, right after the signal candle has completed?
I let it run on a 2 min chart and got the much better results, however on Jan 15th it opens a long trade below the range high and it opened the trade right on 090000.
I think I am missing a very basic concept here and appreciate your insights.
01/19/2025 at 9:49 AM #242801Jan 15th it opens a long trade below the range high and it opened the trade right on 090000.
Line 9 in your screenshot above show Time = 085580 (typo?) did you want 085500?
can not open a position on a 5 min candle at the beginning of the candle, right after the signal candle has completed?
No technical reason why not, but Close (on signal candle) needs to be > High (of signal candle) +3 points (Line 15).
If your code was Close = High then maybe, occasionally, a position would be opened at the beginning of the candle, right after the signal candle has completed?1 user thanked author for this post.
01/19/2025 at 11:57 AM #242806did you want 085500?
If you are running on 2 min Chart Timeframe, then you likely want 085400 or 085600?
01/20/2025 at 7:17 AM #242831Jan 15th it opens a long trade below the range high and it opened the trade right on 090000.
Line 9 in your screenshot above show Time = 085580 (typo?) did you want 085500?
Code for Line 9 should be the code for the signal candle. I only let it run on a lower timeframe as I was trying to get the code to execute at 090000 on the correct level but I seem unable to achieve atm
can not open a position on a 5 min candle at the beginning of the candle, right after the signal candle has completed?
No technical reason why not, but Close (on signal candle) needs to be > High (of signal candle) +3 points (Line 15).
If your code was Close = High then maybe, occasionally, a position would be opened at the beginning of the candle, right after the signal candle has completed?Lets take a 5 min chart, Range H from 085000 to 090000 is 21130 and the L 21119. I would like the code to open a long position at 21133 and a short position at 21116 and not just somewhere random.
I appreciate you taken the time. Thank you.
01/20/2025 at 9:08 AM #242835I think what is meant here is to first determine the range and then open the position exactly (title:Open on Tick) on the “RangeMax” and “RangeLow”…
When the range should consist of the first two five-minute bars (08:50-08:55 and 08:55-09:00)…
Open on Tick123456789101112131415161718192021DefParam CumulateOrders=FalseDEFPARAM FLATBEFORE = 090000DEFPARAM FLATAFTER = 120000If OpenTime=085000 thenRangeHigh=HighRangeLow=LowEndIfIf OpenTime=>085000 and OpenTime<090000 thenRangeHigh=max(RangeHigh,High)//Highest of RangeRangeLow=min(RangeLow,Low)//Lowest of RangeEndIfIf OpenTime=>085500 thenBuy 1 contract at RangeHigh+3*pipsize StopSellShort 1 contract at RangeLow–3*pipsize StopEndIfGraphOnPrice RangeHigh as “RangeHigh”GraphOnPrice RangeLow as “RangeLow”Thank you a lot for your help!
Is it correct that If I want the code to do something, it is always the close of the candle not the open?
In order to eliminate the number of trades the system takes, how can I code that it waits at least 3 candles before it opens another new position?
I added as STOP LOSS, which works well, however I should add a if in profit that the stop gets trailed or is that not possible?
IF LongOnMarket THEN
SET STOP LOSS RangeHigh
ENDIFIF ShortOnMarket THEN
SET STOP LOSS RangeLow
ENDIFAppreciate your assistance. Thank you.
01/20/2025 at 9:59 AM #242839085580 (typo?) did you want 085500?
Time format is HHMMSS so there is no 085580 … 085559 then at the Close of the 59th second, time becomes 085600.
Correct your Time, then check your results for any changes.
1 user thanked author for this post.
01/20/2025 at 10:25 AM #242840Lets take a 5 min chart, Range H from 085000 to 090000 is 21130 and the L 21119. I would like the code to open a long position at 21133 and a short position at 21116 and not just somewhere random.
So if Price goes past 21133 before a trade can be opened, then you don’t want to open a trade.
If you are using a 5 min chart then, by the close of the 090500 candle, price may be 21140.
To get what you want, you need to use the code provided by JS using Stop Orders.
1 user thanked author for this post.
01/20/2025 at 10:48 AM #242842It is correct that the code is executed at the close of the candlestick (Close). Therefore, when a certain condition is triggered during the execution and this condition initiates a position (at market), the position will be opened at the “Open” of the next bar.
This is one way to wait for a period after a position is opened…
Once BarsToWait = 3
If BarIndex – TradeIndex(1) > BarsToWait then
If you want to use a “Trailing Stop Loss,” this is, in my opinion, the most used code https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/
1 user thanked author for this post.
01/20/2025 at 3:21 PM #242862I actually want the code to wait after having been stopped out for 3 bars before opening a new trade, as I hope with this to reduce the number of stop out trades.
Appreciate your support very much!
-
AuthorPosts
Find exclusive trading pro-tools on