SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Mon Nov 30, 2020 5:50 pm

All times are UTC + 3 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: zig zag indicator
PostPosted: Thu Aug 16, 2007 5:11 am 
Offline

Joined: Wed Apr 25, 2007 4:15 pm
Posts: 7
does anyone have a good algorithm for implementing the ZigZag indicator?

any code snippets or articles are greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 20, 2007 1:03 am 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
I am also looking for similar thing, how to code to find the zigzag High/Low of the following.

It would be nice if the indicator would print HH (Higher High) or LL (Lower Low) or LH (Lower High) or Higher Low( HL) above and below each Peak!

It is easy to see from eyes, but is there any simple way to code?

Image


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 20, 2007 3:27 am 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
found this thread but I don't understand the program.

http://www.forex-tsd.com/indicators-met ... ators.html

not sure whether it has code segment to find High/Low?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 5:34 pm 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
Any way, I any how implement one as follow, some one here may be able to do better.

Code:
using System;
using System.Drawing;

using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyStrategy : Strategy
{
   
   private int barcount = 0;
   private double barclose = 0;
   private double barlow = 0;
   private double barhigh = 0;
   private double barlowest = 999999.0;
   private double barhighest = 0.0;
   private double HH1 = 0;
   private double HH2 = 0;
   private double LL1 = 0;
   private double LL2 = 0;
   private bool is_high = true;
   private bool is_low = false;
   private int HLbarcount = 0;
   
   DateTime barlowestDateTime;
   DateTime barhighestDateTime;
   
   TimeSeries HL;
   
   
   
   public override void OnStrategyStart()
   {
      HL = new TimeSeries("High-Low", Color.White);
      Draw(HL, 0);
   }

   public override void OnBar(Bar bar)
   {
      if ((bar.Close > 0) && (bar.High > 0) && (bar.Low > 0) && (bar.Open > 0))
      {   
         if (Mode != StrategyMode.Simulation)
         {
            DataManager.Add(Instrument, bar);
         }
         barcount++;
         HLbarcount++;
         barclose = bar.Close;
         barhigh = bar.High;
         barlow = bar.Low;

         
         if (barcount > 1)
         {
            if ((barlow) < barlowest)
            {
               barlowest = barlow;
               barlowestDateTime = bar.DateTime;
            }
         
            if ((barhigh) > barhighest)
            {
               barhighest = barhigh;
               barhighestDateTime = bar.DateTime;
            }         
         }      
         
         if (barcount > 4)
         {
            if ((HLbarcount > 3) && (is_low) && (Bars.Ago(0).High > Bars.Ago(3).High) && (Bars.Ago(0).Low > Bars.Ago(1).Low) && (Bars.Ago(0).Low > barlowest))
            {
               LL2 = LL1;
               LL1 = barlowest;
               if (LL1 != LL2)
               {
                  is_high = true;
                  is_low = false;
                  HL.Add(barlowestDateTime, barlowest);   
                  barhighest = Bars.HighestHigh(4);   
                  barhighestDateTime = bar.DateTime;
                  HLbarcount = 0;
                  HH1 = 0;
                  HH2 = 0;
                  Console.WriteLine("{0}     LL1 = {1}     barhighest = {2}", barlowestDateTime, LL1, barhighest);                                 
               }
            }
         
            if ((HLbarcount > 3) && (is_high) && (Bars.Ago(0).Low < Bars.Ago(3).Low)&& (Bars.Ago(0).High < Bars.Ago(1).High) && (Bars.Ago(0).High < barhighest))
            {
               HH2 = HH1;
               HH1 = barhighest;
               if (HH1 != HH2)
               {
                  is_low = true;
                  is_high = false;
                  HL.Add(barhighestDateTime, barhighest);      
                  barlowest =  Bars.LowestLow(4);
                  barlowestDateTime = bar.DateTime;
                  HLbarcount = 0;
                  LL1 = 0;
                  LL2 = 0;
                  Console.WriteLine("{0}     HH1 = {1}     barlowest = {2}", barhighestDateTime, HH1, barlowest);                                    
               }
            }

         }      
         
      }    
      else
      {
         Console.WriteLine("Instrument:    {0},       Date/Time:     {1}", Instrument, bar.DateTime);
      }
   }
}



Image


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 23, 2007 4:50 am 
Offline

Joined: Sun May 20, 2007 9:09 am
Posts: 351
By the way, how to make my above code into a custom indicator like SMA?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group