Current Price in different timeframes
01/03/2023 at 9:34 AM #206710
First off i want to explain that i’m new to programming and to PRT so excuse me in advance. I’ve tried to find a solution now for a couple of days but have a hard time.
I want to buy the close if the index is up more than X percent and above MA200 the same day and then sell the open the day after.
The problem i’ve encountered is getting the current price before close and compare it from the previous days close. I came across the function timeframe and was thinking that using that in 5 min and update the price before close and then compare it with yesterdays price.
Anyone have a good solution to this and what timeframe as default would you use for this solution?
Sounds simple but i guess it’s not, thanks in advance.01/03/2023 at 10:05 AM #20671101/03/2023 at 10:16 AM #206712
I want X% to be calculated on yesterday’s close, just like they do with stocks.
For example yesterday dax closed at 14070 and current price is 14255 and it is up 1.33%. So at today’s close if Dax is still up X% I want to buy to sell immediately at open tomorrow.01/03/2023 at 10:20 AM #20671312345678910111213141516171819202122232425262728293031323334353637//Current price in 5min timeframetimeframe(5 minutes, updateonclose)CurrentPrice = closetimeframe(default)IF TIME = 210000 THENbuyconditiontime = 1ELSEbuyconditiontime = 0ENDIFMA1 = Average(open)MA2 = open > MA1PercentageDiff = (CurrentPrice > close*1.015)IF PercentageDiff THENdailypercentage = 1ELSEdailypercentage = 0ENDIFIF NOT LongOnMarket AND buyconditiontime AND MA2 AND dailypercentage THENBUY 1 CONTRACTS AT MARKETENDIFIF TIME = 090000 THENsellconditiontime = 1ELSEsellconditiontime = 0ENDIF// Conditions to exit long positionsIf LongOnMarket AND sellconditiontime THENSELL AT MARKETENDIF
This was what i thought would be correct but it’s not since i cant use timeframe 5 min then go back to daily candles.01/03/2023 at 10:49 AM #20671601/03/2023 at 11:15 AM #206718
You can use something like that…Fonsie PRT forum1234567891011xPercent= 1.33xDifference = (DClose(0) - DClose(1))/DClose(1) * 100If NOT OnMarket and xDifference >= xPercent thenBuy 1 contract at MarketEndIfIf NOT OnMarket and xDifference <= xPercent thenSellShort 1 contract at MarketEndIf01/03/2023 at 11:24 AM #20671901/03/2023 at 12:19 PM #206722123456789101112131415161718192021222324252627282930313233// Conditions// Buy at 21:00 if index is above MA200 and up 1% same day.// Index must be above MA200 for positive trendMA1 = Average(close)MA2 = close > MA1xPercent= 1.33xDifference = (DClose(0) - DClose(1))/DClose(1) * 100// Time condition for Buy at 21:00IF TIME = 210000 THENbuyconditiontime = 1ELSEbuyconditiontime = 0ENDIF// Buy 1 contract if the above indicators are trueIF NOT LongOnMarket AND buyconditiontime AND MA2 AND xDifference >= xPercent THENBUY 1 CONTRACTS AT MARKETENDIF// Time condition for Sell at 9:00 the day afterIF TIME = 090000 THENsellconditiontime = 1ELSEsellconditiontime = 0ENDIF// Conditions to exit long positionsIf LongOnMarket AND sellconditiontime THENSELL AT MARKETENDIF
It works but the results are not that good 🙂
Also i’m running it in 1hour timeframe but when backtesting i only get 30 total trades. Would like to expand the backtesting period, is it possible to do the same execution but in a daily timeframe?01/03/2023 at 2:48 PM #20672601/03/2023 at 4:30 PM #206729