how to code to calculate an average of two inputs
Forums › ProRealTime English forum › ProOrder support › how to code to calculate an average of two inputs
- This topic has 5 replies, 2 voices, and was last updated 3 years ago by
Nicolas.
-
-
06/08/2022 at 9:59 PM #194948
hello, I ask you for help please
How can the bot recalculate the profit when I do two inputs at differentt price?
that is, after putting a second entry, how can I code so that the bot can calculate the average of both entries leaving the initial stoploss of the first entry and have a positive exit?
06/09/2022 at 7:48 AM #19495206/09/2022 at 7:53 AM #194954I explain myself better. The code makes an entry (it is executing a stoploss) if it is placed in the opposite direction to the entry, how can I make it make a second entry and do the average between the first and the second and the operation comes out positive? that without modifying the initial stoploss
06/09/2022 at 9:04 AM #194958Sorry I dont get it 🙂
- Do you want to cover your floating loss with an opposite order?
- The second order is of the same type of the first one?
- When the second order is opened, the first one is still at market or triggered its stoploss already?
1 user thanked author for this post.
06/09/2022 at 10:55 AM #1949691. Do you want to cover your floating loss with an opposite order? NO
2. Is the second order of the same type as the first? YES
3. When the second order is opened, is the first one still in the market or has it already triggered its stoploss? Stay in the market and follow the stop of the initially open position
I give an example: I buy at 12100 (stop at 12090) and it falls to 12000, increase the position bot (buy again and the stop remains at 12090). Once you have opened the second position take an average of both positions and recalculate a positive exit again.
06/10/2022 at 8:40 AM #195011Ok here is a dummy strategy that simulate that behavior (averaging down the first order only 1 time, and exit if the profit is positive)
1234567891011121314151617181920defparam cumulateorders=truedefparam preloadbars=0buyc = rsi[14]crosses over 50//first orderif not longonmarket and buyc thenbuy 1 contract at marketset stop ploss 100endif//averaging down the first order at 20 points in lossif longonmarket and tradeprice-close>=20 and countofposition<2 thenbuy 1 contract at marketendif//put the exit in positive areaif longonmarket and countofposition=2 thenset target price positionprice+1endif1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on