Try this NQ Strategy + Code for ThinkorSwim

F

Fedegrosso

New member
I tried. Nothing happened.
I'll try to write the code from scratch
 
A

AlgoTrader77

New member
Hmmm.... really bazaar. Don't know enough about TOS troubleshooting to know what to check. Hopefully the manual route is the solution!
 
F

Fedegrosso

New member
I've managed to write a simple one and it actually work. The code is:


input length = 20;
input price = close;
plot SMA = Average(price, length);
SMA.AssignValueColor(if close>=SMA then Color.Green else Color.Red);

Spending the weekend trying to automate the strategy
 
mc01439

mc01439

Well-known member
2019 Donor
VIP
New here, so I thought I’d post something everyone can use (who wants to).

I’m normally not a very big fan of lagging indicators but this is super easy to use and gives pretty high win ratios in these markets. Plus, it’s VERY easy to get the hang of it!

I had this created for me a while back (see code below).

You simply wait for a bar/candle to close below/above the line and take a breakout/breakdown 1 tick above/below (depending on direction) the prior candle. (see annotations in screenshot)

Been getting 20 to over 100 points (points NOT ticks!) per trade!!

I annotated this in the screenshot, but to reiterate… loss mitigation is entirely up to you. Some of these candles are 40-90+ points in a single minute. So, use caution on how tight you keep things. Let the market breathe and the strategy do its thing! You can use the opposite end of the prior candle you are trading your breakout/breakdown from to protect capital. Or you can pretty much do whatever is inline with your risk tolerance.

Profit taking is a bit different – at least for how I handle it. I set an initial profit target 100 points above my entry (because these markets are NUTS!!). I’ve had this hit many times in 30 minutes or less. Especially that last one which took about 5 minutes (see Wednesday March 19, 2020 at 2:46 Chicago time short entry price 7395.25).

I use this on the NQ with a 1-minute chart and that’s about it. Super fun and easy to see in real-time.

Here is the code:
Code:
plot myindicator=ExpAverage(close,20);
myindicator.SetDefaultColor(Color.White);
myindicator.AssignValueColor(if close>=myindicator then Color.Green else Color.Red);
myindicator.SetStyle(curve.LONG_DASH);
myindicator.SetPaintingStrategy(paintingstrategy.LINE_VS_SQUARES);
myindicator.SetLineWeight(5);
myindicator.setHiding(if close>open(period="DAY") then 0 else 1);
I liked your video! I have been trading a long time and could not of said it better!
 
A

AlgoTrader77

New member
@Fedegrosso

Not sure if this will matter in the long run, but I put your code on my same chart and it is different from my version. Mostly matches but doesn't at times. Sometimes good, sometimes not good.

Indicator Comparison

@BenTen I must be doing something wrong with http://imgur.com/ Everytime I try to post the link it says there is an error. Could you send me to the instructions again? Saw it somewhere but could not find it. Sorry for the hassle! ¯\(ツ)
 
horserider

horserider

Well-known member
VIP
@Fedegrosso @AlgoTrader77 The plots are different because one is a Simple MA and one is an Exponential MA. That is all. Please try to understand how the indicators you use work. The difference of these two without getting into the calculations is the EMA weights recent prices more while the SMA weights all prices in the length the same. Thus the EMA will follow price more closely.
 
A

AlgoTrader77

New member
@horserider I appreciate the feedback but the redundant comment was because @Fedegrosso was unable to get my version working and therefore had no reference. That's all (y)
 
Last edited:
A

adefrenza

New member
VIP
@zee2881 Thanks and no problem!

@Fedegrosso A limit order is what I use. In TOS it would be a "stoplimit" (sell for short, buy for long) since you are getting in on the breakout/breakdown. The key is to watch the color of the line turn from red to green and visa versa. There is no guessing where to get in because you instantly have your high or low price of the candle where it changes and you can simply place your stop entry order a tick above/below that candle. i.e. Above for long positions, below for short positions. Because you are placing a buy limit to go in that direction above price, it is called a stoplimit. (TOS coders can correct me)

Also @Fedegrosso and @zwarriortrader (and anyone else wanting to give this a go)

As far as the code, try this sequence:

1. Open a notepad doc.
2. Scroll up to the post that contains the code and copy and paste it into your doc. We'll come back to this in step 7 and 8.
3. In TOS, open any chart. I like the NQ using a 1 minute time frame.
4. Right click, hover over "studies" and select "edit studies" (you can also get there by clicking on the test tube looking icon at the top right of your chart).
5. Then click "Create".
6. This will open a work space you can paste the code into. Before you do that, delete the default line of code in there "plot Data = close;".
7. Go back to your notepad doc and highlight and copy the code.
8. Paste it into that work space.
9. At the very top you can name it whatever you want. The default is "NewStudy0". So just delete that and name this something you can remember.
10. Then click "ok" and go back to your chart and add it like you would any other indicator.

Let me know if that does the trick or if you have any other questions.
Algo, I love the simplicity of this indicator and strategy. You have named the indicator "myindicator" in the thinscript. Any chance you can share your code? I am super interested to see if it can be improved in any way and/or convert the code to Ninjatrader. Will obviously share any improvements with you.
 
horserider

horserider

Well-known member
VIP
@adefrenza If Ninjatrader has an exponential moving average then you have it already. Just apply the strategy.
 
A

adefrenza

New member
VIP
@adefrenza If Ninjatrader has an exponential moving average then you have it already. Just apply the strategy.
Perhaps I don’t understand. I don’t see the code for “my indicator”.
 
SocietyForTrading

SocietyForTrading

New member
It looks like you are just trading a move above or below the 20EMA. Is that accurate?
 
horserider

horserider

Well-known member
VIP
@adefrenza In Ninjatrader just put a 20 EMA or if they call it an Exponential moving average put it on the chart and you are set to go.

@SocietyForTrading Yes. It is just a 20 EMA.
 
F

Fedegrosso

New member
Do anyone know if in Thinkscript you can calculate the average time length of the moving average?
 
Billions

Billions

Active member
2019 Donor
VIP
@AlgoTrader77 trader have you had any luck using this strategy on tick charts? And if so what timeframes do you prefer?
 
madeinnyc

madeinnyc

Member
Yo people....what @horserider is trying to say is, "If it looks like a duck, walks like a duck...then chances are....'IT'S A DUCK!'. Look under the hood at the source code and you'll find it's the exact same code as an 'Exponential MA'. This is hardly a strategy....it's more a colored line with basic logic! "Just trade the move above or below the 20EMA on the next bar when it changes color".....anyone with basics in trading could figure that out....but that doesn't make it a viable strategy.

This is not to burst anyone's hope of using this tool. But if you're gonna use it, be sure to combine it with other tools that address areas of consolidation/chop zones and provide confirmation of entry/exits. In concert with other tools, you can then develop a viable process.
 
Last edited:
horserider

horserider

Well-known member
VIP
@madeinnyc (y) Tell them just use the ToS EMA and turn on the arrows. Then do not even need to think about a strategy.
 
Billions

Billions

Active member
2019 Donor
VIP
Of course use other tools to confirm thanks
 
AlexBallas

AlexBallas

New member
@AlgoTrader77 thanks for sharing much appreciated, gonna try it out, I watch your video that's pretty cool, thanks again :)
 
C

convertiblejay

New member
Top