Coding help - page 288

 

Hi,

Firstly an apology if this is in the wrong place, its a pivot indi i am looking at but my Q is in relation to coding, I could have put it in MTF as well but I thought this was best place to start.

In MT4 we have daily, weekly, monthly = W1, D1, MN1

but is there a year function, or a quarter function.

So for example in the attached pivot indicator how do you get 1 year, and is it (or can you choose) a rolling 12 months or a fixed prev year 2013 example. And same for how do I get it to calculate quarterly pivots.

Any guidance would be appreciated, attached is a monthly pivot indi. i am reasonably confident I can modify the attached but I do not know how to start to get the data into it to make it output quarters or year.

allpivots_monthly.mq4

Many thanks

Kevin

Files:
 
mladen:
You changed it to use "#pollan indy" I have no idea what that indicator does (if it is like the rest of "pollan" indicators then it repaints and that can cause your problems, but just doing the guessing game now)

Dear Sir MLADEN...

Could you replace this (#pollan indy) with any other indicator that you have... may be call #VQ bars.... PLEASE give it a try.... cause I do have a reading on the indicator buffer as attached picture... but I couldn't call via iCustom in my EA to further test this '#pollan indy"...

Hope to here from you again soon... THANKS

Yours truly

AZRUL

Files:
my_vq.jpg  48 kb
 
12BPRO:
Dear Sir MLADEN...

Could you replace this (#pollan indy) with any other indicator that you have... may be call #VQ bars.... PLEASE give it a try.... cause I do have a reading on the indicator buffer as attached picture... but I couldn't call via iCustom in my EA to further test this '#pollan indy"...

Hope to here from you again soon... THANKS

Yours truly

AZRUL

There is no need to replace #VQ with #VQ (it is already calculating volatility quality)

If it works as it should with the regular #VQ the only logical conclusion is that there is something wrong with "#pollan indy"

 

Coding help

Good morning to all

Hello mladen

I am trying to create my first codes.

Learn from other codes, since there is no manual MT4 in my language.

I pray not laugh at my code.

Please can help me it works.

It is a simple indicator that marks the creation of a Doji.

I beg your help.

Thank you very much in advance.

Best regards.

Hermo.

PD. Compiles fine but does not work.

Files:
 
Hermo:
Good morning to all

Hello mladen

I am trying to create my first codes.

Learn from other codes, since there is no manual MT4 in my language.

I pray not laugh at my code.

Please can help me it works.

It is a simple indicator that marks the creation of a Doji.

I beg your help.

Thank you very much in advance.

Best regards.

Hermo.

PD. Compiles fine but does not work.

Hermo

Will check it

Waiting ECB press conference now :):)

 
12BPRO:
Dear Sir MLADEN...

That is why in the first place I didn't post my #VQ.... may be you are right about there is something wrong about the "pollan indy" and YES it repaint....

For me, I just would like to try my theory, with this indicator just to see what's the outcome....

The thing is that I couldn't call the indicator buffer in my EA... may be it is caused by the modified version of my #VQ that is blocking the iCustom call to my EA....

With the original #VQ it works just fine... and I could run my EA.... but with the modified #VQ (mine), I couldn't excess but still there is a value as shown in the previous thread..

I think the problem is with my MODIFIED #VQ version.... may be so syntax error... PLEASE if you have time take a look and see if it is working as it should.....

THANKS... and sorry for any negative input.....

yours truly..

AZRUL

AZRUL

I simply can not know what is happening with your "pollan indy" without seeing the code

All I can do is guess, and guessing in coding is very, very bad

all the best

 
mladen:
There is no need to replace #VQ with #VQ (it is already calculating volatility quality) If it works as it should with the regular #VQ the only logical conclusion is that there is something wrong with "#pollan indy"

Dear Sir MLADEN...

That is why in the first place I didn't post my #VQ.... may be you are right about there is something wrong about the "pollan indy" and YES it repaint....

For me, I just would like to try my theory, with this indicator just to see what's the outcome....

