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.


×
×
  • Create New...

Important Information

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