How to buy/sell at Close of a day?
Forums › ProRealTime English forum › ProBuilder support › How to buy/sell at Close of a day?
- This topic has 16 replies, 2 voices, and was last updated 8 years ago by
karunswaro.
-
-
05/03/2016 at 1:12 AM #6364
Hi,
Looking for help with code.
How to buy/sell on Close of a day? for forex, which 24hrs trading.
I saw we can execute at a specific time (23hrs 30min 00sec), so used below code, but did not work.
IF time >=233000 THEN
SELL AT MARKET
ENDIFThanks in advance,
Karun
05/03/2016 at 1:35 AM #6365Also saw a changelog on https://www.prorealtime.com/en/trading-system-programming-changelog
the following instructions have been removed:
- ThisBarOnClose
- TodayOnClose
- TomorrowClose
How do we accomplish similar operations? sell/buy at a specific time?
05/03/2016 at 8:06 AM #6377Hi Karun, if you mean exit all positions at the end of the day, you can use the FlatAfter instruction:
12//exit all positions and prevent new ones to be launched until the end of the daydefparam flatafter = 233000Is that what you were looking for?
05/03/2016 at 1:15 PM #6393Hi Nicolas,
Thanks for your help.
But I am looking for something like this.
IF MyCondition AND time > 233000 THEN
SELL AT MARKET
ENDIF
When I trade manually, I check for MyCondition 30 min before market and close my position manually, so want to do the same in backtesting.
05/03/2016 at 1:48 PM #639605/03/2016 at 1:55 PM #6397Here is my code. made it simple, condition to be when closes above MA5. May be I shouldn’t take close of day and close of MA, right?
// Conditions to exit long positions
indicator2 = close
indicator3 = ExponentialAverage[5](close)
LongExitCondition = (indicator2 >= indicator3)IF LongOnMarket AND LongExitCondition AND TIME > 233000 THEN
SELL AT MARKET
ENDIF05/03/2016 at 2:04 PM #6398How do I get price and Average[5] at a specific time (233000)?
05/03/2016 at 3:45 PM #640205/03/2016 at 3:47 PM #6403Daily. Below code does not work. It does not close at specified time. What am I doing wrong here?
// Conditions to exit long positions
indicator2 = close
indicator3 = ExponentialAverage[5](close)
LongExitCondition = (indicator2 >= indicator3)
IF LongOnMarket AND LongExitCondition AND TIME > 233000 THEN
SELL AT MARKET
ENDIF
05/03/2016 at 4:51 PM #640505/03/2016 at 5:03 PM #640605/03/2016 at 5:25 PM #6408Hi Nicolas,
I wrote some basic code to test this, hope you can help me. I wrote an indicator “InsideBar”, which is a bar inside previous bar.
Then I wrote backtest for it. We buy the open of next day after an Insidebar indicator, and only thing I need is the exit of position on same day at 30 min before close.
We can test this on any stock, and below code exits on next day after entry day,
I want the entry and exit on SAME DAY, entry on open of day and exit at 30 min before market close.
Hope you can help me.
12345678910111213141516171819202122232425262728293031//Indicator code ----- START----REM inside barc1= high[0] < high [1]c2= low[0] > low[1]insidebar= c1 and c2return insidebar//Indicator code ----- END----//Backtest code ----- START----// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = CALL insidebarc1 = (indicator1 > 0)IF c1 AND NOT LongOnMarket THENBUY 1 SHARES AT MARKETENDIFIF LongOnMarket AND time>153000 THENSELL AT MARKETENDIF//Backtest code ----- END----05/03/2016 at 5:39 PM #640905/03/2016 at 7:21 PM #6414Ok, with the whole code it is much clear now 🙂
You should trade the strategy on intraday timeframe and use the daily candlesticks informations with DHIGH and DLOW.
I rewrote the whole code to be more compliant with what you got in mind:
1234567891011121314151617DEFPARAM CumulateOrders = FalseDEFPARAM FlatAfter = 153000 //all positions are closed at 15:30:00//reset a variable to tell the system that we are on a new day and we can start trade againif intradaybarindex=0 thenalreadytraded = 0endif//inside bar (using Daily candles)c1= Dhigh(1) < Dhigh(2)c2= Dlow(1) > Dlow(2)insidebar= c1 and c2IF insidebar AND alreadytraded=0 THENBUY 1 SHARES AT MARKETalreadytraded = 1ENDIFSo do your tests on 5 or even 1 minute timeframe for better prices executions.
05/03/2016 at 7:43 PM #6416Hi Nicolas,
Thanks for your help and quick reply. Now I see the exit is happening at 153000 but the entry has issue.
I debugged more and found the inside bar code you gave is behaving different in different time frames. I tested the same code on daily and hourly and see it’s giving false signals in hourly. Attached screenshot.
This is what I have in code:
REM inside bar
c1= Dhigh(0) < Dhigh (1)
c2= Dlow(0) > Dlow(1)insidebar= c1 and c2
return insidebar
-
AuthorPosts
Find exclusive trading pro-tools on