The thing is that I couldn't call the indicator buffer in my EA... may be it is caused by the modified version of my #VQ that is blocking the iCustom call to my EA....

With the original #VQ it works just fine... and I could run my EA.... but with the modified #VQ (mine), I couldn't excess but still there is a value as shown in the previous thread..

I think the problem is with my MODIFIED #VQ version.... may be some syntax error... PLEASE if you have time take a look and see if it is working as it should..... just for the LEARNING PURPOSES....

THANKS... I HAVE GOT THAT EA RUNNING NOW AND TESTING IF YOU ARE INTERESTED IN FINDING OUT THE OUTCOME I WILL POST IT IN THE POLLAN THREAD.....

yours truly..

AZRUL

 
mladen:
AZRUL

I simply can not know what is happening with your "pollan indy" without seeing the code

All I can do is guess, and guessing in coding is very, very bad

all the best

I HAVE GOT THAT EA RUNNING NOW AND TESTING IF YOU ARE INTERESTED IN FINDING OUT THE OUTCOME I WILL POST IT IN THE POLLAN THREAD.....

IT WAS MY VERSION OF THE #VQ THAT DIDN'T WORK...

THANKS...

yours truly..

AZRUL

 

Hi CODESGURUS,

I have a general question about multi time frame.... as attached

the first picture on the left hand side is a RSI indicator on a 5M timeframe...

On the second is the RSI multi time frame of the 5M on the 15M timeframe...

The question is why is there a difference in the value as indicated in the RED circle....

Can someone PLEASE explain and rectify this RsiMA-MTF codes........

#property indicator_separate_window

#property indicator_buffers 6

#property indicator_color1 Lime

#property indicator_color2 Red

#property indicator_color3 Aqua

#property indicator_color4 Yellow

#property indicator_color5 White

#property indicator_color6 Magenta

#property indicator_width1 1

#property indicator_width2 1

#property indicator_width3 1

#property indicator_width4 1

#property indicator_width5 1

#property indicator_width6 1

//-------------------------------------

//-----

//extern string TimeFrames = "M15; M60";

extern bool TimeFrame1bool = true;

extern int TimeFrame1 = 0;

extern bool TimeFrame2bool = False;

extern int TimeFrame2 = 0;

extern bool TimeFrame3bool = False;

extern int TimeFrame3 = 0;

//int period[]={1,5,15,30,60,240,1440,43200};

//string periodString[]={"M1","M5","M15","M30","H1","H4","D1",MN1"};

// create one more array with indicator names

//string signalNameString[]={"MA"};

int ExtCountedBars=0;

//---------------------

int TF;

//---- buffers

double ExtMapBuffer1[];

double ExtMapBuffer2[];

double ExtMapBuffer3[];

double ExtMapBuffer4[];

double ExtMapBuffer5[];

double ExtMapBuffer6[];

//-------

//+------------------------------------------------------------------+

int init()

