Reply

I want to transplant the zigzag index in MT4 to analyze the form in SQ

0 replies

Mayor Corn

Subscriber, bbp_participant, 1 replies.

Visit profile

2 weeks ago #271096

I like the zigzag morphological analysis index in MT4,I want to transplant the zigzag index in MT4 to analyze the form in SQ, but there is no problem with the code. It seems that there is a problem in the SQ chart.

 

package SQ.Blocks.Indicators.ZIGZAG;

import SQ.Calculators.HighestCalculator;
import SQ.Calculators.LowestCalculator;
import com.strategyquant.lib.*;
import com.strategyquant.datalib.*;
import com.strategyquant.tradinglib.*;

import SQ.Internal.IndicatorBlock;

/**
* Indicator name as it will be displayed in UI, and its return type.
* Possible return types:
* ReturnTypes.Price – indicator is drawn on the price chart, like SMA, Bollinger Bands etc.
* ReturnTypes.Number – indicator is drawn on separate chart, like CCI, RSI, MACD
* ReturnTypes.PriceRange – indicator is price range, like ATR.
*/
@BuildingBlock(name=”(ZIGZAG) ZIGZAG”, display=”ZIGZAG(#InpDepth#,#InpDeviation#,#InpBackstep#)[#Shift#]”, returnType = ReturnTypes.Price)
@Help(“ZIGZAG help text”)
public class ZIGZAG extends IndicatorBlock {

@Parameter
public ChartData Chart;

@Parameter(defaultValue=”12″)
public int InpDepth;

@Parameter(defaultValue=”5″)
public int InpDeviation;

@Parameter(defaultValue=”3″)
public int InpBackstep;

@Output(name = “ExtZigzagBuffer”, color = Colors.Green)
public DataSeries ExtZigzagBuffer;

@Output
public DataSeries ExtHighBuffer;
@Output
public DataSeries ExtLowBuffer;

@Override
protected void OnInit() throws TradingException {
ExtZigzagBuffer.set(0,0);
ExtHighBuffer.set(0,0.00);
ExtLowBuffer.set(0,0.00);

}

//————————————————————————
//————————————————————————
//————————————————————————

/**
* This method is called on every bar update and here the indicator value is computed.
*
* Unlike in MT4 you don’t compute indicator values for multiple bars in a loop,
* you need to compute value only for the latest (current) bar.
* Trading engine will take care of calling this method for every bar in the chart.
*
* Actual bar for which the indicator value is computed is stored in CurrentBar variable.
* If 0, it means it is the very first bar of the chart.
*/
@Override
protected void OnBarUpdate() throws TradingException {

int i;
int    counterZ,whatlookfor=0;
int    back,pos,lasthighpos=0,lastlowpos=0;
double extremum=0;
double curlow=0.0,curhigh=0.0,lasthigh=0.0,lastlow=0.0;
double val;
double Point1=0.00001;
//Chart.getInstrumentInfo.pointValue;
int limit=0;

for(i=limit; i>=0; i–)

{

//— main loop

//— find lowest low in depth of bars

val= Chart.Low(InpDepth+i);

for(int j = InpDepth+i-1; j>=i;j–) {
val = Math.min(val, Chart.Low(j));
}

extremum= val;

//— this lowest has been found previously
if(extremum==lastlow)
extremum=0.0;
else
{
//— new last low
lastlow=extremum;
//— discard extremum if current low is too high
if(Chart.Low(i)-extremum>InpDeviation*Point1)
extremum=0.0;
else
{
//— clear previous extremums in backstep bars
for(back=1; back<=InpBackstep; back++)
{
pos=i+back;
if(ExtLowBuffer.get(pos)!=0 && ExtLowBuffer.get(pos)>extremum)
ExtLowBuffer.set(pos,0.0);
}
}
}
//— found extremum is current low
if(Chart.Low(i)==extremum)

ExtLowBuffer.set(i,extremum);
// ExtLowBuffer[i]=extremum;
else
ExtLowBuffer.set(i,0.00);

val= Chart.High(InpDepth+i);

for(int j = InpDepth+i-1; j>=i;j–){
val = Math.max(val, Chart.High(j));
}

//— find highest high in depth of bars
extremum=val;
//— this highest has been found previously
if(extremum==lasthigh)
extremum=0.0;
else
{
//— new last high
lasthigh=extremum;
//— discard extremum if current high is too low
if(extremum-Chart.High(i)>InpDeviation*Point1)
extremum=0.0;
else
{
//— clear previous extremums in backstep bars
for(back=1; back<=InpBackstep; back++)
{
pos=i+back;
if(ExtHighBuffer.get(pos)!=0 && ExtHighBuffer.get(pos)<extremum)
ExtHighBuffer.set(pos,0.00);
//ExtHighBuffe.set(pos,0.0);
}
}
}
//— found extremum is current high
if(Chart.High(i)==extremum)
ExtHighBuffer.set(i,extremum);
else
// ExtHighBufferr.set(i,0.00);
ExtHighBuffer.set(i,0.00);

}

//— final cutting
if(whatlookfor==0)
{
lastlow=0.0;
lasthigh=0.0;
}
else
{
lastlow=curlow;
lasthigh=curhigh;
}

for(i=limit; i>=0; i–)

{

switch(whatlookfor)
{
case 0: // look for peak or lawn
if(lastlow==0.0 && lasthigh==0.0)
{
if(ExtHighBuffer.get(i)!=0.0)
{
lasthigh=Chart.High(i);
lasthighpos=i;
whatlookfor=-1;
ExtZigzagBuffer.set(i,lasthigh);
}
if(ExtLowBuffer.get(i)!=0.0)
{
lastlow=Chart.Low(i);
lastlowpos=i;
whatlookfor=1;
ExtZigzagBuffer.set(i,lastlow);
}
}
break;
case 1: // look for peak
if(ExtLowBuffer.get(i)!=0.0 && ExtLowBuffer.get(i)<lastlow && ExtHighBuffer.get(i)==0.0)
{
ExtZigzagBuffer.set(lastlowpos,0.0);
lastlowpos=i;
lastlow=ExtLowBuffer.get(i);
ExtZigzagBuffer.set(i,lastlow);
}
if(ExtHighBuffer.get(i)!=0.0 && ExtLowBuffer.get(i)==0.0)
{
lasthigh=ExtHighBuffer.get(i);
lasthighpos=i;
ExtZigzagBuffer.set(i,lasthigh);
whatlookfor=-1;
}
break;
case -1: // look for lawn
if(ExtHighBuffer.get(i)!=0.0 && ExtHighBuffer.get(i)>lasthigh && ExtLowBuffer.get(i)==0.0)
{
ExtZigzagBuffer.set(lasthighpos,0.0);
lasthighpos=i;
lasthigh=ExtHighBuffer.get(i);
ExtZigzagBuffer.set(i,lasthigh);
}
if(ExtLowBuffer.get(i)!=0.0 && ExtHighBuffer.get(i)==0.0)
{
lastlow=ExtLowBuffer.get(i);
lastlowpos=i;
ExtZigzagBuffer.set(i,lastlow);
whatlookfor=1;
}
break;

}
}

}

}

0

Viewing 1 post (of 1 total)