NexusFi: Find Your Edge


Home Menu

 





Help with very basic ThinkScript Strategy


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one Cloudy with 4 posts (0 thanks)
    2. looks_two snipsta with 2 posts (0 thanks)
    3. looks_3 Tunah with 2 posts (0 thanks)
    4. looks_4 abooter69 with 1 posts (0 thanks)
    1. trending_up 11,570 views
    2. thumb_up 0 thanks given
    3. group 4 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

Help with very basic ThinkScript Strategy

  #1 (permalink)
snipsta
Tampa,Florida
 
Posts: 2 since Nov 2011
Thanks Given: 0
Thanks Received: 0

Hello,

I am new to this forum and thinkscript but I am picking it up quick as I have prior programming experience. I'm trying to create a basic strategy with the criteria shown below. I created the code off a modified version of the parabolicsarcrossover study so I am confused why this is not working. No plot is being shown even though I can see this criteria occurring by manually looking at the daily. My code to date is shown below each criteria. Any assistance is appreciated. Thank you

Long Entry (Daily chart, market hours)
----
-Parabolic SAR(.02,.2) becomes bullish
-MACD(12,26,9,EMA) crosses above 0

 
Code
###########
declare LONG_ENTRY;
input opentime = 0930;
input closetime = 1600;

# Only enter during market hours:
#
def AP = getAggregationPeriod();
def daily = if AP >= aggregationPeriod.DAY then 1 else 0;
def isopen = if daily then 1 else if secondsFromTime(opentime) >= 0 and secondsTillTime(closetime) >= 0 then 1 else 0;

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;
input crossingType = {default Bullish, Bearish};

def sar = ParabolicSAR(accelerationFactor=accelerationFactor, accelerationLimit=accelerationLimit);

def psarcrossover = if crosses(sar, close, CrossingType == CrossingType.Bullish) then 1 else 0;

def macdCrossover = if Crosses(MACDHistogram(12, 26, 9, "EMA"), 0, crossingdirection.above) then 1 else 0;

def total = psarcrossover + macdCrossover;

def trigger = if total == 2 then 1 else 0;

def price = close;
addOrder(trigger, price);

# Formatting:
#
SetColor(color.green);
Long Close (Daily chart, market hours)
--
-Parabolic SAR(.02,.2) becomes bearish
-MACD(12,26,9,EMA) crosses below 0

 
Code
###########
declare LONG_EXIT;
input opentime = 0930;
input closetime = 1600;

# Only enter during market hours:
#
def AP = getAggregationPeriod();
def daily = if AP >= aggregationPeriod.DAY then 1 else 0;
def isopen = if daily then 1 else if secondsFromTime(opentime) >= 0 and secondsTillTime(closetime) >= 0 then 1 else 0;

input accelerationFactor = 0.02;
input accelerationLimit = 0.2;
input crossingType = {default Bearish, Bullish};

def sar = ParabolicSAR(accelerationFactor=accelerationFactor, accelerationLimit=accelerationLimit);

def psarcrossover = if crosses(sar, close, CrossingType == CrossingType.Bearish) then 1 else 0;

def macdCrossover = if Crosses(MACDHistogram(12, 26, 9, "EMA"), 0, crossingdirection.below) then 1 else 0;

def total = psarcrossover + macdCrossover;

def trigger = if total == 2 then 1 else 0;

def price = close;
addOrder(trigger, price);

# Formatting:
#
SetColor(color.red);

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Futures True Range Report
The Elite Circle
Build trailing stop for micro index(s)
Psychology and Money Management
Better Renko Gaps
The Elite Circle
Online prop firm The Funded Trader (TFT) going under?
Traders Hideout
 
  #2 (permalink)
 Cloudy 
desert CA
 
Experience: Intermediate
Platform: NT7, various
Broker: various, TDA
Trading: NQ,ES
Posts: 2,124 since Jul 2011
Thanks Given: 2,396
Thanks Received: 1,748

Last I checked which was about a few months ago, strategies, while being able to be parsed in Thinkscript, still doesn't work on TOS. The development resources seemed to have moved on to Prodigio.

Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
snipsta
Tampa,Florida
 
Posts: 2 since Nov 2011
Thanks Given: 0
Thanks Received: 0



Cloudy View Post
Last I checked which was about a few months ago, strategies, while being able to be parsed in Thinkscript, still doesn't work on TOS. The development resources seemed to have moved on to Prodigio.

First off, thanks for the extremely quick reply. While I am new to TOS I have created/modified some other very basic strategies and they seem to work fine. I believe my problem is with the syntax of the parabolic sar as I have created strategies with the MACD with no problems.

Reply With Quote
  #4 (permalink)
 Cloudy 
desert CA
 
Experience: Intermediate
Platform: NT7, various
Broker: various, TDA
Trading: NQ,ES
Posts: 2,124 since Jul 2011
Thanks Given: 2,396
Thanks Received: 1,748

Your welcome. Nice to hear strategies are working now, thanks. I may take a look sometime and try out what you posted.

Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
abooter69
Las Vegas, nv
 
Posts: 1 since Dec 2012
Thanks Given: 0
Thanks Received: 0

might try adding these....


AddOrder(OrderType.BUY_AUTO,trigger name, no, tickcolor = GetColor(1), arrowcolor = GetColor(6), name = "BUY");
AddOrder(OrderType.SELL_AUTO,trigger name, no, tickcolor = GetColor(1), arrowcolor = GetColor(5), name = "SELL");

Reply With Quote
  #6 (permalink)
 
RedK's Avatar
 RedK 
Dubai, UAE
 
Experience: Intermediate
Platform: TOS, TradeStation
Broker: OX, TradeStation
Trading: Stocks & Basic Options
Posts: 171 since May 2012
Thanks Given: 44
Thanks Received: 145

took a quick look and I don't like this line:
def psarcrossover = if crosses(sar, close, CrossingType == CrossingType.Bearish) then 1 else 0;

CrossingType is an enumerated variable (like an array basically), you assign its value in the study settings, but then pass it to the crosses() function.. and it will not mean anything to it, where it expects an actual direction (Above, Below)? would be surprised if that line doesn't produce a script error.. but that's where I would look to change. the next line to it sounds OK.

hope this helps,
K

Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 Cloudy 
desert CA
 
Experience: Intermediate
Platform: NT7, various
Broker: various, TDA
Trading: NQ,ES
Posts: 2,124 since Jul 2011
Thanks Given: 2,396
Thanks Received: 1,748


Cloudy View Post
Your welcome. Nice to hear strategies are working now, thanks. I may take a look sometime and try out what you posted.

my post later

Visit my NexusFi Trade Journal Reply With Quote




Last Updated on August 6, 2013


© 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