Firstly, I would like to thank everyone for creating such an amazing community.
I need a little coding help with the trailing stop algo –
Scenario: Buy Long
Preconditions:
- BUY long 1 contract
- Using the Trailing STOP function from snippet library
- TrailingStart set to 200 pips
- Trailing Step set to 15 pips
During trade:
- Profit reaches 175 pips
- Starts to retrace to 100 pips
I want to:
- Take profit @ 100 pips
- Open another BUY long trade immediately.
Similiar flow for short SELL
Is it a profitable approach?
If yes, can you help me code this or direct me to relevant documentation?
Thanks in advance.
This should do, but couldn’t test it, nor check syntax errors, if any:
Once TriggerPips = 175 * pipsize
Once CloseTrigger = 100 * pipsize
Once TPflag = 0 //will be set to 1 when TP reaches 175 pips
If not OnMarket then
TPflag = 0
MyProfit = 0
Endif
If LongOnMarket then
MyProfit = Close - PositionPrice
Elsif ShortOnMarket then
MyProfit = PositionPrice - close
Endif
If MyProfit >= TriggerPips Then
TPflag = 1
Endif
If TPflag And MyProfit <= CloseTrigger Then
TPflag = 0
MyProfit = 0
NewSL = 0
If LongOnMarket Then
Sell at Market
Buy 1 Contract at Market
Elsif ShortOnMarket Then
Exitshort at Market
Sellshort 1 contract at Market
Endif
Endif
Thanks @robertogozzi, will test it and let you know how it goes.
Cheers.