Strategy Based On Chart Pattern

trading strategies and money management discussion, code, results

Moderator: moderators

User avatar
michal.kreslik
rank: 1000+ posts
rank: 1000+ posts
Posts: 1032
Joined: Sat May 13, 2006 2:40 am
Reputation: 0
Location: Monte Carlo, Monaco
Real name: Michal Kreslik
Gender: Male
Contact:

Postby michal.kreslik » Wed May 24, 2006 11:21 am

I know exactly what you are talking about.

I always perform a full backup and then (and only then) I upgrade to the latest Tradestation version. I do this on one of my computers only and if the new version holds up for 2 days, I upgrade it on the other computers, too.

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

bearwatch
rank: <50 posts
rank: <50 posts
Posts: 31
Joined: Tue May 30, 2006 9:44 am
Reputation: 0
Gender: Male

Postby bearwatch » Tue May 30, 2006 8:42 pm

Hi FD1,

Very interesting trading method, and very intrigued in your use of support and resistance. Your approach is much simpler than mine since I use the good old TA with patterns everyone already knows... wedges, pennants, triangles, heads and shoulders, so imagine how hard it is to code these.

Anyway, if it's as simple as you explain it, it might be doable. In the next following weeks, I'll take up this challenge, but I'll need your full collaboration. I'll download these and see what we can do.

PM me if want to.

User avatar
michal.kreslik
rank: 1000+ posts
rank: 1000+ posts
Posts: 1032
Joined: Sat May 13, 2006 2:40 am
Reputation: 0
Location: Monte Carlo, Monaco
Real name: Michal Kreslik
Gender: Male
Contact:

Postby michal.kreslik » Mon Jun 05, 2006 3:54 pm

Hello,

davidf asked me to post fatdog's code for the DarvasBox strategy so that he might try to convert the strategy to MetaQuotes Language 4 for MetaTrader4.

So here it is:

Code: Select all

[LegacyColorValue = true];

// $_DarvasBox

     
inputs:
 iDecimals( 2 ) ,

iMsgLong("Above Box Top"),

iMsgShort("Below Box Bottom"),

iMsgFlat("INSIDE BOX"),


iMsgXAbove("XA Box Top"),

iMsgXBelow("XB Box Bottom"),

   ShowAll  ( true ) ;

