I will give it a go as well.I'm beta testing this new strategy if you would like to join me. If there is enough interest, I'll start a new thread.
Ruby:# Author Dwain Pattillo - 2023 # Q. Why do I share my strategies? # A. It would be completely and totally silly of me (and you!) to keep them to myself. Who remembers what happen with GameStop? The more people doing the exact same thing at the same time in the market, the more power they have in moving the market in their favor! If we had an army of traders using the same system, oh what power we would have! We (the retail trader) could take the power back from the market makers! # 1. Adjust the length setting to the best FloatingPL and then let'r rip! # In most cases, the lower the timeframe of the chart, the lower the length will be .. I trade one minute and a good starting length is 4. # If you are auto trading 24/5 on the futures or forex, I would suggest turning on the volume filter and optimizing it, otherwise leave it off. # Don't stop adjusting the length just because the P/L goes down! It's almost like you are tuning the strategy to the Elliot waves of the market. input BackTestTradeSize = 1; input ShowBackTestPositions = yes; input Length = 4; input UseVolumeAsFilter = no; input VolumeLength = 600; input AlertOnSignal = no; #Average the volume and only open trades when volume is higher than the average. def VolStrength = lg(volume[1]) - lg(SimpleMovingAvg(volume[1], VolumeLength)); #Add your indicator code here (if you want to use this as a template) :) def min_low = Lowest(low, Length+1); def max_high = Highest(high, Length+1); def rel_diff = close - (max_high + min_low) / 2; def range = max_high - min_low; def avgrel = ExpAverage(ExpAverage(rel_diff, Length), Length); def avgdiff = ExpAverage(ExpAverage(range, Length), Length); def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0; #Define the signals def BuyToOpenSignal = SMI > SMI[1] and (if UseVolumeAsFilter then VolStrength>0 else yes); def SellToCloseSignal = ( SMI < SMI[1] ); def SellToOpenSignal = SMI < SMI[1] and (if UseVolumeAsFilter then VolStrength>0 else yes); def BuyToCloseSignal = ( SMI > SMI[1] ); #Open the orders on the chart for back testing and optimizing the setting AddOrder(OrderType.BUY_AUTO, BuyToOpenSignal and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.CYAN, Color.CYAN, ""); AddOrder(OrderType.SELL_AUTO, SellToOpenSignal and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.RED, Color.RED,""); #Add the signal labels to the chart def OpenOrders = GetQuantity(); AddLabel(BuyToOpenSignal[1] and OpenOrders < 1 , " BUY ", CreateColor(153, 255, 153)); AddLabel(SellToOpenSignal[1] and OpenOrders > -1, " SELL ", CreateColor(255, 102, 102)); #Sound the bell. (If alerts are turn on) Alert(BuyToOpenSignal[1] and OpenOrders < 1 and AlertOnSignal, "Buy Open Signal", Alert.Bar, Sound.Ding); Alert(SellToOpenSignal[1] and OpenOrders > -1 and AlertOnSignal, "Sell Open Signal", Alert.Bar, Sound.Ding); #“Make everything as simple as possible, but not simpler.” Albert Einstein.
I fixed the first post ..I will give it a go as well. BTW, the first post script isn't working correctly. The Trend Length isn't plotting. like the older version. I do have the Show Plot checked under Plots/MA. I have made many changes and tests and it isn't showing up.
Looking forward to testing, thanks!!I'm beta testing this new strategy if you would like to join me. If there is enough interest, I'll start a new thread.
Ruby:# Author Dwain Pattillo - 2023 # Q. Why do I share my strategies? # A. It would be completely and totally silly of me (and you!) to keep them to myself. Who remembers what happen with GameStop? The more people doing the exact same thing at the same time in the market, the more power they have in moving the market in their favor! If we had an army of traders using the same system, oh what power we would have! We (the retail trader) could take the power back from the market makers! # 1. Adjust the length setting to the best FloatingPL and then let'r rip! # In most cases, the lower the timeframe of the chart, the lower the length will be .. I trade one minute and a good starting length is 4. # If you are auto trading 24/5 on the futures or forex, I would suggest turning on the volume filter and optimizing it, otherwise leave it off. # Don't stop adjusting the length just because the P/L goes down! It's almost like you are tuning the strategy to the Elliot waves of the market. input BackTestTradeSize = 1; input ShowBackTestPositions = yes; input Length = 4; input UseVolumeAsFilter = no; input VolumeLength = 600; input AlertOnSignal = no; #Average the volume and only open trades when volume is higher than the average. def VolStrength = lg(volume[1]) - lg(SimpleMovingAvg(volume[1], VolumeLength)); #Add your indicator code here (if you want to use this as a template) :) def min_low = Lowest(low, Length+1); def max_high = Highest(high, Length+1); def rel_diff = close - (max_high + min_low) / 2; def range = max_high - min_low; def avgrel = ExpAverage(ExpAverage(rel_diff, Length), Length); def avgdiff = ExpAverage(ExpAverage(range, Length), Length); def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0; #Define the signals def BuyToOpenSignal = SMI > SMI[1] and (if UseVolumeAsFilter then VolStrength>0 else yes); def SellToCloseSignal = ( SMI < SMI[1] ); def SellToOpenSignal = SMI < SMI[1] and (if UseVolumeAsFilter then VolStrength>0 else yes); def BuyToCloseSignal = ( SMI > SMI[1] ); #Open the orders on the chart for back testing and optimizing the setting AddOrder(OrderType.BUY_AUTO, BuyToOpenSignal and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.CYAN, Color.CYAN, ""); AddOrder(OrderType.SELL_AUTO, SellToOpenSignal and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.RED, Color.RED,""); #Add the signal labels to the chart def OpenOrders = GetQuantity(); AddLabel(BuyToOpenSignal[1] and OpenOrders < 1 , " BUY ", CreateColor(153, 255, 153)); AddLabel(SellToOpenSignal[1] and OpenOrders > -1, " SELL ", CreateColor(255, 102, 102)); #Sound the bell. (If alerts are turn on) Alert(BuyToOpenSignal[1] and OpenOrders < 1 and AlertOnSignal, "Buy Open Signal", Alert.Bar, Sound.Ding); Alert(SellToOpenSignal[1] and OpenOrders > -1 and AlertOnSignal, "Sell Open Signal", Alert.Bar, Sound.Ding); #“Make everything as simple as possible, but not simpler.” Albert Einstein.
Did a quick optimization of the new ASAP code length parameter for SPY in pre-market today (1/12) for various timeframes:
1 day L=12
30m 20
15m 8
10m 17
5m 13
3m 51
1m 18
Not sure what was up with the 3 minute. On most of them, I only ran up to about L=36 and picked the best. On the 3 minute chart, nothing in that range looked good, so I kept going. Don't know if the others would have gotten good results up in the higher range, too.
Also, I like to be able to see what an indicator actually looks like, so I pulled out the SMI part of the ASAP code and created a lower indicator so I could see it. Here's my chart setup for that: http://tos.mx/SWtnDkA
(Probably a good idea to spin off a new thread for the ASAP discussions)
Edit: I should point out that I did the above optimization using the maximum amount of data that ToS would show at each timeframe (e.g., 180 days for 5 min chart). After reducing the number of days shown on my chart, I realized that it pretty drastically changed the answer for the best length. As an example, I changed to a 2d/5m chart and had to change the ASAP length parameter to 39. Guess that reflects the changing nature of the market - the values above give a good long term result, but the near term market may need different lengths to get the best results.
@Zetta_wow did you manually walk through the optimization for each time or is there some kind of strategy input parameter optimization function somewhere? If not, I was thinking it might be possible to use Macro Recorder to automate changing the length input and time and copying the P/L to a spreadsheet. First post, been lurking for a while.Did a quick optimization of the new ASAP code length parameter for SPY in pre-market today (1/12) for various timeframes:
1 day L=12
30m 20
15m 8
10m 17
5m 13
3m 51
1m 18
Not sure what was up with the 3 minute. On most of them, I only ran up to about L=36 and picked the best. On the 3 minute chart, nothing in that range looked good, so I kept going. Don't know if the others would have gotten good results up in the higher range, too.
Also, I like to be able to see what an indicator actually looks like, so I pulled out the SMI part of the ASAP code and created a lower indicator so I could see it. Here's my chart setup for that: http://tos.mx/SWtnDkA
(Probably a good idea to spin off a new thread for the ASAP discussions)
Edit: I should point out that I did the above optimization using the maximum amount of data that ToS would show at each timeframe (e.g., 180 days for 5 min chart). After reducing the number of days shown on my chart, I realized that it pretty drastically changed the answer for the best length. As an example, I changed to a 2d/5m chart and had to change the ASAP length parameter to 39. Guess that reflects the changing nature of the market - the values above give a good long-term result, but the near-term market may need different lengths to get the best results.
Just manually changing the length and watching the FloatPL results. Tedious, but it's what's available in ToS. I do have a spreadsheet with VBA functions that I've built for similar optimizations of other trading systems, but I haven't implemented this one yet. It's fairly slow, so I wouldn't want to use it intraday, but it would be fine for pre-market setup each day. I'm also working on a VB.NET version of the spreadsheet, hoping it will be faster.@Zetta_wow did you manually walk through the optimization for each time or is there some kind of strategy input parameter optimization function somewhere? If not, I was thinking it might be possible to use Macro Recorder to automate changing the length input and time and copying the P/L to a spreadsheet. First post, been lurking for a while.
Care to expand on using VB to optimize settings for a strategy/study?Just manually changing the length and watching the FloatPL results. Tedious, but it's what's available in ToS. I do have a spreadsheet with VBA functions that I've built for similar optimizations of other trading systems, but I haven't implemented this one yet. It's fairly slow, so I wouldn't want to use it intraday, but it would be fine for pre-market setup each day. I'm also working on a VB.NET version of the spreadsheet, hoping it will be faster.
I loaded it as a strategy and it came when the Floating P/L was added.Is there a way to add p/l label into the script like the script below?
Thanks!
https://usethinkscript.com/threads/...r-strategy-v2-for-thinkorswim.8214/post-78083
@METAL If you weren’t thinkin you wouldn’t-a’ thought that.@dap711 Have you tried just a simple Hull Moving average strategy. I do not think this repaint. Would you consider implementing one with just Hull with length options etc.. It seems that buying when line turns blue and selling when it turns pink is extremely effective.
Eazy-Peezy:@dap711 Have you tried just a simple Hull Moving average strategy. I do not think this repaint. Would you consider implementing one with just Hull with length options etc.. It seems that buying when line turns blue and selling when it turns pink is extremely effective.
declare upper;
input HMA_Length = 2;
input HMA_Displace = 2;
input ShowBackTestPositions = yes;
input BackTestTradeSize = 1;
input StartTrading = 0927;
input StopTrading = 1457;
def OkToTrade = secondsFromTime(StartTrading) > 0 and secondsFromTime(StopTrading)<0;
def HMA = HullMovingAvg(price = close, length = HMA_Length);
def BuyToOpenSignal= HMA > HMA[HMA_Displace];
def SellToOpenSignal= HMA < HMA[HMA_Displace];
AddOrder(OrderType.BUY_AUTO, BuyToOpenSignal and ShowBackTestPositions and OkToTrade, open[-1], BackTestTradeSize, Color.CYAN, Color.CYAN, "");
AddOrder(OrderType.SELL_AUTO, SellToOpenSignal and ShowBackTestPositions and OkToTrade, open[-1], BackTestTradeSize, Color.RED, Color.RED,"");
AddOrder(OrderType.SELL_TO_CLOSE, secondsFromTime(StopTrading)> 0 and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.CYAN, Color.CYAN, "");
AddOrder(OrderType.BUY_TO_CLOSE, secondsFromTime(StopTrading)> 0 and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.RED, Color.RED,"");
def OpenOrders = GetQuantity();
AddLabel(yes, " BUY ", if BuyToOpenSignal[1] and OpenOrders < 1 and OkToTrade then CreateColor(153, 255, 153) else Color.White);
AddLabel(yes, " SELL ", if SellToOpenSignal[1] and OpenOrders > -1 and OkToTrade then CreateColor(255, 102, 102) else Color.White);
AddLabel(yes, " CLOSE ", if secondsFromTime(StopTrading)> 0 and OpenOrders != 0 then Color.Yellow else Color.White);
Great forum!Eazy-Peezy:
Ruby:declare upper; input HMA_Length = 2; input HMA_Displace = 2; input ShowBackTestPositions = yes; input BackTestTradeSize = 1; input StartTrading = 0927; input StopTrading = 1457; def OkToTrade = secondsFromTime(StartTrading) > 0 and secondsFromTime(StopTrading)<0; def HMA = HullMovingAvg(price = close, length = HMA_Length); def BuyToOpenSignal= HMA > HMA[HMA_Displace]; def SellToOpenSignal= HMA < HMA[HMA_Displace]; AddOrder(OrderType.BUY_AUTO, BuyToOpenSignal and ShowBackTestPositions and OkToTrade, open[-1], BackTestTradeSize, Color.CYAN, Color.CYAN, ""); AddOrder(OrderType.SELL_AUTO, SellToOpenSignal and ShowBackTestPositions and OkToTrade, open[-1], BackTestTradeSize, Color.RED, Color.RED,""); AddOrder(OrderType.SELL_TO_CLOSE, secondsFromTime(StopTrading)> 0 and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.CYAN, Color.CYAN, ""); AddOrder(OrderType.BUY_TO_CLOSE, secondsFromTime(StopTrading)> 0 and ShowBackTestPositions, open[-1], BackTestTradeSize, Color.RED, Color.RED,""); def OpenOrders = GetQuantity(); AddLabel(yes, " BUY ", if BuyToOpenSignal[1] and OpenOrders < 1 and OkToTrade then CreateColor(153, 255, 153) else Color.White); AddLabel(yes, " SELL ", if SellToOpenSignal[1] and OpenOrders > -1 and OkToTrade then CreateColor(255, 102, 102) else Color.White); AddLabel(yes, " CLOSE ", if secondsFromTime(StopTrading)> 0 and OpenOrders != 0 then Color.Yellow else Color.White);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.