I would like one of the conditions in the algorithm to depend on the direction of the last trade.
An example for simplicity: IF some set of conditions are met AND the last trade was a short position THEN take a long position… and vise versa.
I haven’t been able to find an easy solution to call the last trade direction, so any help would be greatly appreciated!
.
.
ONCE LastTradeDirection = 0
.
.
IF LongOnMarket THEN
LastTradeDirection = 1 //1 = last trade went LONG
ELSIF ShortOnMarket THEN
LastTradeDirection = 2 //2 = last trade went SHORT
ENDIF
.
.
.
.
You need to set a variable when you either go LONG or SHORT, so that it will later let you know if the last trade was going northwards or southwards. If trades are open not so frequently you might decide to reset the variable to ZERO after “n” candlesticks have elapsed. It’s up to you.
Roberto
Hi,
I am using a solution like the above which works fine for last trade direction but not if the trade opens and closes within the same bar. In that circumstance the variable does not change because we are Not OnMarket at the close of the bar.
I have tried various solutions but just can’t seem to nail it.
Any suggestions would be much appreciated.
Thanks, Matt
This snippet will do:
// current version
//
TradeFlag = 0 //1=Long, 2=Short
IF StrategyProfit > StrategyProfit[1] THEN
IF TradePrice(1) > TradePrice(2) THEN
TradeFlag = 1
ELSE
TradeFlag = 2
ENDIF
ELSIF StrategyProfit < StrategyProfit[1] THEN
IF TradePrice(1) < TradePrice(2) THEN
TradeFlag = 1
ELSE
TradeFlag = 2
ENDIF
ENDIF
it will only work when you do not accumulate trades.
But you can also use these new instructions to tell Long from Short trades (
https://www.prorealcode.com/documentation/shorttriggered/):
ShortTriggered[N]
LongTriggered[N]
N is the bar reference [1], [2], ec… [0] is assumed by default and can be omitted.