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?
The average price of orders open price is POSITIONPRICE
So for 2 buy orders, the profit is positive above POSITIONPRICE.
I 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
1. 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.
Ok here is a dummy strategy that simulate that behavior (averaging down the first order only 1 time, and exit if the profit is positive)
defparam cumulateorders=true
defparam preloadbars=0
buyc = rsi[14]crosses over 50
//first order
if not longonmarket and buyc then
buy 1 contract at market
set stop ploss 100
endif
//averaging down the first order at 20 points in loss
if longonmarket and tradeprice-close>=20 and countofposition<2 then
buy 1 contract at market
endif
//put the exit in positive area
if longonmarket and countofposition=2 then
set target price positionprice+1
endif