• Get $40 off VIP by signing up for a free account! Sign Up

Issues with position limits and entry orders in the same direction

Ramisegal

Active member
Plus
In thinkscript the entry price(s) is averaged with every new position in the same direction though in the strategy report it is itemized per transaction.
In the attached image the bubbles display on entry price change (including consecutive long or short) with the delta value of the fpl value from the prior value which is captured on every entry price change.

When the strategy is configured for more than 1 contract the calculated value of the fpl is only for a single contract as a 1/n of the total pnl but on the strategy report it is itemized and summed for all the contracts when the position closes.

Could someone help figure this out?

The example below is using a built- in strategy from thinkorswim but any strategy with consecutive entries will display the same issue.


My9qocf5avvFTjKllrK_GcpqwkT00crNu-kRmwFSvFKyt1SecN4z3XCOm-oHgrM3MEKRlloOJ3tpelf3SuVnLHHF1GxrZfQgCseJVbjZiBg-m6r_DHGJW5XOVuIsAg-zHLyhDQ4FxJQTLVbe2cXoCmY





OVWQSxAla2SlTMN2--d3O5RAxZNt5J7LvU2t9Lt7sPtMTQe169drifJPtW-_ukeADSJAJZRDZjpJ91DKp1RrLcd03vAsHWmAfUwise-c3PaGOUO1-T_v9RAJfDkwM7k1Keb3IHhIObw_pT76WLTPIN8




Code for the bubbles display (must be saved as a strategy)
Code:
##Begin
##
addOrder(OrderType.BUY_AUTO, no); #dont change this line
input enableDashBoard = yes;
input ShowStrategyCurrentPnlBubble = yes;
input ShowStrategyPnlBubble = no;
input ShowStrategyPnlEntryBubble = yes;
input ShowStrategyPnlVertical = no;

def fpl = FPL();
def StrategyEntryprice = if IsNaN(EntryPrice())  then 0 else EntryPrice();
def ep = entryprice();
def poschange = ( StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice == 0 ) or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] == 0  )   or (  StrategyEntryprice <> StrategyEntryprice[1] and StrategyEntryprice[1] > 0   and StrategyEntryprice[0] > 0 );
def pnlentry =  if  poschange  then  fpl[1] else pnlentry[1];
def currentprofit = fpl - pnlentry[1];
def pnlprofit =  if pnlentry <> pnlentry[1] then  fpl[0] - pnlentry[0] else 0  ;
def entryprofit = (if pnlprofit> 0 then 1 else -1 )  * absValue( if  poschange  then if StrategyEntryprice == 0 then open[0] - ep[1] else ep-ep[1] else 0) ;
def dollarentryprofitloss = Round(((entryprofit ) / TickSize()) * TickValue());

AddChartBubble(enableDashBoard and ShowStrategyPnlEntryBubble and poschange and absValue(dollarentryprofitloss  )>0, open[0], AsDollars(dollarentryprofitloss[0]), if dollarentryprofitloss[0] > 0 then Color.light_GREEN else if  dollarentryprofitloss[0] < 0 then Color.pink else Color.BLUE);
AddVerticalLine(ShowStrategyPnlVertical and ShowStrategyPnlEntryBubble and poschange, AsDollars(fpl) + " (" + dollarentryprofitloss + ")" ,  if dollarentryprofitloss > 0 then Color.GREEN else if dollarentryprofitloss < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);

def fplpnlprofit = pnlprofit;
AddChartBubble(enableDashBoard and ShowStrategyPnlBubble and poschange[0] and absValue(fplpnlprofit  )>0, open[0], AsDollars(fplpnlprofit[0]), if fplpnlprofit[0] > 0 then Color.GREEN else if  fplpnlprofit[0] < 0 then Color.RED else Color.BLUE);
AddVerticalLine(enableDashBoard and ShowStrategyPnlVertical and ShowStrategyPnlBubble and poschange, AsDollars(fpl) + " (" + pnlprofit + ")" ,  if pnlprofit > 0 then Color.GREEN else if pnlprofit < 0 then Color.RED else if pnlentry == 0 then Color.WHITE else Color.CYAN);
def lastentry =if isnan( entryprice()) then lastentry[1] else entryprice() ;
AddChartBubble(enableDashBoard and ShowStrategyCurrentPnlBubble  and !IsNaN(close) and IsNaN(close [-1] ) and HighestAll(BarNumber()) and absValue(currentprofit)> 0, lastentry, AsDollars(currentprofit[0]), if currentprofit[0] > 0 then Color.green else if  currentprofit[0] < 0 then Color.red else Color.BLUE);

##
##End
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
264 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top