Help with increase/decrease in number of contracts in steps
Forums › ProRealTime English forum › ProOrder support › Help with increase/decrease in number of contracts in steps
- This topic has 10 replies, 3 voices, and was last updated 2 years ago by MaoRai54.
Tagged: ahort, contracts, decrease, increase, long, lotsize, performance, positionsize, strategyprofit
-
-
11/22/2020 at 3:51 PM #151224
Hi!
I’m a rookie and I’m having trouble to create a code that increases and decreases the number of contracts based on profits/losses.
I need a code that’s increasing contracts by 0.25 for every 350$ profit. So if a single trade profits 700$ that would mean that the system should increase with two steps immediately (increase with 0.5 contracts in this example).
The same if it loses a single trade for 1050$ then it would need to decrease contracts with three steps (0.75 contracts in this example).
I have searched a lot on the forum without finding anything that works the way I want it to. Everything I found does not take into account if a trade make a huge profit or a huge loss, that it need to increase/decrease several steps at once.
If anyone could help me to create this code I would be extremely grateful!
Regards
The rookie
11/22/2020 at 4:26 PM #151227There you go (not tested):
1234Once MinSize = 0.5 //minimum sizecrequiredOnce LotSize = MinSize //starting size (can be bigger than minimum)Once LotStep = 250 //increase/decrease this money stepLotSize = max(MinSize,MinSize + round(StrategyProfit / LotStep) //update LotSize11/22/2020 at 4:34 PM #151229Sorry, line 4 should read:
12LotSize = max(MinSize,MinSize + (MinSize * round(StrategyProfit / LotStep)))1 user thanked author for this post.
11/22/2020 at 6:40 PM #151236Thank you!! I’m gonna try it later tonight!
08/14/2022 at 12:49 PM #199043Hi to everybody here.
Well, I found this topic and it seems interesting to me. I tried to add it into a strategy running in demo and I got different results on long and short trades.
Then I modified it as follows (just setting different quantities and profit amount for short and long trades) but I can’t find a way to obtain the strategyprofit only for long trades and/or for short ones. Is there any way to know the profit generated by long or short trades ????
// for LONG trades
Once MinSizeL = 1 //minimum sizecrequired
Once LotSizeL = MinSizeL //starting size (can be bigger than minimum)
Once LotStepL = 250 //increase/decrease this money step
LotSizeL = max(MinSizeL,MinSizeL + (MinSizeL * round(StrategyProfit / LotStepL)))
myLotL=LotSizeL// for SHORT trades
Once MinSizeS = 1 //minimum sizecrequired
Once LotSizeS = MinSizeS //starting size (can be bigger than minimum)
Once LotStepS = 250 //increase/decrease this money step
LotSizeS = max(MinSizeS,MinSizeS + (MinSizeS * round(StrategyProfit / LotStepS)))
myLotS=LotSizeSMany thanks !!!!!!!!!!!!!
08/14/2022 at 4:51 PM #199054This snippet should to, to split STRATEGYPROFIT into two parts, Long and Short performances (not tested):
123456789ONCE LongProfit = 0ONCE ShortProfit = 0IF StrategyProfit <> StrategyProfit[1] THENIF LongOnMarket[1] THENLongProfit = LongProfit + (StrategyProfit - StrategyProfit[1])ELSIF ShortOnMarket[1] THENShortProfit = ShortProfit + (StrategyProfit - StrategyProfit[1])ENDIFENDIF1 user thanked author for this post.
08/14/2022 at 5:18 PM #19905508/15/2022 at 11:19 AM #199079There was an issue when a single-bar trade occurred, with this modification everything seems to work fine (tested on DAX, Daiky TF):
123456789101112131415161718192021222324252627282930313233343536373839404142434445ONCE LongProfit = 0ONCE ShortProfit = 0IF StrategyProfit <> StrategyProfit[1] AND BarIndex > 0 THENProfitto = StrategyProfit - StrategyProfit[1]IF LongOnMarket[1] THENLongProfit = LongProfit + ProfittoELSIF ShortOnMarket[1] THENShortProfit = ShortProfit + ProfittoELSEp1 = 1p2 = 2IF OnMarket THENp1 = 2p2 = 3ENDIFIF TradePrice(p1) > TradePrice(p2) THENIF Profitto > 0 THENLongProfit = LongProfit + ProfittoELSEShortProfit = ShortProfit + ProfittoENDIFELSIF TradePrice(p1) < TradePrice(p2) THENIF Profitto < 0 THENLongProfit = LongProfit + ProfittoELSEShortProfit = ShortProfit + ProfittoENDIFELSELongProfit = LongProfit + (Profitto / 2)ShortProfit = ShortProfit + (Profitto / 2)ENDIFENDIFENDIFif close crosses over average[200,0](close) thenbuy at marketelsif close crosses under average[200,0](close) thensellshort at marketendifset target pprofit 600set stop ploss 200//GRAPH StrategyProfit coloured(0,0,0,255) //BlackGRAPH LongProfit coloured(0,128,0,155) //GreenGRAPH ShortProfit coloured(255,0,0,255) //RedGRAPH LongProfit + ShortProfit coloured(0,0,255,255) //Blue1 user thanked author for this post.
08/15/2022 at 1:30 PM #199082Dear ROBERTO,
many thanks for spending your time about this issue. I will try your new system but I think is missing the part regarding the definition of buy/sell number of contracts . Here below I added a part of your previous reply to let the system calculate the contract q.ty based on profit levels (SEE BOLD WORDS). Do you think it’s OK in this way ????
ONCE LongProfit = 0
ONCE ShortProfit = 0
IF StrategyProfit <> StrategyProfit[1] AND BarIndex > 0 THEN
Profitto = StrategyProfit – StrategyProfit[1]
IF LongOnMarket[1] THEN
LongProfit = LongProfit + Profitto
ELSIF ShortOnMarket[1] THEN
ShortProfit = ShortProfit + Profitto
ELSE
p1 = 1
p2 = 2
IF OnMarket THEN
p1 = 2
p2 = 3
ENDIF
IF TradePrice(p1) > TradePrice(p2) THEN
IF Profitto > 0 THEN
LongProfit = LongProfit + Profitto
ELSE
ShortProfit = ShortProfit + Profitto
ENDIF
ELSIF TradePrice(p1) < TradePrice(p2) THEN
IF Profitto < 0 THEN
LongProfit = LongProfit + Profitto
ELSE
ShortProfit = ShortProfit + Profitto
ENDIF
ELSE
LongProfit = LongProfit + (Profitto / 2)
ShortProfit = ShortProfit + (Profitto / 2)
ENDIF
ENDIF
ENDIF
// for LONG trades
Once MinSizeL = 1 //minimum sizecrequired
Once LotSizeL = MinSizeL //starting size (can be bigger than minimum)
Once LotStepL = LL200 //250 //increase/decrease this money step
LotSizeL = max(MinSizeL,MinSizeL + (MinSizeL * round(LongProfit / LotStepL)))
myLotL=LotSizeL
// for SHORT trades
Once MinSizeS = 1 //minimum sizecrequired
Once LotSizeS = MinSizeS //starting size (can be bigger than minimum)
Once LotStepS = LS200 //250 //increase/decrease this money step
LotSizeS = max(MinSizeS,MinSizeS + (MinSizeS * round(ShortProfit / LotStepS)))
myLotS=LotSizeS
if close crosses over average[200,0](close) then
buy myLotL contract at market
elsif close crosses under average[200,0](close) then
sellshort myLotS contract at market
endif
set target pprofit 600
set stop ploss 200
//
08/15/2022 at 2:36 PM #199084Mine is just the way to split STRATEGYPROFIT into its two components, Short and Long.
You seem to have used it correctly.
1 user thanked author for this post.
08/15/2022 at 3:07 PM #199086 -
AuthorPosts
Find exclusive trading pro-tools on