Custom Indicator Request PSAR
Hello Tiki and All - I'm hoping someone can convert the Parabolic SAR code I use on TOS so that I can use it here on Tradovate. It's a custom indicator request because there are modifications to the existing Tradovate PSAR indicator that I find really helpful. Thank you and here's the code I'd like to have converted to Tradovate
###########################
# sdi_psarstgy:
#hint:Strategy to evaluate trading parabolic-stop-and-reverse signals http://www.smallDogInvestor.com rev:1.1.0
# author: allen everhart
# date: 16may2014
# revisions:
# 4jun2014-added %win label, corrected reverse price on gaps
input dollarsPerTrade = 10000;
#hint dollarsPerTrade: trades vary in share size in order to keep the invested dollars constant to create a fair comparison to passive strategies. http://www.smallDogInvestor.com rev: 1.1.0
input accelerationFactor = 0.02;
#hint accelerationFactor: controls how steep a parabola is traced by the stop.
input accelerationLimit = 0.2;
#hint accelerationLimit: after the limit is reached the stop moves up in a straight line.
def psar = ParabolicSAR( "acceleration limit" = accelerationLimit, "acceleration factor" = accelerationFactor);
def buySig = close crosses above psar;
def sellSig = close crosses below psar;
def shareSize = round(dollarsPerTrade/psar,0) ;
def buyPrice=#psar;
if open[-1]>psar then open[-1]
else psar;
def sellPrice= #psar;
if open[-1]<psar then open[-1]
else psar;
AddOrder(OrderType.BUY_AUTO, buySig[-1], price = buyPrice, tradeSize=shareSize, name = "buy");
AddOrder(OrderType.SELL_AUTO, sellSig[-1], price = sellPrice, tradeSize=shareSize, name="short");
plot parSAR = psar;
parsar.setPaintingStrategy(paintingStrategy.POINTS);
parSar.setDefaultColor(color.rED);
def longPrice=compoundValue(1,
if !longPrice[1] && buySig[-1] then buyPrice
else if longPrice[1] && sellSig[-1] then 0
else longPrice[1]
,0
);
#plot lp=longPrice;
def shortPrice=compoundValue(1,
if !shortPrice[1] && sellSig[-1] then sellPrice
else if shortPrice[1] && buySig[-1] then 0
else shortPrice[1]
,0
);
#plot sp=shortPrice;
def wincntr= compoundValue(1,
if longPrice[1] && sellSig[-1] && sellPrice>longPrice[1] then wincntr[1]+1
else if shortPrice[1] && buySig[-1] && shortPrice[1]>buyPrice then wincntr[1]+1
else wincntr[1]
,0
);
def winNum=if isnan(wincntr) then winNum[1] else wincntr ;
def losscntr= compoundValue(1,
if longPrice[1] && sellSig[-1] && sellPrice<=longPrice[1] then losscntr[1]+1
else if shortPrice[1] && buySig[-1] && shortPrice[1]<=buyPrice then losscntr[1]+1
else losscntr[1]
,0
);
def lossNum=if isnan(lossCntr) then lossNum[1] else lossCntr ;
addlabel(1,
concat( "win: ",
concat( round( 100*winNum/(winNum+lossNum),1),
concat( "% of ", winNum+lossNum))),
color.BLUE);
#####################
-
Hi Dave - Thanks much and here's a screen shot of how I use PSAR in TOS. I should note this install in TOS is as a strategy not a study. That's perhaps why it didn't show for you and here's a link for help with Strategy installations http://www.smalldoginvestor.com/2011/06/how-to-get-one-of-my-studies.html
Thanks again, Bob

Please sign in to leave a comment.


Comments
6 comments