Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, The_Judge, Grant), 898 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
What's your favourite way of defining breakouts? #441652
05/29/14 16:47
05/29/14 16:47
Joined: Apr 2014
Posts: 45
Germany
webradio Offline OP
Newbie
webradio  Offline OP
Newbie

Joined: Apr 2014
Posts: 45
Germany
I'm thinking about a simple indicator for finding point 2 breakouts of 1-2-3 pattern or from a range. Donchian Channel (highest high / lowest low among last X bars) isn't very appealing because of it's fixed length: e.g. penetrating a 14-bar high doesn't mean a lot if 14 bars ago the price was just rolling downhill keeping making lower highs. More interesting would be to locate a recent local extreme.

Here's my attempt. Every time a bar is complete, let's define upper and lower price levels; if one of those is violated, it will be called a breakout. Upper level will be a high of one of preceeding bars. But of which one? Not simply "highest high of fourteen bars". Walking through preceeding bars, we determine for each of them: how many periods ago was this bar (lets call it LAG) and how SIGNIFICANT was its high - that will be the number of periods we have to walk even deeper into the past to find an even higher high.

Lets define IMPORTANCE = SIGNIFICANCE / LAG.

Upper breakout level is then the high of the bar having the largest IMPORTANCE value. The more significant and recent is the high, the more we like it as breakout level.

To avoid overemphasizing the SIGNIFICANCE over LAG, it can be replaced by natural logarithm of 1+SIGNIFICANCE.

On sceenshots, every time a bar penetrates a dot, a breakout (as defined above) takes place. You see that those dots are at levels of one of preceeding bars' high or low, choosen as described above. On the second screenshot, 14-bar Donchian is added.

indicator attempt, "significant recent extremes"
comparing with Donchian

What's your favourite way of defining breakouts?

Re: What's your favourite way of defining breakouts? [Re: webradio] #441653
05/29/14 16:50
05/29/14 16:50
Joined: Apr 2014
Posts: 45
Germany
webradio Offline OP
Newbie
webradio  Offline OP
Newbie

Joined: Apr 2014
Posts: 45
Germany
here's the code, sorry for MQL4 in Zorro forum - still have to master liteC... Is anybody kind enough to port it to liteC? wink
Code:
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Up
#property indicator_label1  "Up"
#property indicator_type1   DRAW_ARROW
#property indicator_color1  clrBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Down
#property indicator_label2  "Down"
#property indicator_type2   DRAW_ARROW
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input int      periods=50;
//--- indicator buffers
double         Up[];
double         Down[];
//---
//bool FirstPass = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,Up);
   SetIndexBuffer(1,Down);
   SetIndexArrow(0,159);
   SetIndexArrow(1,159);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[])
{
  int toCount, i, j, significance, bestj, bestsignificance;
  double importance, bestimportance;
  toCount = (int)MathMin(rates_total, rates_total - prev_calculated + 1);
  for (i = toCount - 2*periods; i >= 0; --i) {
    bestj = i+1;
    bestimportance = 0.0;
    for (j = i+1; j <= i+periods; ++j) {
      if ((j <= i+1)/*bar just before i*/ || (High[j] > High[iHighest(NULL, NULL, MODE_HIGH, (j-1)-(i+1)+1, i+1)])/*there is no higher high after j till i+1*/) { 
        for (significance = 0; significance <= periods; ++significance) {
          if (High[j+significance] > High[j]) { break; }
        }
        importance = MathLog(1.0+(double)significance) / (j-i); // j-i is "LAG"
        if ((j-i>=2) && (importance > bestimportance)) {
          bestimportance = importance;
          bestj = j;
          bestsignificance = significance;
        }
      }
    }
    Up[i] = High[bestj];
    //if (FirstPass) { printf("  Up: i=%d (%s); j=%d; significance=%d; lag=%d; importance=%f", i, TimeToStr(Time[i], TIME_DATE||TIME_MINUTES), bestj, bestsignificance, (bestj-i), bestimportance); }
    
    bestj = i+1;
    bestimportance = 0.0;
    for (j = i+1; j <= i+periods; ++j) {
      if ((j <= i+1)/*bar just before i*/ || (Low[j] < Low[iLowest(NULL, NULL, MODE_LOW, (j-1)-(i+1)+1, i+1)])/*there is no lower low after j till i+1*/) { 
        for (significance = 0; significance <= periods; ++significance) {
          if (Low[j+significance] < Low[j]) { break; }
        }
        importance = MathLog(1.0+(double)significance) / (j-i); // j-i is "LAG"
        if ((j-i>=2) && (importance > bestimportance)) {
          bestimportance = importance;
          bestj = j;
          bestsignificance = significance;
        }
      }
    }
    Down[i] = Low[bestj];
    //if (FirstPass) { printf("Down: i=%d (%s); j=%d; significance=%d; lag=%d; importance=%f", i, TimeToStr(Time[i], TIME_DATE||TIME_MINUTES), bestj, bestsignificance, (bestj-i), bestimportance); }
  }
  //FirstPass = false;
  return(rates_total);
}
//+------------------------------------------------------------------+


Re: What's your favourite way of defining breakouts? [Re: webradio] #442699
06/30/14 10:28
06/30/14 10:28
Joined: May 2014
Posts: 1
P
pipkiller Offline
Guest
pipkiller  Offline
Guest
P

Joined: May 2014
Posts: 1
I'm a beginner with Zorro. But I'd like to develop and test an "inside day breakout strategy". Where a break-out is defined as follows:
1) An "inside" bar is a bar(bar 2) there the full bar(open, close, high and low) is completely within the previous bar's range (bar 3).
2) A break-out is when the newest bar (bar 1) breaks out of the range of the previous bar
3) It is only used as a signal if the break-out is in the direction of the trend

Since inside-day-breakouts are not that common, it would need to loop through some assets every day to find opportunities.

I've already started on the script, but getting very simple things to work is taking me quite some time.
Maybe someone with a bit more Zorro scripting experience can make a start on this strategy and share the script? This way we can develop, backtest and polish this a lot faster than I can do on my own.

This way we can find out if this strategy can make any real money or not!


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1