HomeSample Page

Sample Page Title


That may be a fast write up , right here is the code :

#property model   "1.00"
#property indicator_chart_window
#property indicator_buffers 10
#property indicator_plots   1
enter int SpinePeriod=4;
enter ENUM_APPLIED_PRICE SpinePrice=PRICE_MEDIAN;
enter int SlowsPeriod=200;
enter int FastsPeriod=7;
enter string noteA="STYLING";
enter colour SpineColor=clrWhite;
enter ENUM_LINE_STYLE SpineStyle=STYLE_SOLID;
enter int SpineWidth=1;

double Backbone[],spinePeriod[];
double DeltaHighToSpine[],DeltaLowToSpine[];
double SlowHighToSpineAvg[],SlowLowToSpineAvg[],SlowPeriods[];
double FastHighToSpineAvg[],FastLowToSpineAvg[],FastPeriods[];
bool RatesSeries=false;
double FullSpine=0.0,FullSlow=0.0,FullFast=0.0;



int OnInit()
  {

   int co=0;
   RatesSeries=false;
   SetIndexBuffer(co,Backbone,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_LINE);
      PlotIndexSetInteger(co,PLOT_LINE_COLOR,SpineColor);
      PlotIndexSetInteger(co,PLOT_LINE_STYLE,SpineStyle);
      PlotIndexSetInteger(co,PLOT_LINE_WIDTH,SpineWidth);
   co++;
   SetIndexBuffer(co,spinePeriod,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,DeltaHighToSpine,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,DeltaLowToSpine,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,SlowHighToSpineAvg,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,SlowLowToSpineAvg,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,SlowPeriods,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,FastHighToSpineAvg,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,FastLowToSpineAvg,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   co++;
   SetIndexBuffer(co,FastPeriods,INDICATOR_DATA);
      PlotIndexSetInteger(co,PLOT_DRAW_TYPE,DRAW_NONE);
   FullSpine=SpinePeriod;
   FullFast=FastsPeriod;
   FullSlow=SlowsPeriod;

   return(INIT_SUCCEEDED);
  }



int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &excessive[],
                const double &low[],
                const double &shut[],
                const lengthy &tick_volume[],
                const lengthy &quantity[],
                const int &unfold[])
  {
  if(SymbolIsSynchronized(_Symbol)){
  
  
    int from=prev_calculated+1,to=rates_total;
    if(prev_calculated==0){
    
    if(ArrayIsSeries(open)){RatesSeries=true;}
       ArrayFill(Backbone,0,ArraySize(Backbone),0.0);
       ArrayFill(spinePeriod,0,ArraySize(spinePeriod),0.0);
       ArrayFill(DeltaHighToSpine,0,ArraySize(DeltaHighToSpine),0.0);
       ArrayFill(DeltaLowToSpine,0,ArraySize(DeltaLowToSpine),0.0);
       ArrayFill(SlowHighToSpineAvg,0,ArraySize(SlowHighToSpineAvg),0.0);
       ArrayFill(SlowLowToSpineAvg,0,ArraySize(SlowLowToSpineAvg),0.0);
       ArrayFill(SlowPeriods,0,ArraySize(SlowPeriods),0.0);
       ArrayFill(FastHighToSpineAvg,0,ArraySize(FastHighToSpineAvg),0.0);
       ArrayFill(FastLowToSpineAvg,0,ArraySize(FastLowToSpineAvg),0.0);
       ArrayFill(FastPeriods,0,ArraySize(FastPeriods),0.0);
    }
    
  
    for(int i=from;i<rates_total;i++){
      int j=i;
      if(!RatesSeries){j=rates_total-i-1;}
    
      spinePeriod[i]=spinePeriod[i-1];
      Backbone[i]=Backbone[i-1];
      add_to_rolling_average(get_prices(open[j],excessive[j],low[j],shut[j],SpinePrice),spinePeriod[i],SpinePeriod,Backbone[i]);
    
    
      if(spinePeriod[i]==FullSpine){
      DeltaHighToSpine[i]=MathAbs(excessive[j]-Backbone[i]);
      DeltaLowToSpine[i]=MathAbs(low[j]-Backbone[i]);
      
        
          SlowHighToSpineAvg[i]=SlowHighToSpineAvg[i-1];
          SlowLowToSpineAvg[i]=SlowLowToSpineAvg[i-1];
          SlowPeriods[i]=SlowPeriods[i-1];
          FastHighToSpineAvg[i]=FastHighToSpineAvg[i-1];
          FastLowToSpineAvg[i]=FastLowToSpineAvg[i-1];
          FastPeriods[i]=FastPeriods[i-1];
        
        add_to_rolling_average(DeltaHighToSpine[i],SlowPeriods[i],SlowsPeriod,SlowHighToSpineAvg[i]);
        SlowPeriods[i]=SlowPeriods[i-1];
        add_to_rolling_average(DeltaLowToSpine[i],SlowPeriods[i],SlowsPeriod,SlowLowToSpineAvg[i]);
        
        add_to_rolling_average(DeltaHighToSpine[i],FastPeriods[i],FastsPeriod,FastHighToSpineAvg[i]);
        FastPeriods[i]=FastPeriods[i-1];
        add_to_rolling_average(DeltaLowToSpine[i],FastPeriods[i],FastsPeriod,FastLowToSpineAvg[i]);
      
      }
    
    }
  
  
  return(rates_total);
  }return(0);
  }

