NexusFi: Find Your Edge


Home Menu

 





Help with Plotting via ThinkScript


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one Andrew2401 with 2 posts (0 thanks)
    2. looks_two bradhouser with 1 posts (1 thanks)
    3. looks_3 rrpp13579 with 1 posts (0 thanks)
    4. looks_4 dledbet1 with 1 posts (0 thanks)
    1. trending_up 4,886 views
    2. thumb_up 1 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

Help with Plotting via ThinkScript

  #1 (permalink)
Andrew2401
Boca Raton Florida
 
Posts: 3 since Mar 2017
Thanks Given: 2
Thanks Received: 0

Hi everybody!

I've run into a bit of an issue coding an alert system in ThinkScript (AD Ameritrade's Think or Swim System). Because the project is confidential, I can only share limited information, but I hope it can be enough to get some help. Basically, my script recognizes entry and exit points, and plots them into the charts as UP and DOWN arrows. It works just fine. The only thing I'm trying to fix is to block it from making multiple of the same arrows in a row. I thought I could set up some sort of ticker that activated when a green arrow was produced, and got deactivated when a red arrow was produced. Any ideas as to how? I appreciate any help. {Tried to post screenshots but couldn't because my account is too new. I'll send them in a message to whoever answers}


Here is as much of the script as I can share:

def BuySignal = {CONFIDENTIAL} then 1 else -1 ;

plot UpFractal = if BuySignal == 1 and BuySignal[1] != BuySignal then close else Double.NaN;

#Sell Signals
def SellSignal = if {CONFIDENTIAL} then 1 else -1;

plot DownFractal = if SellSignal == 1 and SellSignal[1] != SellSignal then close else Double.NaN;

UpFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
UpFractal.SetDefaultColor(GetColor(3));
UpFractal.SetLineWeight(2);

DownFractal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
DownFractal.SetDefaultColor(GetColor(3));
DownFractal.SetLineWeight(2);

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #2 (permalink)
bradhouser
Northern California where the girls are warm
 
Posts: 122 since Nov 2010
Thanks Given: 15
Thanks Received: 72

I would suggest you track the signal itself in the background, and only display it if it goes from off to on. Not sure how you do it Thinkscript, but you could build logic that displays the arrow only after the transition from off to on, but not after on to on.


Sent from my iPad using futures.io

Reply With Quote
Thanked by:
  #3 (permalink)
Andrew2401
Boca Raton Florida
 
Posts: 3 since Mar 2017
Thanks Given: 2
Thanks Received: 0


Well guys, I found a beautiful solution to the issue using iterations. First of all, I defined a new variable, backscan_period = 200 / it's just how long the iterations will continue looking backward to find the last signal. Iterations finds the previous Up arrow, and the previous Down arrow, and then compares their periods. If the closest signal is a Sell, and it's trying to plot a Buy, it allows itself to do so, and vice versa. Here's the iterations code. Also, I cleared the Buy and Sell signals to only use boolean values of 1 and 0, instead of 1 and -1. I hope this helps anyone that comes across this problem in the future!

plot UpFractal = if BuySignal and (fold i1 = 1 to backscan_period with x while SellSignal[i1] != 1 do i1) < (fold i2 = 1 to backscan_period with y while BuySignal[i2] != 1 do i2) then close else double.NAN;

plot DownFractal = if SellSignal and (fold i3 = 1 to backscan_period with a while SellSignal[i3] != 1 do i3) > (fold i4 = 1 to backscan_period with b while BuySignal[i4] != 1 do i4) then close else double.NAN;

Reply With Quote
  #4 (permalink)
dledbet1
Plainview
 
Posts: 1 since Jun 2020
Thanks Given: 0
Thanks Received: 0

Hey Andrew,

I came across this and I believe this is exactly what I'm looking for, except I'm only plotting one signal, so I'm only wanting to check and see if that signal has been plotted within a certain amount of time, and plot it if it has not occurred within that period.

How might I adapt the middle portion of this to do so?

For example say my code is basically the same as yours:

plot UpFractal = if BuySignal and ??????????????????????? then close else double.NAN;

Reply With Quote
  #5 (permalink)
rrpp13579
new york + new york
 
Posts: 4 since May 2020
Thanks Given: 0
Thanks Received: 0

Please see if this helps
https://researchtrade.com/forum/read.php?7,2258,7792

Reply With Quote




Last Updated on July 1, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts