Buy or Sell at set time and price change on any market.
Forums › ProRealTime English forum › General trading discussions › Buy or Sell at set time and price change on any market.
- This topic has 17 replies, 7 voices, and was last updated 2 months ago by Andre Vorster.
-
-
08/27/2024 at 12:43 PM #236742
Hello.
I don’t know coding to write the code for this idea. I will appreciate help on this one please.
The idea I have.
As you know when the US market opens the volumes are high and moves fast in any direction.
Have code that will open 2 x short OR 2 x long positions depending on the price direction.The positions opens on price change at a set time(market open time) Or opens positions at a candle count after market open.
With the time set or candle count one can start trades on any market and on any time frame even on a 10sec time frame.Can apply this strategy on any market on any time frame. The market and time frame can then be any of your choice.
If this can work this can work in Bull and Bear market.On market open and the price goes higher that what the price was at open. Open 2 x Long positions.
LONG:
1.) Buy 1 contract – set profit for $20 or 20 Points (20 = example/variable)
Close this trade automatically when set profit is reached.
Set Trailing stop at $10 or 10 points (10 = example/variable)
2.) Buy 1 contract with $10/10 points trailing stop so this one can run (10 points = example)SHORT:
The same applies as the above if the price moves lower on market open.
1.) Short 1 contract – set profit for $20 or 20 Points (20 = example/variable)
Close this trade when profit set is reached.
Set Trailing stop at $10 or 10 points (10 = example/variable)
2.) Short 1 contract with $10/10 points trailing stop so this one can run (10 points = example)Thank you.
08/27/2024 at 6:03 PM #236760This is what chatgtp made of it.
ChatGTP123456789101112131415161718192021222324252627282930313233343536// Strategy ParametersTimeMarketOpen = 093000 // Market open time in HHMMSS format (e.g., 09:30:00)TP1 = 20 // Take Profit for the first position in pointsTS1 = 10 // Trailing Stop for the first position in pointsTS2 = 10 // Trailing Stop for the second position in pointsStartTime = TimeMarketOpenCandleCountAfterOpen = 0 // Set to 0 to trade immediately at open// InitializeONCE MarketOpenPrice = 0// Determine the market open price or wait for the candle countIF (Time = StartTime AND CurrentMinute = CandleCountAfterOpen) THENMarketOpenPrice = CloseENDIF// Determine the direction and enter positionsIF (MarketOpenPrice > 0) THENIF Close > MarketOpenPrice THEN// Price is higher than market open, go longBUY 1 CONTRACT AT MARKETSET TARGET pPROFIT TP1SET STOP TRAILING TS1BUY 1 CONTRACT AT MARKETSET STOP TRAILING TS2ELSIF Close < MarketOpenPrice THEN// Price is lower than market open, go shortSELLSHORT 1 CONTRACT AT MARKETSET TARGET pPROFIT TP1SET STOP TRAILING TS1SELLSHORT 1 CONTRACT AT MARKETSET STOP TRAILING TS2ENDIFENDIF08/27/2024 at 6:51 PM #23676108/28/2024 at 6:06 AM #236772Thank you for this.
May be I’m missing something but the code does not open any positions. I changed the TimeMarketOpen, TP & TS values but still no results.
Used the code like one would test any strategy. My PRT is working and have no issues there.08/28/2024 at 9:33 AM #23677908/28/2024 at 10:01 AM #236780fifi743
Thank you for the input.Your comment is the same as in the original code. What do you suggest?
line 14 – MarketOpenPrice = CloseWhat do you mean? I don’t understand (because I can’t code)
line 19 and line 27
MarketOpenPrice cannot be different from closeThank you
08/28/2024 at 10:11 AM #23678108/28/2024 at 10:20 AM #236783Still no trades opened.
08/28/2024 at 10:29 AM #23678408/28/2024 at 11:08 AM #236785Ah.! Now it takes positions.
Thank you.But it keeps on opening positions. I want it just to take positions and then stop.
Example: When the market opens it should take positions buy/sell then exit the code/market.08/28/2024 at 4:44 PM #23679108/31/2024 at 11:00 AM #236946It still opens trades at any time.
Does not start at set time and end when set target profit is reached.Thanks you.
08/31/2024 at 11:26 AM #236948Try this version:
123456789101112131415161718192021222324252627282930313233343536DEFPARAM CumulateOrders = FALSE// Strategy ParametersTimeMarketOpen = 093000 // Market open time in HHMMSS format (e.g., 09:30:00)TP1 = 20 // Take Profit for the first position in pointsTS1 = 10 // Trailing Stop for the first position in pointsTS2 = 10 // Trailing Stop for the second position in pointsStartTime = TimeMarketOpenCandleCountAfterOpen = 0 // Set to 0 to trade immediately at open// InitializeMarketOpenPrice = 0// Determine the market open price or wait for the candle countIF (Time = StartTime) then//AND CurrentMinute = CandleCountAfterOpen) THENMarketOpenPrice = openENDIF// Determine the direction and enter positionsIF (MarketOpenPrice > 0) THENIF Close > MarketOpenPrice THEN// Price is higher than market open, go longBUY 2 CONTRACT AT MARKETSET TARGET pPROFIT TP1//SET STOP TRAILING TS1//BUY 1 CONTRACT AT MARKETSET STOP TRAILING TS2ELSIF Close < MarketOpenPrice THEN// Price is lower than market open, go shortSELLSHORT 2 CONTRACT AT MARKET//SET TARGET pPROFIT TP1//SET STOP TRAILING TS1//SELLSHORT 1 CONTRACT AT MARKET//SET STOP TRAILING TS2ENDIFENDIFthe last SET TARGET and SET STOP always override the previous ones. It’s not possible to set two different STOPs or TARGETs.
08/31/2024 at 2:34 PM #236957This one works. Thank you Robert.
Profit not as much as I thought it might be but I’ll keep on playing with the TS and TP and see which combination gives best results.
Question:
See att image. What are the differences between the highlighted amounts?08/31/2024 at 11:30 PM #236967 -
AuthorPosts
Find exclusive trading pro-tools on