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 = 120000
DEFPARAM 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 = 0
IF Time = 090000 and open= SignalHigh THEN
BUY 1 CONTRACT AT MARKET
ENDIF
//Set Stop-Loss
SET STOP TRAILING 20
Change to below and you should get some trades?
IF LongCondition THEN
BUY 1 CONTRACT AT MARKET
ENDIF
Good 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
the 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?
// Definition of code parameters
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 120000
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
//Long Conditions
IF Time = 085500 THEN
SignalHigh = High
SignalLow = Low
ENDIF
//Define the breatout Conditions
LongCondition = (Close > SignalHigh+3*pipsize and time >= 090000)
ShortCondition = (Close < SignalLow-3*pipsize and time >= 090000)
IF LongCondition THEN
BUY 1 CONTRACT AT MARKET
SET STOP pTRAILING 80*pipsize //20*pipsize
ENDIF
If ShortCondition THEN
SellShort 1 Contract at Market
SET STOP pTRAILING 90*pipsize //20*pipsize
ENDIF
JSParticipant
Senior
I 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)…
DefParam CumulateOrders=False
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 120000
If OpenTime=085000 then
RangeHigh=High
RangeLow=Low
EndIf
If OpenTime=>085000 and OpenTime<090000 then
RangeHigh=max(RangeHigh,High)//Highest of Range
RangeLow=min(RangeLow,Low)//Lowest of Range
EndIf
If OpenTime=>085500 then
Buy 1 contract at RangeHigh+3*pipsize Stop
SellShort 1 contract at RangeLow-3*pipsize Stop
EndIf
GraphOnPrice RangeHigh as "RangeHigh"
GraphOnPrice RangeLow as "RangeLow"
Thank 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.
Jan 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?
did you want 085500?
If you are running on 2 min Chart Timeframe, then you likely want 085400 or 085600?
Jan 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.
I 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)…
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
DefParam CumulateOrders=False
DEFPARAM FLATBEFORE = 090000
DEFPARAM FLATAFTER = 120000
If OpenTime=085000 then
RangeHigh=High
RangeLow=Low
EndIf
If OpenTime=>085000 and OpenTime<090000 then
RangeHigh=max(RangeHigh,High)//Highest of Range
RangeLow=min(RangeLow,Low)//Lowest of Range
EndIf
If OpenTime=>085500 then
Buy 1 contract at RangeHigh+3*pipsize Stop
SellShort 1 contract at RangeLow–3*pipsize Stop
EndIf
GraphOnPrice 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
ENDIF
IF ShortOnMarket THEN
SET STOP LOSS RangeLow
ENDIF
Appreciate your assistance. Thank you.
085580 (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.
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.
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.
JSParticipant
Senior
It 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/
I 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!