{

SetIndexBuffer(0, ExtMapBuffer1);

SetIndexBuffer(1, ExtMapBuffer2);

SetIndexBuffer(2, ExtMapBuffer3);

SetIndexBuffer(3, ExtMapBuffer4);

SetIndexBuffer(4, ExtMapBuffer5);

SetIndexBuffer(5, ExtMapBuffer6);

//-----

SetIndexStyle(0, DRAW_LINE);

SetIndexStyle(1, DRAW_LINE);

SetIndexStyle(2, DRAW_LINE);

SetIndexStyle(3, DRAW_LINE);

SetIndexStyle(4, DRAW_LINE);

SetIndexStyle(5, DRAW_LINE);

// SetIndexStyle(0,DRAW_LINE,EMPTY,1);

// SetIndexBuffer(0,ExtMapBuffer1);

//-------------------------------------------------------------+++

int M1 = PERIOD_M1;

int M5 = PERIOD_M5;

int M15 = PERIOD_M15;

int M30 = PERIOD_M30;

int H1 = PERIOD_H1;

int H4 = PERIOD_H4;

int D1 = PERIOD_D1;

int WK1 = PERIOD_W1;

int MN1 = PERIOD_M1;

TF=Period();

if (TF==PERIOD_M1) { TimeFrame1 = M1; TimeFrame2 = M1; TimeFrame3 = M1;}

else if (TF==PERIOD_M5) { TimeFrame1 = M1; TimeFrame2 = M5; TimeFrame3 = M15;}

else if (TF==PERIOD_M15) { TimeFrame1 = M5; TimeFrame2 = M15; TimeFrame3 = H1; }

else if (TF==PERIOD_M30) { TimeFrame1 = M5; TimeFrame2 = M15; TimeFrame3 = H1; }

else if (TF==PERIOD_H1) { TimeFrame1 = M15; TimeFrame2 = H1; TimeFrame3 = H4; }

else if (TF==PERIOD_H4) { TimeFrame1 = H4; TimeFrame2 = H4; TimeFrame3 = D1; }

else if (TF==PERIOD_D1) { TimeFrame1 = H4; TimeFrame2 = D1; TimeFrame3 = WK1;}

else if (TF==PERIOD_W1) { TimeFrame1 = D1; TimeFrame2 = WK1; TimeFrame3 = MN1;}

else if (TF==PERIOD_MN1) { TimeFrame1 = D1; TimeFrame2 = WK1; TimeFrame3 = MN1;}

else { TimeFrame1 = D1; TimeFrame2 = WK1; TimeFrame3 = MN1;}

//-----

return(0);

}

//+------------------------------------------------------------------+

int start()

{

datetime TimeArray1[];

datetime TimeArray2[];

datetime TimeArray3[];

int limit, i,y=0;

// int counted_bars = IndicatorCounted();

ExtCountedBars=IndicatorCounted();

if(ExtCountedBars < 0) return(-1);

if(ExtCountedBars > 0) ExtCountedBars--;

limit = Bars - ExtCountedBars;

//-----

ArrayCopySeries(TimeArray1,MODE_TIME,Symbol(),TimeFrame1);

ArrayCopySeries(TimeArray2,MODE_TIME,Symbol(),TimeFrame2);

ArrayCopySeries(TimeArray3,MODE_TIME,Symbol(),TimeFrame3);

for(i=0,y=0;i<limit;i++)

{

if(TimeFrame1bool)

{

if (Time<TimeArray1[y]) y++;

{

//ExtMapBuffer1

ExtMapBuffer1 = iCustom(NULL,TimeFrame1 , "#RSI-MA",0, y);

ExtMapBuffer2 = iCustom(NULL,TimeFrame1 , "#RSI-MA",3, y);

}

}

//-----

if(TimeFrame2bool)

{

if (Time<TimeArray2[y]) y++;

{

//ExtMapBuffer1

ExtMapBuffer3 = iCustom(NULL,TimeFrame2 , "#RSI-MA",0,y);

ExtMapBuffer4 = iCustom(NULL,TimeFrame2 , "#RSI-MA",3,y);

}

}

//-----

if(TimeFrame3bool)

{

if (Time<TimeArray3[y]) y++;

{

//ExtMapBuffer1

ExtMapBuffer5 = iCustom(NULL,TimeFrame3 , "#RSI-MA",0, y);

ExtMapBuffer6 = iCustom(NULL,TimeFrame3 , "#RSI-MA",3, y);

}

}

}

//-----//--------------------------------------------------------------------------+

//=======================================================

return(0);

}

//+--------------------------------------------------------------------------+

int deinit()

{

return(0);

}

//+------------------------------------------------------------------+

Files:
rsi-mtf_diff.jpg  290 kb
 

THIS IS A COPY OF THE RSI-MA........

#property indicator_separate_window

#property indicator_buffers 4

#property indicator_color1 LimeGreen

#property indicator_color2 Red

#property indicator_color3 Yellow

#property indicator_color4 White ///DarkGray

#property indicator_width1 3

