Hi,
I want to write a code so that the breakeven is equal to the price the position was bought for. The system buys 2 contracts initially and sells one after X number of pips, I want the breakeven of the second contract to be set at the entryprice + 2 pips so the 2nd contract can follow a trailing stop instead.
When I try with:
if size = 1 then
breakevenLevel = entryPrice + PointsToKeep * pipsize Pvalue = breakevenLevel + 2 * pipsize
It sells the 2nd contract based on where to first sell of the 1st contract took place. I want it to be based on the initial postion instead.
I´ve also tried with tradeprice (1) instead of entryprice but that seems to refer to the previous latest trade of selling 1 contract instead of the initial price when I bought the position.
anyone have any idea on how I can solve this?
With kind regards, Victor
First you have to store the Entry Price on the first entry bar (which is when it’s OnMarket, but it wasn’t the prior bar).
Then SET the stop whenever you have reduced the position size:
IF OnMarket AND Not OnMarket[1] THEN
EntryLevel = Tradeprice
BreakEvenLevel = EntryLevel + (PointsToKeep * pipsize)
ENDIF
IF abs(CountOfPosition) < abs(CountOfPosition)[1] then
SET STOP PRICE BreakEvenLevel
ENDIF
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR.
For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com
If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.
Get Assistance
Assistance Type
Your Need
Proposed Solutions
Do you like cookies? 🍪 We use cookies to ensure you get the best experience on our website.
(Learn more)