ramaParticipant
Senior
I have a buy order
initial stop is 20
market went in my favor say to 30,40,50 etc
when market moves back I want keep 66 .6 profit
if longonmarket then
if ( x-close)<=.66*(close-tradeprice) then
sell at market
endif
endif
what is the X? how to code variable X
Try this one
IF LongOnMarket AND close > TradePrice THEN
x = (close - tradeprice) / pipsize //convert price to pips
IF x >= 30 THEN //go ahead only if 30+ pips
y = x * 0.666 //y = 66.6% of current profit
SELL AT close - (y * pipsize) STOP //convert pips to price
ENDIF
ENDIF
Roberto
I’ve added above to the Snippet Link Database
https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit?usp=sharing
Thank You @robertogozzi
Sorry GraHal, I forgot to (as I do most of times). Thanks for paying attention.
ramaParticipant
Senior
Thanks for your fast reply Roberto. I have am back testing this now, will take another 4 to 5 hours get decent result.
I my guess it may not work, as soon as the profit falls below the 30 , the stop will go to the original stop loss
I am keeping fingers crossed, I will post the results by EoD today
This trailing SL is hard coded in your strategy, not managed by ProOrder or your broker, it’s a pending order to be set at each new candle.
You may as well have set your stop ploss at, say 100 pips, but still exit in profit as this code is progressing candle after candle.
ramaParticipant
Senior
please find the screen shots
if max profit once gone past 30 say 36
I want keep stop loss .66(tradeprice+36) at least in the event market is coming back.
on the other hand if the profit goes to 60 i want keep .66(tradeprice+60)
I tested the code is not working, as the price keeps falling after >=30 SL coming down by .33%
Well… It works almost like that, but if it reaches 50 pips profit Y will be set to 33.3, but if the next candle decreases to 40 pips profit, it won’t keep 33.3 but will decrease to 26.6.
I will make a change.
This should work
IF Not OnMarket THEN
y = 0
ENDIF
IF LongOnMarket AND close > TradePrice THEN
x = (close - tradeprice) / pipsize //convert price to pips
IF x >= 30 THEN //go ahead only if 30+ pips
y = max(x * 0.666, y) //y = 66.6% of max profit
SELL AT close - (y * pipsize) STOP //convert pips to price
ENDIF
ENDIF
ramaParticipant
Senior
I am running the strategy on 3 sec or 5 seconds range.
it is keeping changing, the whole is ideas is keep some profits.
how above set stop loss trailing SL
SL=(1-y)
ramaParticipant
Senior
thanks, I am doing back testing, will update the feedback soon
ramaParticipant
Senior
I have back tested even modified code is not working
it strange.
LeoParticipant
Veteran
IF LongOnMarket AND close > TradePrice THEN
x = (close - tradeprice) / pipsize //convert price to pips
MaxX=MaxX=max(x,MaxX) //store the max profit during trade
IF x >= 30 THEN //go ahead only if 30+ pips
y = MaxX * 0.666 //y = 66.6% of current profit
SELL AT TradePrice + Y*pipsize STOP //convert pips to price
ENDIF
ENDIF
Try this.
Hello Léo
I don’t understand : MaxX=MaxX=max(x,MaxX)
could you explain me well detailed ??
ramaParticipant
Senior
back testing is on , collecting sample data before conclude whether the code works or not.