Hi there,
I wondered if I could have some help coding an algo idea that I have, I’m trying to get PRT to take a trade on the open of the red candle (with the red arrow) on the attached.
This is the trade entry criteria for the order;
For a short
Close < VWAP
close < close[1]
close[1] > close[2]
close[2] > close[3]
Open = High (No wick on top of candle)
Stop = High[1]
Target = 2 x Stop
Any help would be greatly appreciated.
AH
Your screenshot doesn’t seem to have HA candlesticks plotted?
Here is the code using HA candlesticks:
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen[1] + xClose[1]) / 2
endif
//xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
myVWAP, my1, my11, my2, my21, my3, my31 = CALL "VWAP - SMF"
c1 = xClose < myVwap
c2 = xClose < xClose[1]
c3 = xClose[1] > xClose[2]
c4 = xClose[2] > xClose[3]
c5 = xOpen = xHigh
Cond = c1 AND c2 AND c3 AND c4 AND c5 AND Not OnMarket
SL = xHigh[1]
TP = SL * 2
IF Cond THEN
SELLSHORT 1 CONTRACT AT MARKET
SET STOP PRICE SL
SET TARGET PRICE TP
ENDIF
@Roberto
could we kindly have also the opposite in order to send a BUY order ?
many thanks in advance
First of all I noticed a bug in the code, regarding the TP calculations. This is the amended code:
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen[1] + xClose[1]) / 2
endif
//xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
myVWAP, my1, my11, my2, my21, my3, my31 = CALL "VWAP - SMF"
c1 = xClose < myVwap
c2 = xClose < xClose[1]
c3 = xClose[1] > xClose[2]
c4 = xClose[2] > xClose[3]
c5 = xOpen = xHigh
Cond = c1 AND c2 AND c3 AND c4 AND c5 AND Not OnMarket
SL = xHigh[1]
TP = xClose - (abs(xClose - SL) * 2)
IF Cond THEN
SELLSHORT 1 CONTRACT AT MARKET
SET STOP PRICE SL
SET TARGET PRICE TP
ENDIF
then here is the code with both entries:
once xOpen = open
xClose = (open + close + high + low) / 4
if barindex > 0 then
xOpen = (xOpen[1] + xClose[1]) / 2
endif
xLow = min(low,min(xClose,xOpen))
xHigh = max(high,max(xClose,xOpen))
myVWAP, my1, my11, my2, my21, my3, my31 = CALL "VWAP - SMF"
//
b1 = xClose > myVwap
b2 = xClose > xClose[1]
b3 = xClose[1] < xClose[2]
b4 = xClose[2] < xClose[3]
b5 = (xOpen = xLow)
//
c1 = xClose < myVwap
c2 = xClose < xClose[1]
c3 = xClose[1] > xClose[2]
c4 = xClose[2] > xClose[3]
c5 = (xOpen = xHigh)
//
CondB = b1 AND b2 AND b3 AND b4 AND b5 AND Not OnMarket //LongOnMarket for S&R
CondC = c1 AND c2 AND c3 AND c4 AND c5 AND Not OnMarket //ShortOnMarket for S&R
//
IF CondB THEN
BUY 1 CONTRACT AT MARKET
SL = xLow[1]
TP = xClose + (abs(xClose - SL) * 2)
SET STOP PRICE SL
SET TARGET PRICE TP
ENDIF
//
IF CondC THEN
SELLSHORT 1 CONTRACT AT MARKET
SL = xHigh[1]
TP = xClose - (abs(xClose - SL) * 2)
SET STOP PRICE SL
SET TARGET PRICE TP
ENDIF
//graphonprice SL coloured("Red")
//graphonprice TP coloured("Blue")
Is the VWAP – SMF Indicator in the Library please (under another name?)?
Yes, I used the f symbol to automatically insert the CALL instruction and the code of the indicator was not visible as it’s a built-in proprietary code.
In any case a different VWAP indicator can be used, despite some differences in the returned data. But VWAP is almost impossible to replicate exactly.
Just CALL another one.