#property indicator_width2 3

#property indicator_width3 3

#property indicator_width4 1

#property indicator_levelcolor Aqua

extern string TimeFrame = "Current time frame";

extern int RsiOma_Period = 13;

extern int RsiOma_Price = 0;

extern int RsiOma_Mode = MODE_LWMA;

extern int MaPeriod = 8;

extern int MaType = MODE_LWMA;

extern double levelOb = 88;

extern double levelOs = 13;

extern int OB_RSI = 80;

extern int OS_RSI = 15;

extern string note = "turn on Alert = true; turn off = false";

extern bool alertsOn = true; ///false;

extern bool alertsOnCurrent = true;

extern bool alertsMessage = true;

extern bool alertsSound = true; ///false;

extern bool alertsEmail = false;

extern string soundfile = "connect.wav"; ///"alert2.wav";

extern string SoundUp = "ok.wav";

extern string SoundDown = "stops.wav";

double rsi[];

double rsida[];

double rsidb[];

double ma[];

double mab[];

double trend[];

double slope[];

string indicatorFileName;

int Char, timeFrame;

bool returnBars;

bool calculateValue;

//+------------------------------------------------------------------+

int init()

{

IndicatorBuffers(7);

SetIndexBuffer(0,rsi);

SetIndexBuffer(1,rsida);

SetIndexBuffer(2,rsidb);

SetIndexBuffer(3,ma);

SetIndexBuffer(4,mab);

SetIndexBuffer(5,trend);

SetIndexBuffer(6,slope);

SetLevelValue(0,levelOs);

SetLevelValue(1,levelOb);

indicatorFileName = WindowExpertName();

calculateValue = (TimeFrame=="calculateValue"); if (calculateValue) return(0);

returnBars = (TimeFrame=="returnBars"); if (returnBars) return(0);

timeFrame = stringToTimeFrame(TimeFrame);

IndicatorShortName(timeFrameToString(timeFrame)+" Rsi-Ma MaxMin ("+RsiOma_Period+","+MaPeriod+")");

SetIndexLabel(0,"RSI");

SetIndexLabel(1,"RSIDA");

SetIndexLabel(2,"RSIDB");

SetIndexLabel(3,"MA");

return(0);

}

int deinit() { return(0); }

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

int i,limit;

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

limit = MathMin(Bars-counted_bars,Bars-1);

if (returnBars) { rsi[0] = limit+1; return(0); }

if (calculateValue || timeFrame==Period())

{

if (slope[limit] == -1) ClearPoint(limit,rsida,rsidb);

for (i=limit; i >= 0; i--) mab = iMA(NULL,0,RsiOma_Period,0,RsiOma_Mode,RsiOma_Price,i);

for (i=limit; i >= 0; i--) rsi = iRSIOnArray(mab,0,RsiOma_Period,i);

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

{

ma = iMAOnArray(rsi,0,MaPeriod,0,MaType,i);

rsida = EMPTY_VALUE;

rsidb = EMPTY_VALUE;

slope = slope;

trend = trend;

if ((rsi > rsi) && (rsi > OB_RSI))

slope= 1;

if ((rsi < rsi) && (rsi < OS_RSI))

slope=-1;

if ((rsi > ma) && (rsi > OB_RSI))

trend= 1;

if ((rsi < ma) && (rsi < OS_RSI))

trend=-1;

if (slope == -1)

PlotPoint(i,rsida,rsidb,rsi);

}

manageAlerts();

return(0);

}

limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));

if (slope[limit]==-1) ClearPoint(limit,rsida,rsidb);

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

{

int y = iBarShift(NULL,timeFrame,Time);

rsi = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",RsiOma_Period,RsiOma_Price,RsiOma_Mode,MaPeriod,MaType,0,y);

rsida = EMPTY_VALUE;

rsidb = EMPTY_VALUE;

ma = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",RsiOma_Period,RsiOma_Price,RsiOma_Mode,MaPeriod,MaType,3,y);

trend = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",RsiOma_Period,RsiOma_Price,RsiOma_Mode,MaPeriod,MaType,5,y);

slope = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",RsiOma_Period,RsiOma_Price,RsiOma_Mode,MaPeriod,MaType,6,y);

}

