Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

clbradley

TS Stochastic Crossover Strategy Code Help?

Recommended Posts

Have a Stochastic Crossover Strategy Code for Tradestation that I need help with please. I need to add conditions that the stochastic slow k went to either less than 10 or just less than oversold before crossing back above the oversold line of 20 before buying, and also the opposite, that it got to 90 before crossing back under the overbought level of 80 before selling short. Guess it needs 4 conditions, if 1, then 2 are met, then buy, and if 3 then 4 are met, sell short. Here is the Stochastic Crossover Strategy code so far:

 

inputs:

PriceH( High ),

PriceL( Low ),

PriceC( Close ),

StochLength( 14 ),

SmoothingLength1( 3 ),

SmoothingLength2( 3 ),

SmoothingType( 1 ).

Oversold( 20 ),

Overbought( 80 ) ;

 

variables:

FastK( 0 ).

FastD( 0 ),

SlowK( 0 ),

SlowD( 0 ) ;

 

Value1 = Stochastic( PriceH, PriceL, PriceC, StochLength, SmoothingLength1,

SmoothingLength2, SmoothingType, FastK, FastD, SlowK, SlowD ) ;

 

If SlowK crosses over SlowD

Then buy 1 share next bar at market;

 

If SlowK crosses under SlowD

Then sell short 1 share next bar at market;

 

 

Thanks for any help.

 

Curtis

Share this post


Link to post
Share on other sites

Use flags for the sequence or increment a couter

 

if slowk < 10 then ready = true;

if ready and slowk > 20 then steady=true;

if steady and slowk crosses above slowd then go;

 

if go then buy.....

 

 

If "any condition that invalidates setup" then reset the 'flags'

 

incrementing a variable might be neater

 

if slowk < 10 then tradestup = 1;

if (tradesetup = 1) and (slowk > 20) then tradesetup = 2;

if (tradesetup = 2) and (slowk crosses above slowd) the tradestup = 3;

 

if tradesetup = 3 then buy.....

 

The second approach is better for more sophisticated applications (you can model pretty complex stuff). This is a rudimentary 'state engine'.

 

Finite-state machine - Wikipedia, the free encyclopedia

Edited by BlowFish

Share this post


Link to post
Share on other sites

Thanks Blowfish. I've seen similar setups before in other strategies using Condition1, Condition2, possibly 3 etc. for a buy or sell/sellshort stating if condition 1 is met first, then condition 2, then 3, then buy next bar at market. But you're just stating it a different way. I'll try it this weekend and let you know if it works. Thanks again for your help.

 

Curtis

Share this post


Link to post
Share on other sites

just to help,,, before you code any stochastic based strategy you need to find a way of real time optimization of its settings other wise your settings become arbitrary and OB or OS does not mean any thing ,, hence all you buy sell signals going to be irrelevant to the market

 

Grey1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Topics

  • Posts

    • Date: 23rd September 2024. Market Update – Gold at record highs; Stocks climb amid Chinese stimulus bets. Asia & European Sessions:   Asian markets were mostly positive on Monday, buoyed by last week’s interest rate decisions from central banks in the US, Japan, China, and the UK. PBOC reduced its 14-day reverse repurchase rate to 1.85% from 1.95%, following a decision to keep key lending rates unchanged the previous week. China’s decision to hold an unusual economic briefing involving three top financial regulators and its cut to a key short-term policy rate heightened speculation about forthcoming stimulus efforts. Chinese stocks rose after the bank’s announcement. Japan’s stock markets were closed due to a public holiday. Attention remained on the BoJ which also stayed put (0.25%) & Ueda suggested that the central bank is cautious on further tightening amid ongoing uncertainty. This decision led to a drop in the Yen. Australia’s ASX 200 dipped 0.5% to 8,170.50 as the RBA prepared for a 2-day policy meeting. The NASDAQ and S&P500 stumbled on Friday to 17,948 and 5702. The Dow edged up 0.1%, reaching a new record high of 42,579. This week: key US economic data is expected, including reports on business activity, consumer spending, and a final revision of the economy’s growth during the spring. Financial Markets Performance: Gold surged to a record high, reaching $2,631.13, as traders anticipated more rate cuts by the Fed following its recent 50 bps reduction. Bullion’s momentum was further supported by concerns over rising tensions in the Middle East, with investors turning to gold as a safe-haven asset. Despite this rally, gold may be overbought, with its RSI nearing 70, a signal of possible short-term overextension. Meanwhile, silver, palladium, and platinum posted losses. USOIL rose to $71.59 per barrel, while UKOIL gained 52 cents, reaching $75.01 per barrel. Currently they have both seen a pullback slightly into EU open. Yen slid from last week’s high of around 140 per US dollar to 144.36 yen by today. The USDIndex steadied to 100.50 area. The Euro inched higher to 1.1164 but currently is steady after Germany’s Social Democrats narrowly defeated the far-right Alternative for Germany party, maintaining control of the eastern state of Brandenburg. Meanwhile, French Prime Minister Michel Barnier signaled potential tax increases on large corporations and the wealthy to address the country’s growing budget deficit. Always trade with strict risk management. Your capital is the single most important aspect of your trading business. Please note that times displayed based on local time zone and are from time of writing this report. Click HERE to access the full HFM Economic calendar. Want to learn to trade and analyse the markets? Join our webinars and get analysis and trading ideas combined with better understanding on how markets work. Click HERE to register for FREE! Click HERE to READ more Market news. Michalis Efthymiou Andria Pichidi HFMarkets Disclaimer: This material is provided as a general marketing communication for information purposes only and does not constitute an independent investment research. Nothing in this communication contains, or should be considered as containing, an investment advice or an investment recommendation or a solicitation for the purpose of buying or selling of any financial instrument. All information provided is gathered from reputable sources and any information containing an indication of past performance is not a guarantee or reliable indicator of future performance. Users acknowledge that any investment in FX and CFDs products is characterized by a certain degree of uncertainty and that any investment of this nature involves a high level of risk for which the users are solely responsible and liable. We assume no liability for any loss arising from any investment made based on the information provided in this communication. This communication must not be reproduced or further distributed without our prior written permission.
    • its a good site, they do have good rating system, if unsure go to forexpeacearmy they have better insight for forex broker reviews and news..
    • ASPN Aspen Aerogels stock, nice move higher off the 24 triple support area, from Stocks to Watch at https://stockconsultant.com/?ASPN
    • PSNL Personalis stock watch for a narrow range breakout, target 7.76 at https://stockconsultant.com/?PSNL
    • VAC Marriott Vacations stock, watch for a bottom breakout at https://stockconsultant.com/?VAC
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.