hey there, are you asking about making this work so TOS takes orders for you? if so this cannot be doneI like this code, I havent tried it out live yet but i spent a lot of time this weekend trying it out with the on demand feature and it was successful much more than unsuccessful on the 30 minute chart, I hacked this code up a little trying to add the position size calculator to it. I can get the labels to show for the position size calculator but i cant figure out how to get them to show in the "add order" portion of the code so that it give real time live position to take according to account size and also realistically give what your P/L would be if you traded according to the back test trade report. Lines 320 through 344 are the code i hacked up to work,. can someone possible try to make the add order portion to
Code:#A.URExPELONSAX - CUSTOM ORB-FTFC STRATEGY AddLabel(yes, “ ORBxSTRATxMA.1 ”, color.yellow); input OpenRangeMinutes = 5; input MarketOpenTime = 0930; input StartTime = 0930; input MarketCloseTime = 1105; input Time_Frame = AggregationPeriod.FOUR_HOURS; input Time_Frame2 = AggregationPeriod.DAY; input MA_TimeFrame = AggregationPeriod.DAY; input ShowTodayOnly = no; input price = close; input securityType = { default "stocks"}; #--------- Choose Target ---------- input use_T1 = no; input use_T2 = no; input use_T3 = yes; input use_T4 = yes; input use_T5 = yes; input use_T6 = yes; #--------------ORB----------------- def Today = if GetDay() == GetLastDay() then 1 else 0; def FirstMinute = if SecondsFromTime(MarketOpenTime) < 60 then 1 else 0; def OpenRangeTime = if SecondsFromTime(MarketOpenTime) < 60 * OpenRangeMinutes then 1 else 0; def ORHigh = if FirstMinute then high else if OpenRangeTime and high > ORHigh[1] then high else ORHigh[1]; def ORLow = if FirstMinute then low else if OpenRangeTime and low < ORLow[1] then low else ORLow[1]; plot OpenRangeHigh = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORHigh else Double.NaN; plot OpenRangeLow = if ShowTodayOnly and !Today then Double.NaN else if !OpenRangeTime then ORLow else Double.NaN; def Active; if securityType == securityType.stocks { Active = if (SecondsFromTime(StartTime) > 0 and SecondsTillTime(MarketCloseTime) > 0) then 1 else 0; } else { Active = 1; #Active = if ((SecondsFromTime(0500) > 0 and SecondsTillTime(0800) > 0)) or ((SecondsFromTime(1700) > 0 and SecondsTillTime(2100) > 0)) then 1 else 0; } OpenRangeHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); OpenRangeHigh.SetDefaultColor(Color.YELLOW); OpenRangeHigh.SetLineWeight(1); OpenRangeLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); OpenRangeLow.SetDefaultColor(Color.YELLOW); OpenRangeLow.SetLineWeight(1); def half = (ORHigh + ORLow) / 2; def rangee = OpenRangeHigh - OpenRangeLow; def T1 = ORHigh + (rangee / 2); def T2 = ORLow - (rangee / 2); plot T3 = ORHigh + (rangee); plot T4 = ORLow - (rangee); plot T5 = ORHigh + (rangee * 2); plot T6 = ORLow - (rangee * 2); #plot mid = half; AddLabel(yes, Round(T5, 2) + " ", Color.CYAN); AddLabel(yes, Round(T3, 2) + " ", Color.CYAN); AddLabel(yes, Round(rangee, 2) + " ", Color.YELLOW); AddLabel(yes, Round(T4, 2) + " ", Color.MAGENTA); AddLabel(yes, Round(T6, 2) + " ", Color.MAGENTA); T3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); T3.SetDefaultColor(Color.CYAN); T3.SetLineWeight(1); T4.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); T4.SetDefaultColor(Color.MAGENTA); T4.SetLineWeight(1); T5.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); T5.SetDefaultColor(Color.CYAN); T5.SetLineWeight(1); T6.SetPaintingStrategy(PaintingStrategy.HORIZONTAL); T6.SetDefaultColor(Color.MAGENTA); T6.SetLineWeight(1); # ----------------------------------- # HIGHER TIMEFRAMES # ----------------------------------- def H1 = high(period = Time_Frame); def L1 = low(period = Time_Frame); def O1 = open(period = Time_Frame); def C1 = close(period = Time_Frame); def H2 = high(period = Time_Frame2); def L2 = low(period = Time_Frame2); def O2 = open(period = Time_Frame2); def C2 = close(period = Time_Frame2); #------------------------------------ # DEFINE SCENARIOS #------------------------------------ def insidebar = (H1 < H1[1] and L1 > L1[1]) or (H1 == H1[1] and L1 > L1[1]) or (H1 < H1[1] and L1 == L1[1]) or (H1 == H1[1] and L1 == L1[1]); def outsidebar = H1 > H1[1] and L1 < L1[1]; def insidebarup = insidebar and O1 < C1; def twoup = H1 > H1[1] and L1 >= L1[1]; def outsidebarup = outsidebar and O1 < C1; def insidebardown = insidebar and O1 > C1; def twodown = H1 <= H1[1] and L1 < L1[1]; def outsidebardown = outsidebar and O1 > C1; #------------------------------------ # DEFINE SCENARIOS 4HR #------------------------------------ def fourlong = twoup or outsidebarup; def fourshort = twodown or outsidebardown; def fourcontlong = ((twoup[1] or (twoup[2] or outsidebar[2] and insidebar[1]) or (insidebar[2] and insidebar[1]) or outsidebar[1]) and twoup); def fourcontshort = ((twodown[1] or (twodown[2] or outsidebar[2] and insidebar[1]) or (insidebar[2] and insidebar[1]) or outsidebar[1]) and twodown); #------------------------------------ # DEFINE SCENARIOS DAY #------------------------------------ def insidebar2 = (H2 < H2[1] and L2 > L2[1]) or (H2 == H2[1] and L2 > L2[1]) or (H2 < H2[1] and L2 == L2[1]) or (H2 == H2[1] and L2 == L2[1]); def outsidebar2 = H2 > H2[1] and L2 < L2[1]; def insidebarup2 = insidebar2 and O2 < C2; def twoup2 = H2 > H2[1] and L2 >= L2[1]; def outsidebarup2 = outsidebar2 and O2 < C2; def insidebardown2 = insidebar2 and O2 > C2; def twodown2 = H2 <= H2[1] and L2 < L2[1]; def outsidebardown2 = outsidebar2 and O2 > C2; #------------------------------------ # DEFINE REVERSALS DAILY SETUP #------------------------------------ def daylongsetup = twodown2[1] or outsidebar2[1] or ((twodown2[2] or outsidebar2[2]) and insidebar2[1]); def dayshortsetup = twoup2[1] or outsidebar2[1] or ((twoup2[2] or outsidebar2[2]) and insidebar2[1]); def daycontlong = twoup2[1] or (twoup2[2] or outsidebar2[2] and insidebar2[1]) or outsidebarup2[1]; def daycontshort = twodown2[1] or (twodown2[2] or outsidebar2[2] and insidebar2[1]) or outsidebardown2[1]; #------------FTFC-------------- def "30mAGG" = AggregationPeriod.THIRTY_MIN; def "1hAGG" = AggregationPeriod.HOUR; def "dAGG" = AggregationPeriod.DAY; def "wAGG" = AggregationPeriod.WEEK; def thirty = open(period = "30mAGG"); def hour = open(period = "1hAGG"); def dayy = open(period = "dAGG"); def week = open(period = "wAGG"); def UP = if thirty >= hour and thirty >= dayy then thirty else if hour >= thirty and hour >= dayy then hour else if dayy >= thirty and dayy >= hour then dayy else Double.NaN; def DOWN = if thirty <= hour and thirty <= dayy then thirty else if hour <= thirty and hour <= dayy then hour else if dayy <= thirty and dayy <= hour then dayy else Double.NaN; #WFTC---------------------- def WEEKUP = if thirty >= hour and thirty >= dayy and thirty >= week then thirty else if hour >= thirty and hour >= dayy and hour >= week then hour else if dayy >= thirty and dayy >= hour and dayy >= week then dayy else if week >= thirty and week >= hour and week >= dayy then week else Double.NaN; def WEEKDN = if thirty <= hour and thirty <= dayy and thirty <= week then thirty else if hour <= thirty and hour <= dayy and hour <= week then hour else if dayy <= thirty and dayy <= hour and dayy <= week then dayy else if week <= thirty and week <= hour and week <= dayy then week else Double.NaN; def FTCUP = close > UP; def FTCDN = close < DOWN; def WFTCUP = close > WEEKUP; def WFTCDN = close < WEEKDN; #------------HALF---------------- def h = H1; def l = H1; def halfrange = (h[1] - l[1]) / 2; def stop = h[1] - halfrange; def overhalf = price > stop; def underhalf = price < stop; #------------STOPS--------------- def LX = low crosses below ORLow; def SX = high crosses above ORHigh; #-------------------------------- def MA_close = close(period = MA_TimeFrame); def MA1 = Average(MA_close, 9); def MA2 = Average(MA_close, 21); plot ln1 = MA1; ln1.SetDefaultColor(color.gray); ln1.SetLineWeight(3); #def over_ma = MA1 > MA2; #def under_ma = MA1 < MA2; def overdayma = price > MA1; def underdayma = price < MA1; def crossAbove = high crosses above ORHigh; def crossBelow = low crosses below ORLow; def fourhourhigh = H1[1]; def fourhourlow = L1[1]; def fhcl = ORHigh >= fourhourhigh and overdayma; def fhcs = ORLow <= fourhourlow and underdayma; #def buy = FTCUP and Active and crossAbove and (daylongsetup); #def sell = FTCDN and Active and crossBelow and (dayshortsetup); def buy = (if (FTCUP and Active and crossAbove and (fourcontlong or fourlong) and daylongsetup and fhcl) then 1 else if (WFTCUP and Active and crossAbove and (fourcontlong or fourlong) and daycontlong and fhcl) then 1 else 0); def sell = (if (FTCDN and Active and crossBelow and (fourcontshort or fourshort) and dayshortsetup and fhcs) then 1 else if (WFTCDN and Active and crossBelow and (fourcontshort or fourshort) and daycontshort and fhcs) then 1 else 0); #ENTRY----------------------- AddOrder(OrderType.BUY_TO_OPEN, buy[-1], tickcolor = Color.LIME, arrowcolor = Color.LIME, name = "LONG : " + ORLow); AddOrder(OrderType.SELL_TO_OPEN, sell[-1], tickcolor = Color.RED, arrowcolor = Color.RED, name = "SHORT : " + ORHigh); #OUTS_----------------------- def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1]; def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD()); def afterEnd = GetTime() > RegularTradingEnd(GetYYYYMMDD()); def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then 1 else 0; def lastBarOfDay = if (afterEnd[-2] == 1 and afterEnd == 0) or (isRollover[-2] and firstBarOfDay[-2]) then 1 else 0; AddOrder(OrderType.SELL_TO_CLOSE, high[-1] crosses above (if use_T1 and T1 then T1 else if use_T3 and T3 then T3 else if use_T5 and T5 then T5 else 0), tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "TP"); AddOrder(OrderType.BUY_TO_CLOSE, low[-1] crosses below (if use_T2 and T2 then T2 else if use_T4 and T4 then T4 else if use_T6 and T6 then T6 else 0), tickcolor = Color.CYAN, arrowcolor = Color.CYAN, name = "TP"); AddOrder(OrderType.SELL_TO_CLOSE, lastBarOfDay, tickcolor = Color.PLUM, arrowcolor = Color.PLUM, name = "EOD"); AddOrder(OrderType.BUY_TO_CLOSE, lastBarOfDay, tickcolor = Color.PLUM, arrowcolor = Color.PLUM, name = "EOD"); AddOrder(OrderType.SELL_TO_CLOSE, LX[-1], tickcolor = Color.YELLOW, arrowcolor = Color.YELLOW, name = "STOP"); AddOrder(OrderType.BUY_TO_CLOSE, SX[-1], tickcolor = Color.YELLOW, arrowcolor = Color.YELLOW, name = "STOP"); #RISK - EMILY IN DISCORD # Input max percentage of a portfolio that one stock should be input Max_Percent = 0.01; def netliq = GetNetLiq (); input scale_in = yes; input times_to_scale_in = 2; ### Risk of Portfolio def twoperc = netliq * (Max_Percent / 1); AddLabel(yes, Max_Percent + "% ActRisk " + AsDollars(twoperc), Color.CYAN); # Input position risk input RiskPercent = .02; # Position Size def currentPrice = close; def dollarRisk = (currentPrice * RiskPercent); def stopPrice = (currentPrice - dollarRisk); def SHAREStoBUY = twoperc / (currentPrice - stopPrice); input showlabel = yes; AddLabel (yes, " shares to buy " + roundup ((SHAREStoBUY),0), Color.CYAN); #AddLabel (yes, " shares to BUY 3 times " + roundup ((SHAREStoBUY /3),0), Color.CYAN); AddLabel (yes, AsPercent(RiskPercent)+ " Stop " + AsDollars (currentPrice - (currentPrice * RiskPercent)), Color.light_red); AddLabel (yes, " Total Capital this trade " + AsDollars (SHAREStoBUY * currentPrice), Color.CYAN); #Globals def nan = Double.NaN; def bn = if !IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close[-1]) then BarNumber() else bn[1]; #Inputs input fplTargetWinLoss = .50; #hint fplTargetWinLoss: sets the target winlossRatio (in percent) which determines display colors of the W/L label. input fplTargetWinRate = 1; #hint fplTargetWinRate: sets the target winRate (float) which determines display colors of the WinRate label; input fplHidePrice = no; #hint fplHidePrice: hide's the underlying price graph. \nDefault is no. input fplHideFPL = yes; #hint fplHideFPL: hide's the underlying P&L graph.\nDefault is yes. #temp input var references def targetWinLoss = fplTargetWinLoss; def targetWinRate = fplTargetWinRate; def hidePrice = fplHidePrice; def hideFPL = fplHideFPL; #hide chart candles HidePricePlot(hidePrice); #Plot default Floating P&L plot FPL = FPL(); FPL.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM); FPL.DefineColor("Positive and Up", Color.GREEN); FPL.DefineColor("Positive and Down", Color.DARK_GREEN); FPL.DefineColor("Negative and Down", Color.RED); FPL.DefineColor("Negative and Up", Color.DARK_RED); FPL.AssignValueColor(if FPL >= 0 then if FPL > FPL[1] then FPL.Color("Positive and Up") else FPL.Color("Positive and Down") else if FPL < FPL[1] then FPL.Color("Negative and Down") else FPL.Color("Negative and Up")); FPL.SetHiding(hideFPL); plot ZeroLine = if IsNaN(close) then nan else 0; ZeroLine.SetDefaultColor(Color.GRAY); ZeroLine.SetHiding(hideFPL); #Global Scripts script incrementValue { input condition = yes; input increment = 1; input startingValue = 0; def _value = CompoundValue(1, if condition then _value[1] + increment else _value[1], startingValue); plot incrementValue = _value; } ; # Entry Calculations. Note: Only parses on a Strategy Chart def entry = EntryPrice(); def entryPrice = if !IsNaN(entry) then entry else entryPrice[1]; def hasEntry = !IsNaN(entry); def isNewEntry = entryPrice != entryPrice[1]; #is active trade def highFPL = HighestAll(FPL); def lowFPL = LowestAll(FPL); def fplreturn = (FPL - FPL[1]) / FPL[1]; def cumsum = Sum(fplreturn); def highBarNumber = CompoundValue(1, if FPL == highFPL then bn else highBarNumber[1], 0); def lowBarNumber = CompoundValue(1, if FPL == lowFPL then bn else lowBarNumber[1], 0); #Win/Loss ratios def entryBarsTemp = if hasEntry then bn else nan; def entryBarNum = if hasEntry and isNewEntry then bn else entryBarNum[1]; def isEntryBar = entryBarNum != entryBarNum[1]; def entryBarPL = if isEntryBar then FPL else entryBarPL[1]; def exitBarsTemp = if !hasEntry and bn > entryBarsTemp[1] then bn else nan; def exitBarNum = if !hasEntry and !IsNaN(exitBarsTemp[1]) then bn else exitBarNum[1]; def isExitBar = exitBarNum != exitBarNum[1]; def exitBarPL = if isExitBar then FPL else exitBarPL[1]; def entryReturn = if isExitBar then exitBarPL - exitBarPL[1] else entryReturn[1]; def isWin = if isExitBar and entryReturn >= 0 then 1 else 0; def isLoss = if isExitBar and entryReturn < 0 then 1 else 0; def entryReturnWin = if isWin then entryReturn else entryReturnWin[1]; def entryReturnLoss = if isLoss then entryReturn else entryReturnLoss[1]; def entryFPLWins = if isWin then entryReturn else 0; def entryFPLLosses = if isLoss then entryReturn else 0; def entryFPLAll = if isLoss or isWin then entryReturn else 0; #Counts def entryCount = incrementValue(entryFPLAll); def winCount = incrementValue(isWin); def lossCount = incrementValue(isLoss); def highestReturn = if entryReturnWin[1] > highestReturn[1] then entryReturnWin[1] else highestReturn[1]; def lowestReturn = if entryReturnLoss[1] < lowestReturn[1] then entryReturnLoss[1] else lowestReturn[1]; def winRate = winCount / lossCount; def winLossRatio = winCount / entryCount; def avgReturn = TotalSum(entryFPLAll) / entryCount; def avgWin = TotalSum(entryFPLWins) / winCount; def avgLoss = TotalSum(entryFPLLosses) / lossCount; #Labels AddLabel(yes, text = "Total Trades: " + entryCount + " ", color = Color.WHITE ); #AddLabel(yes, # text = "WinCount: " + winCount + # " | LossCount: " + lossCount + # " | WinRate: " + Round(winRate, 2) + " ", # color = if winRate >= targetWinRate # then Color.CYAN # else Color.MAGENTA # ); AddLabel(yes, text = "W/L: " + AsPercent(winLossRatio) + " ", color = if winLossRatio > targetWinLoss then Color.CYAN else Color.MAGENTA ); #AddLabel(yes, # text = "AvgReturn: " + AsDollars(avgReturn) + # " | AvgWin: " + AsDollars(avgWin) + # " | AvgLoss: " + AsDollars(avgLoss) + " ", # color = if avgReturn >= 0 # then Color.CYAN # else Color.MAGENTA # ); AddLabel(yes, text = "Total Profit: " + AsDollars(FPL) + " ", color = if FPL > 0 then Color.CYAN else Color.MAGENTA );