logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
StorkBite  
#1 Posted : Saturday, March 11, 2006 2:34:35 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Thought I'd share this profit tracker code that I made... I'm sure it must have been done before, but I couldn't find it. Comments welcome. [code:1:31dc3b46b3]{ ProfitCalc by g_stockman, 2006 } i1:=Input("Share purchase price",0,1000,0); i2:=Input("Number of shares purchased",0,50000,0); i3:=Input("Brokerage Fee",0,25,8); i4:=Input("Desired Profit %",0,100,7); i5:=Input("StopLoss %",-100,0,-15); i6:=Input("Plot: 1=$, 2=%, 3=signals",1,3,1); { p/l calculations } CB:=(i1*i2)+i3; PLD:=(C*i2)-cb; PLP:=(PLD/CB)*100; { signals } up:=If(PLP>=i4,1,0); dn:=If(PLP<=i5,-1,0); plot:= If(i6=1,PLD, If(i6=2,PLP, If(up=1 AND BarsSince(Ref(up, -1)) > 0,1, If(dn=-1 AND BarsSince(Ref(dn, -1)) > 0,-1,0)))); If(i6=3,plot,0); plot[/code:1:31dc3b46b3]
Jose  
#2 Posted : Saturday, March 11, 2006 5:59:36 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
I would add a zero output to the last line, so that the indicator plots something when values are out of range: [code:1:950c7cfe5a]... 0;plot [/code:1:950c7cfe5a] jose '-)
StorkBite  
#3 Posted : Saturday, March 11, 2006 6:56:16 PM(UTC)
StorkBite

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 3/19/2005(UTC)
Posts: 2,995

Was thanked: 14 time(s) in 10 post(s)
Thanks for the suggestion, Jose. I tinkered with that thought, hence the line 'If(i6=3,plot,0)'. I just got near-sighted. Now, I'll eliminate that line and go with just a plain 'plot;0' instead. Thanks... I'm still in the back of the class. Hey, where's Patrick?! :lol: [code:1:09a2e3de53] {_g4_ProfitCalc v1.1, g_stockman, 2006} { user inputs } i1:=Input("Share purchase price",0,1000,0); i2:=Input("Number of shares purchased",0,50000,0); i3:=Input("Brokerage Fee",0,25,8); i4:=Input("Desired Profit %",0,100,7); i5:=Input("StopLoss %",0,100,15); i6:=Input("Plot: 1=$, 2=%, 3=signals",1,3,1); { p/l calculations } CB:=(i1*i2)+i3; PLD:=(C*i2)-cb; PLP:=(PLD/CB)*100; { signals } up:=If(PLP>=i4,1,0); dn:=If(PLP<=-i5,-1,0); { plot } plot:= If(i6=1,PLD, If(i6=2,PLP, If(up=1 AND BarsSince(Ref(up, -1)) > 0,1, If(dn=-1 AND BarsSince(Ref(dn, -1)) > 0,-1,0)))); 0;plot [/code:1:09a2e3de53] Addendum: re: zero reference avoidance- "It's probably better to place the zero plot before the plot line end, so that if the indicator gets referenced then it won't reference a zero value." Also, changed that weird stoploss input.
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.