Coding help - page 139

Aki Miu
2407
Aki Miu  

Is there a way to post a code properly? Spacebar doesn't work I don't know why.

Mladen Rakic
186590
Mladen Rakic  
RyuShin:
Is there a way to post a code properly? Spacebar doesn't work I don't know why.

You can do as shown on the picture (simply paste the code in the php box)

or you can attach the code using the regular attachment

Files:
Aki Miu
2407
Aki Miu  
mladen:
You can do as shown on the picture (simply paste the code in the php box)or you can attach the code using the regular attachment

The problem is I don't see the box. I have no idea why. I used Firefox and internet explorer but they didn't show the box :/ Anyways I'll use another computer and try again.

Aki Miu
2407
Aki Miu  

Okay here's the code for the indicators.

Weekly

#property indicator_chart_window

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

ObjectDelete("WS1");

ObjectDelete("WS2");

ObjectDelete("WS3");

ObjectDelete("WR1");

ObjectDelete("WR2");

ObjectDelete("WR3");

ObjectDelete("WEEKLY PIVOT");

ObjectDelete("Weekly Support 1");

ObjectDelete("Weekly 2");

ObjectDelete("Weekly 3");

ObjectDelete("Weekly Pivot level");

ObjectDelete("Weekly Resistance 1");

ObjectDelete("Weekly Resistance 2");

ObjectDelete("Weekly Resistance 3");

Comment(" ");

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

//----

double rates[1][6],weekly_close,weekly_high,weekly_low;

ArrayCopyRates(rates, Symbol(), PERIOD_W1);

if(DayOfWeek() == 1)

{

if(TimeDayOfWeek(iTime(Symbol(),PERIOD_W1,1)) == 5)

{

weekly_close = rates[1][4];

weekly_high = rates[1][3];

weekly_low = rates[1][2];

}

else

{

for(int d = 5;d>=0;d--)

{

if(TimeDayOfWeek(iTime(Symbol(),PERIOD_W1,d)) == 5)

{

weekly_close = rates[d][4];

weekly_high = rates[d][3];

weekly_low = rates[d][2];

}

}

}

}

else

{

weekly_close = rates[1][4];

weekly_high = rates[1][3];

weekly_low = rates[1][2];

}

//---- Calculate Pivots

Comment("\nWeekly quotations:\nH ",weekly_high,"\nL ",weekly_low, "\nC ",weekly_close);

double R = weekly_high - weekly_low;//range

double wp = (weekly_high + weekly_low + weekly_close)/3;// Standard Pivot

double wr3 = wp + (R * 1.000);

double wr2 = wp + (R * 0.618);

double wr1 = wp + (R * 0.382);

double ws1 = wp - (R * 0.382);

double ws2 = wp - (R * 0.618);

double ws3 = wp - (R * 1.000);

drawLine(wr3,"WR3", LimeGreen,0);

drawLabel(" WR 3",wr3,LimeGreen);

drawLine(wr2,"WR2", LimeGreen,0);

drawLabel(" WR 2",wr2,LimeGreen);

drawLine(wr1,"WR1", LimeGreen,0);

drawLabel(" WR 1",wr1,LimeGreen);

drawLine(wp,"WEEKLY PIVOT",Black,1);

drawLabel(" WP",wp,Black);

drawLine(ws1,"WS1",Crimson,0);

drawLabel(" WS 1",ws1,Crimson);

drawLine(ws2,"WS2",Crimson,0);

drawLabel(" WS 2",ws2,Crimson);

drawLine(ws3,"WS3",Crimson,0);

drawLabel(" WS 3",ws3,Crimson);

//----

return(0);

}

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

void drawLabel(string name,double lvl,color Color)

{

if(ObjectFind(name) != 0)

{

ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);

ObjectSetText(name, name, 8, "Arial", EMPTY);

ObjectSet(name, OBJPROP_COLOR, Color);

}

else

{

ObjectMove(name, 0, Time[10], lvl);

}

}

void drawLine(double lvl,string name, color Col,int type)

{

if(ObjectFind(name) != 0)

{

ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);

if(type == 1)

ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);

else

ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);

ObjectSet(name, OBJPROP_COLOR, Col);

ObjectSet(name,OBJPROP_WIDTH,1);

}

else

{

ObjectDelete(name);

ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);

if(type == 1)

ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);

else

ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);

ObjectSet(name, OBJPROP_COLOR, Col);

ObjectSet(name,OBJPROP_WIDTH,1);

}

}[/PHP]

Monthly

[PHP]//+------------------------------------------------------------------+

#property indicator_chart_window

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

ObjectDelete("MS1");

ObjectDelete("MS2");

ObjectDelete("MS3");

ObjectDelete("MR1");

ObjectDelete("MR2");

ObjectDelete("MR3");

ObjectDelete("MONTHLY PIVOT");

ObjectDelete("Monthly Support 1");

ObjectDelete("Monthly 2");

ObjectDelete("Monthly 3");

ObjectDelete("Monthly Pivot level");

ObjectDelete("Monthly Resistance 1");

ObjectDelete("Monthly Resistance 2");

ObjectDelete("Monthly Resistance 3");

Comment(" ");

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

//----

double rates[1][6],monthly_close,monthly_high,monthly_low;

ArrayCopyRates(rates, Symbol(), PERIOD_MN1);

if(DayOfWeek() == 1)

{

if(TimeDayOfWeek(iTime(Symbol(),PERIOD_MN1,1)) == 5)

{

monthly_close = rates[1][4];

monthly_high = rates[1][3];

monthly_low = rates[1][2];

}

else

{

for(int d = 5;d>=0;d--)

{

if(TimeDayOfWeek(iTime(Symbol(),PERIOD_MN1,d)) == 5)

{

monthly_close = rates[d][4];

monthly_high = rates[d][3];

monthly_low = rates[d][2];

}

}

}

}

else

{

monthly_close = rates[1][4];

monthly_high = rates[1][3];

monthly_low = rates[1][2];

}

//---- Calculate Pivots

Comment("\nMonthly quotations:\nH ",monthly_high,"\nL ",monthly_low, "\nC ",monthly_close);

double R = monthly_high - monthly_low;//range

double mp = (monthly_high + monthly_low + monthly_close)/3;// Standard Pivot

double mr3 = mp + (R * 1.000);

double mr2 = mp + (R * 0.618);

double mr1 = mp + (R * 0.382);

double ms1 = mp - (R * 0.382);

double ms2 = mp - (R * 0.618);

double ms3 = mp - (R * 1.000);

drawLine(mr3,"MR3", Lime,0);

drawLabel(" MR 3",mr3,Lime);

drawLine(mr2,"MR2", Lime,0);

drawLabel(" MR 2",mr2,Lime);

drawLine(mr1,"MR1", Lime,0);

drawLabel(" MR 1",mr1,Lime);

drawLine(mp,"MONTHLY PIVOT",Black,1);

drawLabel(" MP",mp,Black);

drawLine(ms1,"MS1",Red,0);

drawLabel(" MS 1",ms1,Red);

drawLine(ms2,"MS2",Red,0);

drawLabel(" MS 2",ms2,Red);

drawLine(ms3,"MS3",Red,0);

drawLabel(" MS 3",ms3,Red);

//----

return(0);

}

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

void drawLabel(string name,double lvl,color Color)

{

if(ObjectFind(name) != 0)

{

ObjectCreate(name, OBJ_TEXT, 0, Time[10], lvl);

ObjectSetText(name, name, 8, "Arial", EMPTY);

ObjectSet(name, OBJPROP_COLOR, Color);

}

else

{

ObjectMove(name, 0, Time[10], lvl);

}

}

void drawLine(double lvl,string name, color Col,int type)

{

if(ObjectFind(name) != 0)

{

ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);

if(type == 1)

ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);

else

ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);

ObjectSet(name, OBJPROP_COLOR, Col);

ObjectSet(name,OBJPROP_WIDTH,1);

}

else

{

ObjectDelete(name);

ObjectCreate(name, OBJ_HLINE, 0, Time[0], lvl,Time[0],lvl);

if(type == 1)

ObjectSet(name, OBJPROP_STYLE, STYLE_SOLID);

else

ObjectSet(name, OBJPROP_STYLE, STYLE_DOT);

ObjectSet(name, OBJPROP_COLOR, Col);

ObjectSet(name,OBJPROP_WIDTH,1);

}

}
Mladen Rakic
186590
Mladen Rakic  
RyuShin:
The problem is I don't see the box. I have no idea why. I used Firefox and internet explorer but they didn't show the box :/ Anyways I'll use another computer and try again.

RyuShin

You will not see a box, you will see something like this :

and it will result in this :

paste your code here
Files:
code_2.gif 35 kb
yuhu
89
yuhu  

Hi Guys,

Can you take a look at my code, please? it is very simple, but i have no idea why it is not working the way I want it to be. Basically i want to check if two consecutive value of an indicator. If they are same, draw and arrow on the candle close.

now=iCustom(NULL,0,"Stoch",period,5,i+1);

previous=iCustom(NULL,0,"Stoch",period,5,i+2);

if ( (now==previous))

{

CrossUp=previous;

}

[/CODE]

The code above is not showing any arrows when it should (I checked in data window)

The parameters, indicators name is all working fine because with the following code, it is showing arrows

[CODE]

now=iCustom(NULL,0,"Stoch",period,5,i+1);

previous=iCustom(NULL,0,"Stoch",period,5,i+1);

if ( (now==previous))

{

CrossUp=previous;

}

Can anyone help why the first set of code is not the same?

The value in data window is the same!..

Thank you in advance!

Mladen Rakic
186590
Mladen Rakic  
yuhu:
Hi Guys,

Can you take a look at my code, please? it is very simple, but i have no idea why it is not working the way I want it to be. Basically i want to check if two consecutive value of an indicator. If they are same, draw and arrow on the candle close.

now=iCustom(NULL,0,"Stoch",period,5,i+1);

previous=iCustom(NULL,0,"Stoch",period,5,i+2);

if ( (now==previous))

{

CrossUp=previous;

}

[/CODE]

The code above is not showing any arrows when it should (I checked in data window)

The parameters, indicators name is all working fine because with the following code, it is showing arrows

[CODE]

now=iCustom(NULL,0,"Stoch",period,5,i+1);

previous=iCustom(NULL,0,"Stoch",period,5,i+1);

if ( (now==previous))

{

CrossUp=previous;

}

Can anyone help why the first set of code is not the same?

The value in data window is the same!..

Thank you in advance!

yuhu

Data for indicators in the data window is displayed only to 4 digits precision if not defined differently with IndicatorDigits() function. What is not displayed is what is causing that you do not get an equal condition. Use NormalizeDouble() and then it should happen more often

Use something like this :

if ( (NormalizeDouble(now,4)==NormalizeDouble(previous,4)))

Or use some other number instead of 4 that you want the values to be rounded to

metrus
49
metrus  

CSM objective measure

Hi

Could someone help me with coding the following:

Provide an alert when

1 - one currency (example EUR in chart below) has consistently high values across several timeframes, and

2 - a second currency (example JPY in chart) has consistently low values across the same timeframes.

For instance, alert would show if, specifying M15, M30, H1 and H4 (user selected timeframes),

1 - the EUR has all four readings of HiScore (a variable, default 70) or above, and

2 - the JPY has all four readings of LowScore (a variable, default 35) or less.

(The "hanover --- extensible functions.mgh" and "hanover --- function header.mgh" have to be placed in the experts/include folder to see the chart properly. I think it also needs the "PLCC___" font installed in windows, but I wasn't successful in uploading that font here.)

Thank you!

yuhu
89
yuhu  

Thank so much Mladen. you are a hero

Take care!!

Aki Miu
2407
Aki Miu  

mladen, after my metatrader passed 0 o'clock, the weekly and monthly pivot indicators started working again. I don't know why they don't work on Monday :/ Thank you for your attention anyways.