ramaParticipant
Senior
pr=2
mp=40
mp1=-30
floatingprofit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gains
if floatingprofit>=(mp or mp1) then
SELL AT close-pr stop
endif
floatingprofit = (((positionprice-close)*pointvalue)*countofposition)/pipsize //actual trade gains
if floatingprofit>=(mp or mp1) then
EXITSHORT AT close+pr stop
endif
I want to close all open positions short or long
if loss is >=30
or profit >=40
Just a thought … below won’t work if, for example, you are trying to exit within the bid-ask spread range (spread = 4 or more?).
I guess you’ve tried higher values for pr?
pr=2
SELL AT close-pr stop
EXITSHORT AT close+pr stop
COUNTOFPOSITION can be positive or negative which will completely mess up your calculations.
Also as GraHal says CLOSE +/- 2 will very likely be too close for a minimum order distance on most markets.
Isn’t COUNTOFPOSITION either 0 or greater?
When can it be negative?
@rama try below (AND increase pr > spread) … let us know if it works.
floatingprofit = (((close-positionprice)*pointvalue)*countoflongshares)/pipsize //actual trade gains
if floatingprofit>=(mp or mp1) then
SELL AT close-pr stop
endif
floatingprofit = (((positionprice-close)*pointvalue)*countofshortshares)/pipsize //actual trade gains
if floatingprofit>=(mp or mp1) then
EXITSHORT AT close+pr stop
endif
ramaParticipant
Senior
I am testing the new code, I have tried with PR =1 and MP=any value(without mp1 condition) it works well
I am trying to add loss in the same code that is where it has problem
try below and let us know
if (floatingprofit>= mp) or (floatingprofit <= mp1) then
ramaParticipant
Senior
I am running the program now with ,I will let you know the results
|
|
if (floatingprofit>= mp) or (floatingprofit <= mp1) then
|
COUNTOFPOSITION can be positive or negative
I think the definition in the manual should be tweaked to make that a bit more obvious. All it says at the moment is “Counts the number of open shares or lots.”
Can a clarification be added (eg “a buy position would should as +1 and a sell position would show as -1”)?
*when I say manual I mean here: https://www.prorealcode.com/documentation/countofposition/