inputs:


 ShareOrPosition( 1 ), { pass in 1 for per share basis, 2 for position basis }

 ProfitTargetAmt( .12 ), { pass in 0 if you don't want a profit target } 
      
 StopLossAmt( 0 ), { pass in 0 if you don't want a stop loss }
    
 BreakevenFloorAmt( 0 ), { pass in 0 if you don't want a breakeven stop }
 DollarTrailingAmt( 0 ), { pass in 0 if you don't want a dollar trailing stop }
 PctTrailingFloorAmt( 0 ), { pass in 0 here and/or in next input if you don't want
  a percent trailing stop }
 PctTrailingPct( 0 ), { pass in 0 here and/or in previous input if you don't want
  a percent trailing stop; else pass in XX for XX percent }
 ExitOnClose( TRUE ) ; { pass in true if you want to exit the position at the
  close of the day, else pass in false. CAUTION: We recommend that you set this to
  TRUE only for back-testing, if at all; in automated execution, the exit order
  will NOT be filled at the close of the day; instead, the order can be sent into
  the extended session as a limit order. }

variables:
   BoxTop   ( 0 ) ,
   BoxBtm   ( 0 ) ,
   Ctr      ( 0 ) ,
   BBD      ( 0 ) ,
   BBT      ( 0 ) ,
   EBD      ( 0 ) ,
   EBT      ( 0 ) ,
   TextId   ( -1 ) ,
   TopId    ( -1 ) ,
   TopIdP   ( -1 ) ,
   BtmId    ( -1 ) ,
   BtmIdP   ( -1 ) ,
   LSId     ( -1 ) ,
   LSIdP    ( -1 ) ,
   RSId     ( -1 ) ,
   RSIdP    ( -1 ) ,
   UpBand   ( 0 ) ,
   DnBand   ( 0 ) ,
   CurrState( 1 ) ,
   HiFirst  ( true ) ,
   LoFirst  ( false ) ,
   State1   ( false ) ,
   State2   ( false ) ,
   State3   ( false ) ,
   State4   ( false ) ,
   State5   ( false ) ,
   DrawBox  ( false ) ,
   ValidBox ( false ) ,
   HadBreak ( false ) ,
   NewBox   ( false ) ;




variables:
 
tTrade(""),

   tDrawBox  ( "" ) ,
   tValidBox ( "" ) ,
   tHadBreak ( "" ) ,
   tNewBox   ( "" ) ,


xBoxTop   ( 0 ) ,
xBoxBtm   ( 0 ) ,


xBoxRange(0),
xBoxPosition(0),

tInd(""),
tAlert(""),

FG1(white),
BG1(black),

fg2(white),
bg2(black),

fg3(white),
bg3(black),

fg4(white),
bg4(black);
   



{commentary variables}
variables:
xcomm(0),
oComm1( "" ),    
oComm2( "" ),    
oComm3( "" ),    
oComm4( "" ),    
oComm5( "" ),
oComm6( "" ),
oComm7( "" ),
oComm8( "" ),
oComm9( "" ),    
oComm10( "" );
   

{ INITIALIZE }

tInd   = "";
tAlert  = "";
tTrade  = "";

FG1 = WHITE;
BG1 = BLACK;

fg2 = WHITE;
bg2 = BLACK;

fg3 = WHITE;
bg3 = BLACK;

fg4 = WHITE;
bg4 = BLACK;


{ PROCESSING }

if BarNumber = 1 then
   begin
      BoxTop = high ;
      BoxBtm = low ;
      State1 = true ;
      BBD    = date ;
      BBT    = time ;
   end ;



if NewBox and high > UpBand then
   begin
      BBD      = date ;
      BBT      = time ;
      

      xBoxTop = UpBand ;
      xBoxBtm = DnBand ;

      TL_SetEnd( TopId, BBD, BBT, UpBand ) ;
      TL_SetEnd( BtmId, BBD, BBt, DnBand ) ;
      
      RSIdP  = RSId ;
      RSId  = TL_New( BBD, BBT, DnBand, BBD, BBT, UpBand ) ;
      
      if ShowAll = false and RSIdP <> -1 then
         TL_Delete( RSIdP ) ;   

      if HiFirst then
         TL_SetColor( RSId, yellow )
      else
         TL_SetColor( RSId, magenta ) ;
   
      NewBox   = false ;
      State1   = true ;
      LoFirst  = false ;
      HiFirst  = true ;      
   end ;

if NewBox and low < DnBand then
   begin
      BBD      = date ;
      BBT      = time ;

      xBoxTop = UpBand ;
      xBoxBtm = DnBand ;

      TL_SetEnd( TopId, BBD, BBT, UpBand ) ;
      TL_SetEnd( BtmId, BBD, BBt, DnBand ) ;

      RSIdP  = RSId ;
      RSId  = TL_New( BBD, BBT, DnBand, BBD, BBT, UpBand ) ;
      
      if ShowAll = false and RSIdP <> -1 then
         TL_Delete( RSIdP ) ;   

      if HiFirst then
         TL_SetColor( RSId, yellow )
      else
         TL_SetColor( RSId, magenta ) ;

      NewBox   = false ;
      State1   = true ;
      HiFirst  = false ;
      LoFirst  = true ;      
   end ;


if HiFirst then
   begin      
      if State4 then
         begin
            if high > BoxTop then
               begin
                  BoxTop = high ;
                  State1 = true ;
                  State4 = false ;
                  CurrState = 1 ;
               end
            else
               begin
                  if low < BoxBtm then
                     begin
                        State4 = false ;
                        State3 = true ;
                        BoxBtm = low ;
                        CurrState = 3 ;
                     end
                  else
                     begin
                        State4 = false ;
                        State5 = true ;
                        CurrState = 5 ;
                     end ;
               end ;
         end ;
      
      if State3 then
         begin
            if high > BoxTop then
               begin
                  BoxTop = high ;         
                  State1 = true ;
                  State3 = false ;
                  CurrState = 1 ;
               end
            else
               begin
                  if low < BoxBtm then
                     begin
                        State3 = true ;
                        BoxBtm = low ;
                        CurrState = 3 ;
                     end
                  else
                     begin
                        State3 = false ;
                        State4 = true ;
                        CurrState = 4 ;
                     end ;
               end ;
         end ;
      
      if State2 then
         if high > BoxTop then
            begin
               BoxTop = high ;            
               State1 = true ;
               State2 = false ;
               CurrState = 1 ;
            end
         else
            begin
               State2 = false ;
               State3 = true ;
               BoxBtm = low ;
               CurrState = 3 ;
            end ;
      
      if State1 then
         if high > BoxTop then
            begin
               BoxTop = high ;         
               State1 = true ;
               CurrState = 1 ;
            end
         else
            begin
               State1 = false ;
               State2 = true ;
               CurrState = 2 ;
            end ;
   end
else { Using LoFirst }
   begin
      if State4 then
         begin
            if low < BoxBtm then
               begin
                  BoxBtm = low ;
                  State1 = true ;
                  State4 = false ;
                  CurrState = 1 ;
               end
            else
               begin
                  if high > BoxTop then
                     begin
                        State3 = true ;
                        State4 = false ;
                        BoxTop = high ;
                        CurrState = 3 ;
                     end
                  else
                     begin
                        State4 = false ;
                        State5 = true ;
                        CurrState = 5 ;
                     end ;
               end ;
         end ;
      
      if State3 then
         begin
            if low < BoxBtm then
               begin
                  BoxBtm = low ;         
                  State1 = true ;
                  State3 = false ;
                  CurrState = 1 ;
               end
            else
               begin
                  if high > BoxTop then
                     begin
                        State3 = true ;
                        BoxTop = high ;
                        CurrState = 3 ;
                     end
                  else
                     begin
                        State3 = false ;
                        State4 = true ;
                        CurrState = 4 ;
                     end ;
               end ;
         end ;
      
      if State2 then
         if low < BoxBtm then
            begin
               Boxbtm = low ;            
               State1 = true ;
               State2 = false ;
               CurrState = 1 ;
            end
         else
            begin
               State2 = false ;
               State3 = true ;
               BoxTop = high ;
               CurrState = 3 ;
            end ;
      
      if State1 then
         if low < BoxBtm then
            begin
               BoxBtm = low ;         
               State1 = true ;
               CurrState = 1 ;
            end
         else
            begin
               State1 = false ;
               State2 = true ;
               CurrState = 2 ;
            end ;
   end ; { END IF HIFIRST OR LOFIRST }   

if State5 then   
   begin
      DrawBox  = true ;
      EBD      = date ;
      EBT      = time ;
   end ;
         

if DrawBox then
   begin
   
      TopIdP = TopId ;
      BtmIdP = BtmId ;
      LSIdP  = LSId ;   
      
      TopId = TL_New( BBD, BBT, BoxTop, EBD, EBT, BoxTop ) ;
      BtmId = TL_New( BBD, BBT, BoxBtm, EBD, EBT, BoxBtm ) ;
      LSId  = TL_New( BBD, BBT, BoxBtm, BBD, BBT, BoxTop ) ;
      
      if ShowAll = false then
         begin
            if TopIdP <> -1 then
               TL_Delete( TopIdP ) ;
            if BtmIdP <> -1 then
               TL_Delete( BtmIdP ) ;
            if LSIdP <> -1 then
               TL_Delete( LSidP ) ;
                      
         end ;
      
      if HiFirst then
         begin
            TL_SetColor( TopId, yellow ) ;
            TL_SetColor( BtmId, yellow ) ;
            TL_SetColor( LSId,  yellow ) ;            
         end
      else
         begin      
            TL_SetColor( TopId, magenta ) ;
            TL_SetColor( BtmId, magenta ) ;
            TL_SetColor( LSId,  magenta ) ;      
         end ;
         
      State1   = false ;
      State2   = false ;
      State3   = false ;
      State4   = false ;
      State5   = false ;
      DrawBox  = false ;
      ValidBox = true ;      
   end ;
      


if ValidBox then
   begin

      UpBand   = BoxTop ;
      DnBand   = BoxBtm ;
      ValidBox = false ;
      NewBox   = true ;
      BoxTop   = high ;
      BoxBtm   = low ;   
   end ;


{
if HiFirst then
   TextId = Text_New( date, time, high * 1.002, NumToStr( CurrState, 0 ) )
else
   TextId = Text_New( date, time, low * .998 , NumToStr( CurrState, 0 ) ) ;
}

{ Alert criteria }



If close crosses above xBoxTop
then begin
   tInd = iMsgXAbove ;
   Fg1 = darkgreen;
   Bg1 = white;
   tTrade  = "Buy";
end
else
If close crosses below xBoxBtm
then begin
   tInd = iMsgXBelow ;
   Fg1 = red;
   Bg1 = white;
   tTrade  = "Short";
end
else
If close > xBoxTop
then begin
   tInd = iMsgLong ;
   Fg1 = green;
   Bg1 = BLACK;
end
else
If close < xBoxBtm
then begin
   tInd = iMsgShort ;
   Fg1 = red;
   Bg1 = BLACK;
end
else
begin
   tInd = iMsgFlat ;
   Fg1 = white;
   Bg1 = BLACK;
end;



If tTrade  = "Buy"
   then Buy next bar at market
else
If tTrade  = "Short"
   then Sell Short next bar at market;


{*************************************************}
{              T A K E   P R O F I T              }
{*************************************************}

if ShareOrPosition = 1
   then  SetStopShare
   else  SetStopPosition ;


if ProfitTargetAmt  > 0 then
 SetProfitTarget( ProfitTargetAmt  ) ;

if StopLossAmt > 0 then
 SetStopLoss( StopLossAmt ) ;

if BreakevenFloorAmt > 0 then
 SetBreakeven( BreakevenFloorAmt ) ;

if DollarTrailingAmt > 0 then
  SetDollarTrailing( DollarTrailingAmt ) ;

if PctTrailingFloorAmt > 0 and PctTrailingPct > 0 then
 SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ;

if ExitOnClose = true then
 SetExitOnClose ;

User avatar
michal.kreslik
rank: 1000+ posts
rank: 1000+ posts
Posts: 1032
Joined: Sat May 13, 2006 2:40 am
Reputation: 0
Location: Monte Carlo, Monaco
Real name: Michal Kreslik
Gender: Male
Contact:

Postby michal.kreslik » Fri Jun 09, 2006 10:52 am

We have added a new feature to the forums: the maximum inline image that can be displayed directly in the forum is set to 1000 pixels. If the attached image exceeds this value, the image won't be displayed directly on the page, but rather will be attached as a file to the post. You may simply click on the attachement and this larger image will be displayed in a newly opened window.

This is to prevent too wide images to be posted on the forums directly. These wide images then worsen the readability of the thread.

I think 1000 pixels is a generous measure.

Have a look at an example of how it works:

http://kreslik.com/forums/viewtopic.php?p=250#250

I am posting this message here because there are lots of too wide images in this thread, so don't be surprised you can't see them inline anymore. You can still display them in a separate window if you click on the image attachement.

Michal

bearwatch
rank: <50 posts
rank: <50 posts
Posts: 31
Joined: Tue May 30, 2006 9:44 am
Reputation: 0
Gender: Male

Postby bearwatch » Fri Jun 09, 2006 11:07 am

FD1, please continue posting, I'm trying to follow your strategy to put some ideas together. One question I do have is if the top and bottom of the last 2-3 boxes back from current bar, will this be remembered? Should it be recorded for later use?

Michal, one question I have is can we subscribe to a particular user so when he/she posts, I get notified? This feature is available in TS forum, would like to see it here too. Thanks.

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.

User avatar
michal.kreslik
rank: 1000+ posts
rank: 1000+ posts
Posts: 1032
Joined: Sat May 13, 2006 2:40 am
Reputation: 0
Location: Monte Carlo, Monaco
Real name: Michal Kreslik
Gender: Male
Contact:

Postby michal.kreslik » Fri Jun 09, 2006 11:18 am

bearwatch,

that's a good idea, we will work on that. Anyway, you should post these suggestions in the "website suggestions" forum, otherwise I might not get to them.

We have added one more image-wise feature now. There will be automatically created a resized thumbnail for every image that exceeds the 1000 pixels width. You can click on the thumbnail and the picture will be shown in a newly opened window.

This feature will create a thumbnail for all new posts that contain an image wider than 1000 pixels.

An example:
Attachments
5000_width_2000_height.jpg

fatdog1
rank: 150+ posts
rank: 150+ posts
Posts: 164
Joined: Thu May 18, 2006 11:58 am
Reputation: 0
Gender: Male
Contact:

Postby fatdog1 » Sat Jun 10, 2006 2:25 am

Hi Guys,
Sorry for not posting but I have been very busy.
The small screenshot need to be saved that way to be able to post it.

Bearwatch, yes and no on remembering candles in the future.

The no reason is I don't use time in my pattern.

I use the begining of a key reversal as a way to get in close to an area of support or resistance.

I know the area is good when the key reversal bar happens.

After studing the pattern, I have determined that the first key reversal candle is the most important part of the pattern.

It needs to be a strong reversal from a down trend for a up trend to begin or resume to get me in at the beginning of a move.

After that, the DarvasBox breakout of a congestion area is the next best place to enter a trade in the direction of the key reversal candle.

The DarvasBox as it is currently coded will lose frequently since it will take shorts and longs anytime the box is broken. If you are near support when the short trade is taken, you will lose 99.9% of the time. How much you lose is then determined depending on where your "stop loss" is. The 99.9% is especially true if it is the first time back to the breakout line from a former congestion area. Your odds of a break down in your favor increase the more times back to the breakout line since the number of left behind willing buyers will be reduced each time price returns to the former resistance.

I think adding the condition that longs are taken on a break of a DarvasBox only after a key reversal bar or candle, and same with short trades will cut down on the number of losing trades.

The yes reason is after the pattern has formed, I want to buy the first pullback to the breakout point in the future. That pullback could happen today, tomorrow, next week or 6 years from now.
This is how I can tell when and where the key areas of support or resistance are. I place horizontal lines on the charts.
If I can not find recent resistance, I scroll to the left of the chart.

If we are at 6 year highs in the S & P's, Dow, BRCM, ect. I go back 6 years ago to find resistance.

I get a kick out of people who use Fibs, Pivots, Gann. The only time they work is when they accidently form near true support and resistance.

Chicken or the egg. Which came first, the Fib, or the price revisiting old S/R.

FD1

User avatar
michal.kreslik
rank: 1000+ posts
rank: 1000+ posts
Posts: 1032
Joined: Sat May 13, 2006 2:40 am
Reputation: 0
Location: Monte Carlo, Monaco
Real name: Michal Kreslik
Gender: Male
Contact:

Postby michal.kreslik » Sun Jun 11, 2006 10:07 pm

fatdog1 wrote:The small screenshot need to be saved that way to be able to post it.


fd,

you don't stuff your head with the attachements size. The system does this for you:

- if you post a picture attachement that is wider than 1000 pixels, the system will automatically create a smaller thumbnail and will display this thumbnail along with your post. Then if you click this thumbnail, a new page with an original (not resized) version of your picture opens

- if you post a picture attachement that is up to 1000 pixels wide, the system will attach this very picture directly to the post and won't create any thumbnail of it

Michal

fatdog1
rank: 150+ posts
rank: 150+ posts
Posts: 164
Joined: Thu May 18, 2006 11:58 am
Reputation: 0
Gender: Male
Contact:

Postby fatdog1 » Mon Jun 12, 2006 12:40 am

michal.kreslik wrote:
fatdog1 wrote:The small screenshot need to be saved that way to be able to post it.


fd,

you don't stuff your head with the attachements size. The system does this for you:

- if you post a picture attachement that is wider than 1000 pixels, the system will automatically create a smaller thumbnail and will display this thumbnail along with your post. Then if you click this thumbnail, a new page with an original (not resized) version of your picture opens

- if you post a picture attachement that is up to 1000 pixels wide, the system will attach this very picture directly to the post and won't create any thumbnail of it

Michal


Hi Michal,
Let's give it a try. It did not let me post a screen shot on Saturday.

fatdog1
rank: 150+ posts
rank: 150+ posts
Posts: 164
Joined: Thu May 18, 2006 11:58 am
Reputation: 0
Gender: Male
Contact:

Postby fatdog1 » Mon Jun 12, 2006 12:41 am

The Attachment/Image must be less than 1000 pixels wide and 2000 pixels high

I get this error message again.

Sorry

Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.


Return to “strategy trading & money management”