for (i=limit;i>=0;i--) if (slope==-1) PlotPoint(i,rsida,rsidb,rsi);

manageAlerts();

return(0);

}

//+------------------------------------------------------------------

string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};

int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};

int stringToTimeFrame(string tfs)

{

tfs = stringUpperCase(tfs);

for (int i=ArraySize(iTfTable)-1; i>=0; i--)

if (tfs==sTfTable || tfs==""+iTfTable) return(MathMax(iTfTable,Period()));

return(Period());

}

string timeFrameToString(int tf)

{

for (int i=ArraySize(iTfTable)-1; i>=0; i--)

if (tf==iTfTable) return(sTfTable);

return("");

}

string stringUpperCase(string str)

{

string s = str;

for (int length=StringLen(str)-1; length>=0; length--)

{

Char = StringGetChar(s, length);

if((Char > 96 && Char 223 && Char < 256))

s = StringSetChar(s, length, Char - 32);

else if(Char > -33 && Char < 0)

s = StringSetChar(s, length, Char + 224);

}

return(s);

}

//+------------------------------------------------------------------+

void ClearPoint(int i,double& first[],double& second[])

{

if ((second != EMPTY_VALUE) && (second != EMPTY_VALUE))

second = EMPTY_VALUE;

else

if ((first != EMPTY_VALUE) && (first != EMPTY_VALUE) && (first == EMPTY_VALUE))

first = EMPTY_VALUE;

}

void PlotPoint(int i,double& first[],double& second[],double& from[])

{

if (first == EMPTY_VALUE)

{

if (first == EMPTY_VALUE)

{

first = from;

first = from;

second = EMPTY_VALUE;

}

else

{

second = from;

second = from;

first = EMPTY_VALUE;

}

}

else

{

first = from;

second = EMPTY_VALUE;

}

}

void manageAlerts()

{

if (!calculateValue && alertsOn)

{

if (alertsOnCurrent)

int whichBar = 0;

else whichBar = 1; whichBar = iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar));

if (trend[whichBar] != trend[whichBar+1])

{

if (trend[whichBar] == 1)

//doAlert(whichBar,"trend");

doAlerts( whichBar,"UP RSI-MA "+Symbol()+" (tf:"+Period()+")",SoundUp);

if (trend[whichBar] ==-1)

//doAlert(whichBar,"no trend");

doAlerts( whichBar,"DOWN RSI-MA "+Symbol()+" (tf:"+Period()+")",SoundDown);

}

}

}

void doAlerts(int forBar, string doWhat, string SoundFile) {

static string previousAlert="nothing";

static datetime previousTime;

string message;

if (previousAlert != doWhat || previousTime != Time[forBar]) {

previousAlert = doWhat;

previousTime = Time[forBar];

message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," - ",timeFrameToString(timeFrame)+" rsioma ",doWhat);

if (alertsMessage) Alert(message);

if (alertsSound) PlaySound(SoundFile);

if (alertsEmail) SendMail(StringConcatenate(Symbol()," rsioma "),message);

}

}

//---------------------------------------------------------------------------------------------------

void doAlert(int forBar, string doWhat)

{

static string previousAlert="nothing";

static datetime previousTime;

string message;

if (previousAlert != doWhat || previousTime != Time[forBar]) {

previousAlert = doWhat;

previousTime = Time[forBar];

message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," - ",timeFrameToString(timeFrame)+" rsioma ",doWhat);

if (alertsMessage) Alert(message);

if (alertsEmail) SendMail(StringConcatenate(Symbol()," rsioma "),message);

if (alertsSound) PlaySound(soundfile);

}

}

THANKS ALL.....

best regards

AZRUL..........

PS... how do I attaced these FILES code in here..... Sorry for the mess....

Reason: