help to code a position automation
Forums › ProRealTime English forum › ProBuilder support › help to code a position automation
- This topic has 9 replies, 2 voices, and was last updated 2 months ago by robertogozzi.
-
-
07/30/2024 at 10:56 AM #235926
Hello, I am looking to automate a daily position taking but I have no coding knowledge.
The parameters looked like this:
- Calculate the price variation in % between yesterday’s 09:05 closing and today’s 9:00 opening.
—> If the variation is greater than 0.5% then take a buy on the market instantly with 1% of the capital (100 pts of SL / 100 pts of TP)
—> If the variation is less than -0.5% then take a short on the market instantly with 1% of the capital (100 pts of SL / 100 pts of TP)
I would need the position taking to be done as soon as the 9:00 candle appears, as close as possible to the open to fit with my manual backtests.
Example:
Close at 9:05 on 07/25th is at 39856
Open at 9:00 on 07/26th is at 40082
= a variation of +0.56%, the bot must long instantly in this case because we are above the 0.5% variation requested to enter a position.
Thank you in advance for your valuable help.
07/30/2024 at 6:30 PM #235946There you go:
123456789101112131415161718192021222324252627282930313233343536ONCE myCapital = 10000ONCE Open0900 = openONCE Close0905 = Open0900ONCE PClimit = 0.5IF OpenTime = 090000 THENOpen0900 = openENDIFmyVar = Close0905 - Open0900varPC = 100 - (Open0900 * 100 / Close0905)Money = 100 * PipValueEquity = myCapital + StrategyProfittemp = Money * 100 / EquityLotSize = 1 / tempIF (varPC > PClimit) AND Not LongOnMarket THENBUY LotSize CONTRACTS AT MARKETELSIF (varPC < -PClimit) AND Not ShortOnMarket THENSELLSHORT LotSize CONTRACTS AT MARKETENDIFSET STOP pLOSS 100SET TARGET pPROFIT 100IF Time = 090500 THENClose0905 = closeENDIF// --- debugging code//graphonprice Open0900 coloured("Blue")//graphonprice Close0905 coloured("Fuchsia")//graph myVar//graph varPC//graph LotSize//graph temp1 user thanked author for this post.
07/31/2024 at 9:24 PM #23598908/01/2024 at 9:11 AM #236000Check that your timeframe is <= 5 minutes, as the candle involved must close on the minute (in your case 00 ans 05) used in the code.
08/01/2024 at 4:34 PM #23602908/01/2024 at 5:06 PM #236033It depends on the variable LotSize, I changed it so that it cannot fall below 0.5 lots (if it still doesn’t work try 1, instead of 0.5):
1LotSize = max(0.5,1 / temp)08/13/2024 at 3:17 PM #23637008/13/2024 at 3:59 PM #236371With this line 16, it works on all assets/instruments (using both 1-minute and 5-minute TFs):
1LotSize = max(1,1 / temp)08/19/2024 at 8:42 AM #23649608/19/2024 at 8:58 AM #236497Yes, it works like a charm.
-
AuthorPosts
Find exclusive trading pro-tools on