Position Indicator
Forums › ProRealTime English forum › ProBuilder support › Position Indicator
- This topic has 11 replies, 3 voices, and was last updated 4 years ago by robertogozzi.
-
-
12/19/2020 at 2:06 PM #154421
Hello! I need help building an indicator.
I have an algo that can take three positions at different levels. The indicator should show how many positions it has taken.
I am sending a picture of what the indicator should look like.
Also sends a simple code we can start from.
The idea is to be able to use this indicator for another algo that will hedge this position. I can make the indicator so that it shows the positions but not that it goes down to zero when algo closes the position123456789101112131415161718// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = RSI[14](close)c1 = (indicator1 < 12)IF not longonmarket and c1 THENBUY 1 CONTRACT AT MARKETENDIFIF longonmarket AND COUNTOFPOSITION=1 and close - tradeprice < -100*pointsize thenBuy 1 CONTRACT AT MARKETendifIF longonmarket AND COUNTOFPOSITION=2 and close - tradeprice < 150*pointsize then Buy 1 CONTRACT AT MARKET endif //Take profit floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains If LONGONMARKET and floatingprofit>20 thensell at marketendif12/19/2020 at 2:43 PM #154424- Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.
- Do not double post. Ask your question only once and only in one forum. All double posts will be deleted anyway so posting the same question multiple times will just be wasting your own time and will not get you an answer any quicker. Double posting just creates confusion in the forums
1 user thanked author for this post.
12/19/2020 at 2:58 PM #15442612/19/2020 at 4:05 PM #15443312345678910111213141516171819202122232425262728// Definition of code parametersDEFPARAM CumulateOrders = True // Cumulating positions deactivated// Conditions to enter long positionsindicator1 = RSI[14](close)c1 = (indicator1 < 30)IF not longonmarket and c1 THENBUY 1 CONTRACT AT MARKETENDIFIF longonmarket AND COUNTOFPOSITION=1 and close - tradeprice < -100*pointsize thenBuy 1 CONTRACT AT MARKETendifIF longonmarket AND COUNTOFPOSITION=2 and close - tradeprice < 150*pointsize thenBuy 1 CONTRACT AT MARKETendifset stop loss 130//Take profitfloatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsIf LONGONMARKET and floatingprofit>20 thensell at marketendif12/20/2020 at 10:31 AM #154545Crillezz – Do not try to bump your own topic by quoting yourself. Can you imagine what a mess the forums would be if everyone did this?
If you have not received a reply it is most likely because either other forum members don’t know the answer or other forum members don’t understand what you want.
The forums are quieter at the weekends when markets are closed and people are away from their desks so some patience helps.
I have deleted your post.
12/20/2020 at 3:42 PM #15459812/20/2020 at 4:14 PM #154604You have five minutes to edit your posts – after that time has passed the edit button is no longer available and only moderators can edit or delete your posts for you. If it is the first post in a topic then only Nicolas can delete it and that action deletes the entire topic.
1 user thanked author for this post.
01/03/2021 at 5:15 PM #15610801/05/2021 at 5:21 AM #156376I assume that your line 17 should read -150.
There you go:
12345678910111213141516171819202122232425262728293031323334353637IF BarIndex = 0 THENMyPositionCount = 0MyPositionPrice = 0ENDIFindicator1 = RSI[14](close)c1 = (indicator1 < 12)IF MyPositionCount = 0 AND c1 THENMyPositionCount = 1MyPositionPrice = closeENDIFIF MyPositionCount = 1 and ((close - MyPositionPrice) < -100*pointsize) thenMyPositionCount = MyPositionCount + 1MyPositionPrice = (MyPositionPrice + close) / 2endifIF MyPositionCount = 2 and ((close - MyPositionPrice) < -150*pointsize) thenMyPositionCount = MyPositionCount + 1MyPositionPrice = ((MyPositionPrice * (MyPositionCount - 1)) + close) / MyPositionCountendifIF (MyPositionPrice - close) >= 130 THEN //Stop LossMyPositionCount = 0MyPositionPrice = 0ENDIFIF MyPositionCount THENfloatingprofit = (((close-MyPositionPrice)*pointvalue)*MyPositionCount)/pipsizeIf MyPositionCount > 0 and floatingprofit > 20 thenMyPositionCount = 0MyPositionPrice = 0endifENDIFRETURN MyPositionCount AS "MyPositionCount"1 user thanked author for this post.
01/15/2021 at 12:34 PM #157942Thanks Roberto. Just what I was looking for. But I have a problem. When I have to do the same thing but with a short position, it increases the position when it is profitable. It should only increase the position in case of loss. And it never reaches floating profit. I do not manage to change the code in the opposite direction
01/15/2021 at 12:43 PM #157943MyPositionCount12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970IF BarIndex = 0 THENMyPositionCount = 0MyPositionPrice = 0ENDIFindicator1 = RSI[14](close)c1 = (indicator1 < 12)IF MyPositionCount = 0 AND c1 THENMyPositionCount = 1MyPositionPrice = closeENDIFIF MyPositionCount = 1 and ((close - MyPositionPrice) < -60*pointsize) thenMyPositionCount = MyPositionCount + 1MyPositionPrice = (MyPositionPrice + close) / 2endifIF MyPositionCount = 2 and ((close - MyPositionPrice) < -90*pointsize) thenMyPositionCount = MyPositionCount + 1MyPositionPrice = ((MyPositionPrice * (MyPositionCount - 1)) + close) / MyPositionCountendif//////////Shortindicator1 = RSI[14](close)c2 = (indicator1 > 88)IF MyPositionCount = 0 AND c2 THENMyPositionCount = -1MyPositionPrice1 = closeENDIFIF MyPositionCount = -1 and ((close + MyPositionPrice1) < -60*pointsize) thenMyPositionCount = MyPositionCount - 1MyPositionPrice1 = (MyPositionPrice1 + close) / 2endifIF MyPositionCount = -2 and ((close + MyPositionPrice1) < -90*pointsize) thenMyPositionCount = MyPositionCount - 1MyPositionPrice1 = ((MyPositionPrice1 * (MyPositionCount - 1)) + close) / MyPositionCountendifIF (MyPositionPrice1 - close) >= 130 THEN //Stop LossMyPositionCount = 0MyPositionPrice1 = 0ENDIFIF MyPositionCount THENfloatingprofit = (((close-MyPositionPrice)*pointvalue)*MyPositionCount)/pipsizeIf MyPositionCount > 0 and floatingprofit > 20 thenMyPositionCount = 0MyPositionPrice = 0endifIf MyPositionCount < 0 and floatingprofit > 20 thenMyPositionCount = 0MyPositionPrice = 0endifENDIFRETURN MyPositionCount AS "MyPositionCount"01/15/2021 at 4:39 PM #157952Lines 40 and 45 should read:
1MyPositionPrice1 - closeJust after line 58 (before line 59), insert:
1floatingprofit1 = (((MyPositionPrice1-close)*pointvalue)*abs(MyPositionCount))/pipsizeand at line 63 you should reference floatingprofit1.
-
AuthorPosts
Find exclusive trading pro-tools on