Trailingstop vid graphonprice
Forums › ProRealTime English forum › ProOrder support › Trailingstop vid graphonprice
- This topic has 8 replies, 3 voices, and was last updated 2 weeks ago by druby.
-
-
10/13/2024 at 11:55 AM #238929
Hi,
Im trying to use an algo with a trailingstop, but the trailingstop dosent seem to be working as intended
Does anyone know a code with a working trailingstop that you can use with graphonprice so I can view the behavior of the trailingstop?Im using a similar code like this:
1234567891011121314151617181920212223242526272829303132333435363738//points trailing stop functiontrailingstart = tst //trailing will start @trailinstart points profittrailingstep = st //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF10/13/2024 at 12:39 PM #238932Did you try below
12GRAPH NewSLGRAPHONPRICE NewSL2 users thanked author for this post.
10/14/2024 at 4:48 PM #238985Did you try below
12GRAPH NewSLGRAPHONPRICE NewSLHi,
I haven’t been able to try the code yet, but I will tomorrow. Will get back to you with the results 🙂
Btw, is there a way to access prt from your phone? I’m using prt through IG…
Thank you 🙂
10/14/2024 at 5:16 PM #238987There is a web based version, but no AutoTrading yet.
Compare 3 versions on the link below
https://www.prorealtime.com/en/compare-trading-platforms
10/15/2024 at 11:54 AM #23901410/15/2024 at 6:46 PM #23903210/16/2024 at 8:04 AM #23903710/16/2024 at 9:03 AM #239039When Algo is trading Live all we get to see is equity curve and positions.
GRAPHS and GRAPHONPRICE are best for debugging Stops and Taget and Trailing Stops etc, but only when backtesting Algos.
To check performance before going Live, we use our Demo Accounts … have you enabled your PRT Demo Account? It is enabled on the IG Dashboard.
10/16/2024 at 4:09 PM #239088I think there’s an error in above code, lines 14 and 18 appear to set newSL with none zero value, however, lines 35 and 36 look for a none zero newSL and exits.
Similar scenario for the short.
I played around with some code to display the trailing stop (TS) to see what’s what using a out of thin air entry condition.
I added in a default TS value , TSdefaultAmt, because zero messes with the charts auto scale with graphonprice.
When the yellow line is horizontal, it represents the TS start threshold level above the entry price , TSstartLvl.
When price closes above, the TS is active, TSactive = 1, which triggers the TS.
After entry but before TS triggered, The horizontal orange line represent the default TS.
After being triggered, TS jumps to the startprice + step amount.
Subsequent bars increment the TS ‘TSL’ by the step amount.
If close triggers the exit condition, the trade is exited.
If low hits the default stop level it is also exited.
As I worked through I graphed some variables.
Some are true/false and some are number values.
Using cursor values…
The values are scaled within a ‘1’ range and +n value offset then to the ‘y’ scale.
The *0.75 are the booleans where the integer value is false and value+0.75 is true.
The*0.00001 are values, just look at decimal portion and crop off last digit.
see what you think.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273entryCondition = date = 20241016 and opentime >= 000000TSdefaultAmt = 30 // TS default stop levelTSstartAmt = 15 // TS threshold setting amountTSstepAmt = 1 // TS step amount per step// difference between Current price and last Trade entryCTdiff = close-tradePrice[1]// get the TS threshold levelTSstartLvl = tradeprice[1] + TSstartAmt// set a default TS stopTSdefaultL = close - TSdefaultAmt// new TS stepCmTSL = Close - TSL// not on marketif not LongonMarket thenLONG = 0TSactive = 0// enter Marketif entryCondition thenbuy 1 contract at market// set a default TSTSL = TSdefaultLendifendif// on Marketif LongonMarket thenLONG = 1if close >= TSstartLvl and TSactive = 0 thenTSactive = 1TSL = tradePrice[1] + TSstepAmtendifif TSactive =1 and CmTSL >= TSstepAmt thenTSL = TSL + TSstepAmtendif// if close below TSLif close <= TSL thensell at marketendif// exit if low hits default stop levelif low <= tradePrice[1] - TSdefaultAmt thensell at marketendifendif// displayif onmarket thengraphonprice TSstartLvl as"TSstartLvl" coloured("yellow")graphonprice TSL as"TSL" coloured("orange")endifgraph TSactive * 0.75 + 5 as"TSactive"graph TSstartLvl * 0.00001 + 4 as"TSstepLvl"graph TSstepAmt * 0.00001 + 3 as"TSstepAmt"graph TSstartAmt * 0.00001 + 2 as"TSstartAmt"graph TSdefaultAmt * 0.00001 + 1 as"TSdefaultAmt"graph LONG * 0.75 + 0 as"LONG" -
AuthorPosts