Stop Loss Problem
Forums › ProRealTime English forum › ProOrder support › Stop Loss Problem
- This topic has 17 replies, 3 voices, and was last updated 4 years ago by Nicolas.
-
-
08/07/2020 at 8:38 AM #141038
Good morning,
I have recently put Nicolas’s clever stop loss code :
SET STOP LOSS abs(close – (lowest[3](low) * pipsize))
into my code and it works beautifully.
My problem is that when in a trade, I want to limit the maximum $ loss of any single trade to $100 and I don’t immediately see how to do this whilst retaining the recent swing high/low stop loss code above.
I checked the forum and found reference to the following post:
https://www.prorealcode.com/blog/learning/max-profit-loss-day-trading-strategy/
BUT I can’t get it to work with the swing high/low code. It’s like the system just ignores my ‘max loss’ code resulting in many losses far in excess of $100 on the backtest.
See below for what I currently have (without my buy/sell conditions which just add clutter). Any help much appreciated.
Regards
Mark
1234567891011121314151617181920212223242526272829303132333435363738MaxLoss=100 //Max loss allowed(in $)// first time we launch the code, the trading is allowedonce TradeAllowed=1// reset the current state of the strateygprofit each new dayIf intradaybarindex=0 thenMyProfit=STRATEGYPROFITTradeAllowed=1endif// test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowedIf StrategyProfit<=MyProfit-MaxLoss thenTradeAllowed=0endif// if max $loss of 100 on long/short trade then following code should be executedIF LongOnMarket AND TradeAllowed=0 thenSell PositionSize contracts at marketendifIf ShortOnMarket AND TradeAllowed=0 thenExitshort PositionSize contracts at marketendif// BUY order codeIF NOT OnMarket AND buyCondition and TradeAllowed THENBUY PositionSize CONTRACTS AT MARKETSET STOP LOSS abs(close - (lowest[3](low) - 1 * pipsize))set target $profit 150ENDIF// SELL order codeIF NOT OnMarket AND sellCondition and TradeAllowed THENSELLSHORT PositionSize CONTRACTS AT MARKETSET STOP LOSS abs(close - (highest[3](high) + 1 * pipsize))set target $profit 150ENDIF08/07/2020 at 10:02 AM #141046Actually your line SET STOP LOSS abs(close – (lowest[3](low) * pipsize)) is wrong, LOSS does not require pips, but a difference between prices.
You could use PLOSS, instead, but in this case it should be “/ pipsize” and the closing parentheses are not in the correct place. It should be one of the following:
12SET STOP LOSS abs(close – lowest[3](low))SET STOP pLOSS abs(close – lowest[3](low)) / pipsizeBut in your case you can easily use:
1SET STOP $LOSS 1001 user thanked author for this post.
08/07/2020 at 2:12 PM #14107208/07/2020 at 7:11 PM #141110Hi Roberto,
Thanks for clarifying that the ‘pipsize’ term can simply be removed.
I know how to use the $LOSS function on its own but do you have any idea how to COMBINE the
abs(close – lowest[3](low)) AND $LOSS (max $100)
Depending on the entry candle of my trade, if the trade moves against me then the loss can be anywhere from $50-$150 (typically).
I would like the abs(close – lowest[3](low)) code to be used as my primary stop loss wherever possible EXCEPT when the loss becomes a value >$100 which is when my secondary $LOSS code executes to get me out.
Is this easily possible to do ?
Regards
Mark
08/07/2020 at 7:12 PM #141111It looks like I found it here:
https://www.prorealcode.com/topic/stop-loss-at-last-swing-low/
but it looks like (with hindsight) it was actually a post that Roberto was moderating.
Apologies for the mix up.
Regards
Mark
08/07/2020 at 9:32 PM #141122It was NOT an error, you simply copied it wrong!
08/08/2020 at 2:32 AM #141130It was not copied wrong Roberto, did you check the link with your post?
I think you’re missing the point… your code works perfectly for finding the swing low/high! (either with the word ‘pipsize’ included or without it).
My remaining issue however is trying to find a solution for combining the swing high/low code and a max $loss as I explained above. Can anyone help with this issue?
08/08/2020 at 2:43 AM #14113208/08/2020 at 3:06 AM #141133One of the rules you should have read clearly states:
- Do not include personal informationsuch as email addresses or telephone numbers in your posts.
Abide by it, please.
I removed your email address.
08/08/2020 at 3:15 AM #141134As for your code the line is correct, but your text is wrong, that’s what I remarked.
You can calculate the value by using both PIPSIZE and PIPVALUE (not tested):
12Sl = abs(close – lowest[3](low)) / PipSize * PipValueSet Stop $loss min(100,Sl)1 user thanked author for this post.
08/08/2020 at 3:17 AM #14113508/08/2020 at 3:25 AM #141136As a moderator I am supposed not to help, this can be done by anyone on this forum (myself included), but to remark what’s not correct in a post pointing out what the correct form is.
You, as a member of this community, are supposed to abide by the rules.
Thank you 🙂
08/08/2020 at 3:39 AM #14113708/08/2020 at 3:47 AM #141138I’m sorry if my requests have created a bit of tension between us. Obviously my goal is simply to get my code strategy sorted and if I can call upon either you or Nicolas’s expertise then it is of great help.
I am happy to pay for your services as I realize it takes a lot of effort and skill to acquire this knowledge which you give back freely to the community. That is greatly appreciated and I’m sure I speak for all newbies when I say that.
Regards
Mark
2 users thanked author for this post.
08/08/2020 at 8:04 AM #141139Hi Roberto,
I think I’m nearly there with the code BUT came across a perplexing problem a bit later.
When I apply the stop loss code on the DJI index (Wall St) in IG, it works perfectly as per your suggestion when applied to a PositionSize of £1/point.
When I increase PositionSize to 2 (or greater), the system no longer exits trades in the correct place.
P1 in pic below is the correct exit (the last swing high)
P2 in pic below is where the exit occurs when PositionSize is increased from ‘1’ to ‘2’
Note that when I increased the PositionSize to ‘2’, I also increased the stop loss and profit target e.g.
Set Stop $loss min(200,S1) //as opposed to Set Stop $loss min(100,S1)
Set target $profit 260 //as opposed to Set target $profit 130but it still exits incorrectly. Any idea what is going wrong when the PositionSize is increased?
Regards
Mark
1234567891011121314151617PositionSize = 1// BUY order codeIF NOT OnMarket AND buyCondition THENBUY PositionSize CONTRACTS AT MARKETSl = abs(close – lowest[3](low)-1) / PipSize * PipValueSet Stop $loss min(100,Sl)set target $profit 130ENDIF// SELL order codeIF NOT OnMarket AND sellCondition THENSELLSHORT PositionSize CONTRACTS AT MARKETSl = abs(close - highest[3](high) + 1)/ PipSize * PipValueSet Stop $loss min(100,Sl)set target $profit 130ENDIF -
AuthorPosts
Find exclusive trading pro-tools on