double get_prices(const double open,const double excessive,const double low,const double shut,ENUM_APPLIED_PRICE utilized){
double value=0.0;
     if(utilized==PRICE_CLOSE){value=shut;}
else if(utilized==PRICE_HIGH){value=excessive;}
else if(utilized==PRICE_LOW){value=low;}
else if(utilized==PRICE_OPEN){value=open;}
else if(utilized==PRICE_MEDIAN){value=NormalizeDouble((excessive+low)/2.00,_Digits);}
else if(utilized==PRICE_TYPICAL){value=NormalizeDouble((excessive+low+shut)/3.00,_Digits);}
else if(utilized==PRICE_WEIGHTED){value=NormalizeDouble((excessive+low+shut+shut)/4.00,_Digits);}
return(value);
}
void add_to_rolling_average(double knowledge,double &_total,int max,double &avg){
      _total+=1.0;
      int t=(int)MathRound(_total);
      
      if(t>max){
           
           avg=avg-(avg/((double)max))+(knowledge/((double)max));
           _total=max;    
           }
      
      else if(t==max){
           avg+=knowledge;
           avg/=((double)max);
           }
       
       else{
           avg+=knowledge;
           }
       }

We now have the backbone common , rolling .

When we’ve sufficient backbone durations we begin amassing backbone deltas.

We additionally rolling common them

Now right here is the bizarre try.

We wish to create an index which when added on the backbone it comes as shut as potential to the precise excessive costs.

We’ll name this highGuess . Identical for the lows , lowGuess.

So let’s set up extra guidelines :

  • we begin “optimizing” when we’ve full durations on the whole lot

We’re not taken with what occurred every yesterday with yesterdays backbone and yesterdays guesses , like analysts are . Nonono , we would like 

the yesterdays backbone to venture todays excessive and lows , and if it fails we can’t disguise it! So rule 2

Now let’s introduce extra weirdness . We now have fasts and slows proper ? 

If we’ve a plot that may be a composite of the gradual and quick and a toggle variable that adjusts the weights of how a lot quick and the way a lot gradual the

plot is we will get a fluctuating common , will not be correct , however , will not be gradual both (in crunch time).

So let’s name that X . If X is the burden , the % , the quantity of Fasts within the new plot then 1.00 – X is the % , the quantity of Slows within the Plot.

That may be very helpful as that is one unknown ! 

So , if we’ve :

  1. a accomplished bar
  2. with a earlier bar that has all rollings obtainable
  3. we all know the earlier to it backbone stage
  4. we all know its excessive and low
  5. we do not know what X is (or what X ought to have been)

And that is the bizarre half , we’ll use the X of the knowns because the “toggle” for the unknowns and , we’ll plot the guesses accordingly (together with our errors).

After that we may go forward and in addition rolling common the X! however one weirdness at a time .

So okay , we would like X , how can we get it ?

and for the Lows

If there is a mistake let me know . 

So let’s code it and see what occurs.

On first look its unstable , each guesses .

(white=backbone , blue=guess excessive, purple = guess low)

So what can we do? We will attempt including a rolling common to the x coefficients as effectively.

hmm not significantly better xD . Anyway that was enjoyable.

hooked up is the supply code.

–EDITS—–

However hold on , we’re getting excessive projections which might be beneath the backbone . 

Why ? as a result of the projection is predicated on the earlier backbone and we’ll solely know the present backbone as soon as the bar concludes .

There is no such thing as a level in projecting on the backbone because it evolves , we would like a transparent projection on the time of bar opening that claims 

excessive is right here , low is right here . We wish to commerce it not brag about it being proper yesterday .

Nevertheless , if we place ourselves on the time of a bar’s opening , we do have the open value .! proper ?

So , model 2 will be utilizing the open value for each testing and projecting as an alternative of the backbone .

Let’s have a look at the way it does.

Not a lot totally different , however i spotted that we’ve a problem anyway.

the Xs usually are not certain between 0 and 1 !

i will should give you one thing higher there.

Anyway attaching the model with opens as effectively.

Will replace when i discover a resolution 

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles