Tradery Forum Index Tradery
Trading tools and community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Simple Slow Stochastic System

 
Post new topic   Reply to topic    Tradery Forum Index -> Trading systems
View previous topic :: View next topic  
Author Message
gch2010



Joined: 17 Mar 2010
Posts: 2

PostPosted: Wed Mar 17, 2010 1:18 pm    Post subject: Simple Slow Stochastic System Reply with quote

Hey,

I'm trying to implement a simple slow stochastic system. Here's what it should do:
- Buy when the %D is below the oversold line (20%) and the %K crosses over it.
- Sell when the %D is above the overbought line (80%) and the %D crosses under it.

I'm very new to "tradery" and not very familiar with the entry and exit functions.
Can someone help me get started with it?

Thanks
Back to top
View user's profile Send private message
gch2010



Joined: 17 Mar 2010
Posts: 2

PostPosted: Wed Mar 17, 2010 3:53 pm    Post subject: Reply with quote

OK so I've been working on it for the past few hours, and this is what i arrived to:
Code:

//This is simple Slow Stochastic implementation
//Applied to the GOOG symbol

void run()
{
   Bars goog = bars("GOOG");
   Series stochSlowD;
   Series stochSlowK;


   if (goog)
   {
      stochSlowD = goog.StochSlowD(5, 10, SMA, 5, SMA);
      stochSlowK = goog.StochSlowK(5, 10, SMA, 5, SMA);
   }
    else
    {
       // we don't have data, print an error message
       PrintLine( "No data for symbol GOOG" );
       return;
    }
   
    Series overbought(size());
    Series oversold(size());
   
    for (unsigned int i=0; i< size(); i++)
    {
       overbought.setValue(i, 80);
       oversold.setValue(i, 20);
    }
   
    Pane pane1 = createPane("Stochastic");
    pane1.drawSeries("Slow % D", stochSlowD, RED);
    pane1.drawSeries("Slow % K", stochSlowK, BLUE);
    pane1.drawSeries("Overbought (80)", overbought, SILVER);
    pane1.drawSeries("Oversold (20)", oversold, SILVER);
   
    // this is the bar loop
    for( Index bar = 1; bar <size>80 AND
              stochSlowK[bar-1]>stochSlowD[bar] AND
              stochSlowK[bar]<stochSlowD[bar])
          {
             bool sold = sellAtMarket(bar+1, pos, "Selling at Market");
             if (sold)
             {
                PrintLine("Position closed on: " << pos.getCloseTime().toString() << ", at Market: " << pos.getClosePrice());
                PrintLine("Profit Made: "<<pos.getGain());
             }
          }
   }

   // position entry logic
   // Below undersold
   if (stochSlowD[bar]<20 AND
       stochSlowK[bar-1]<stochSlowD>stochSlowD[bar] AND
       !hasOpenPositions()
       )
   {
      PositionId id = buyAtMarket(bar+1, 1000, "Buying 1000 shares at market");
      Position pos2 = getPosition(id);
      if (pos2)
      {
         PrintLine("Position entered on: " << pos2.getEntryTime().toString() << ", at Market: " << pos2.getEntryPrice());
      }
   }
       
    }
}


I know it's not very well written but it does the job. I'm trying to integrate RSI with it for trend detection.
Please let me know how I can improve my system Very Happy

Thanks
Back to top
View user's profile Send private message
vovay45



Joined: 09 Jan 2008
Posts: 356
Location: San Francisco

PostPosted: Mon Mar 22, 2010 5:33 pm    Post subject: Reply with quote

My implementation of gch2010 idea but not only for GOOG

Code:
//SlowK-SlowD

Series stochSlowK;
Series stochSlowD;

bool init()
{
   stochSlowK = DEF_BARS.StochSlowK(5, 10, SMA, 5, SMA);
   stochSlowD = DEF_BARS.StochSlowD(5, 10, SMA, 5, SMA);
   return true;
}
void run()
{
  PositionId LongPosition = 0;
  for( Index bar = 10; bar < barsCount(); bar++ )
  {
    if (LongPosition )
    {
      if(stochSlowK[bar-1]>stochSlowD[bar-1]
         && stochSlowK[bar]<stochSlowD[bar]
         && stochSlowD[bar]>80 )
      {
            sellAtMarket(bar+1,LongPosition,"XLM"); 
            LongPosition = 0;
      }             
    }
    else
    {
      if(stochSlowK[bar-1]<stochSlowD[bar-1]
         && stochSlowK[bar]>stochSlowD[bar]
         && stochSlowD[bar]<20)
      { 
            LongPosition=buyAtMarket(bar+1, 1000, "ELM" );
      }       
    }         
  }
}


VY
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Tradery Forum Index -> Trading systems All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group