Coding help - page 25

 

Please help....

PLEASE HELP....

Moving avarage red line, slope direction is under Line

Moving avarage blue line, under the Red Line is moving avarege

Price "slope direction Line" cut time

All takes place at the same time: GIVE AN ALARM INDma_crossover_lines.ex4ma_crossover_lines.mq4

slope_direction_line.ex4CATOR

Please Help

--

UmUt EtİkEr

 

Daily, Weekly, Monthly Gains Function Required

I'm having trouble with some coding. I'm trying to create an indicator that displays the daily closed gains, weekly closed and monthly closed gains.

Does anyone have a function that will calculate the gains from these periods?

ie.

Today Closed : 5.3%

Week Closed : 13.7%

Month Closed: 41.3%

Year Closed: 79.5%

I kinda know what needs to be done but having trouble with getting it right. If someone has the functions that will do this can you please help me out?

 
Try using this as a basis :
//+------------------------------------------------------------------+

//| |

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

//

//

//

// show statistics

//

//

//

double stat[18];

#define stat.OTodayBuy 0

#define stat.OTodaySell 1

#define stat.OTodayTotal 2

#define stat.OTodayBuyPips 3

#define stat.OTodaySellPips 4

#define stat.OTodayTotalPips 5

#define stat.TodayBuy 6

#define stat.TodaySell 7

#define stat.TodayTotal 8

#define stat.TodayBuyPips 9

#define stat.TodaySellPips 10

#define stat.TodayTotalPips 11

#define stat.TotalBuy 12

#define stat.TotalSell 13

#define stat.TotalTotal 14

#define stat.TotalBuyPips 15

#define stat.TotalSellPips 16

#define stat.TotalTotalPips 17

//

//

//

//

//

void stat.colect()

{

int pointRatio = MathPow(10,Digits%2);

int pipMultiplier = MathPow(10,Digits);

double temp;

//

//

//

//

//

ArrayInitialize(stat,0);

for(int i = 0; i < OrdersTotal(); i++)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;

if(OrderMagicNumber() != MagicNumber) continue;

if(OrderSymbol() != Symbol()) continue;

if(OrderType()==OP_BUY || OrderType()==OP_SELL)

{

double tempa = OrderProfit()+OrderSwap();

double tempp = 0;

if (OrderType()==OP_BUY)

{

tempp = (Bid-OrderOpenPrice())*pipMultiplier/pointRatio;

stat[stat.OTodayBuy] += tempa;

stat[stat.OTodayBuyPips] += tempp;

}

else

{

tempp = (OrderOpenPrice()-Ask)*pipMultiplier/pointRatio;

stat[stat.OTodaySell] += tempa;

stat[stat.OTodaySellPips] += tempp;

}

}

stat[stat.OTodayTotal] += tempa;

stat[stat.OTodayTotalPips] += tempp;

}

//

//

//

// now check the history

//

//

//

datetime startTime = StrToTime(StringSubstr(TimeToStr(TimeCurrent()),0,10)+" 00:00");

datetime endTime = StrToTime(StringSubstr(TimeToStr(TimeCurrent()),0,10)+" 24:00");

//

//

//

//

//

for(i = 0; i < OrdersHistoryTotal(); i++)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) break;

if(OrderMagicNumber() != MagicNumber) continue;

if(OrderSymbol() != Symbol()) continue;

//

//

//

//

//

bool isOutOfToday = (OrderCloseTime()endTime);

if(OrderType()==OP_BUY || OrderType()==OP_SELL)

{

tempa = OrderProfit()+OrderSwap();

tempp = 0;

if (OrderType()==OP_BUY)

{

tempp = (OrderClosePrice()-OrderOpenPrice())*pipMultiplier/pointRatio;

stat[stat.TotalBuy] += tempa;

stat[stat.TotalBuyPips] += tempp;

if (!isOutOfToday)

{

stat[stat.TodayBuy] += tempa;

stat[stat.TodayBuyPips] += tempp;

}

}

else

{

tempp = (OrderOpenPrice()-OrderClosePrice())*pipMultiplier/pointRatio;

stat[stat.TotalSell] += tempa;

stat[stat.TotalSellPips] += tempp;

if (!isOutOfToday)

{

stat[stat.TodaySell] += tempa;

stat[stat.TodaySellPips] += tempp;

}

}

//

//

//

//

//

if (!isOutOfToday)

{

stat[stat.TodayTotal] += tempa;

stat[stat.TodayTotalPips] += tempp;

}

stat[stat.TotalTotal] += tempa;

stat[stat.TotalTotalPips] += tempp;

}

}

}

void showStatistics()

{

if (!showStatistics) return;

//

//

//

//

//

stat.colect();

createLabel( 1,"opened buy profit" ,stat[stat.OTodayBuy] , 10);

createLabel( 2,"opened buy profit (pips)" ,stat[stat.OTodayBuyPips] , 20,0);

createLabel( 3,"opened sell profit" ,stat[stat.OTodaySell] , 30);

createLabel( 4,"opened sell profit (pips)",stat[stat.OTodaySellPips] , 40,0);

createLabel( 5,"opened profit" ,stat[stat.OTodayTotal] , 50);

createLabel( 6,"opened profit (pips)" ,stat[stat.OTodayTotalPips], 60,0);

createLabel( 7,"daily buy profit" ,stat[stat.TodayBuy] , 80);

createLabel( 8,"daily buy profit (pips)" ,stat[stat.TodayBuyPips] , 90,0);

createLabel( 9,"daily sell profit" ,stat[stat.TodaySell] ,100);

createLabel(10,"daily sell profit (pips)" ,stat[stat.TodaySellPips] ,110,0);

createLabel(11,"daily profit" ,stat[stat.TodayTotal] ,120);

createLabel(12,"daily profit (pips)" ,stat[stat.TodayTotalPips] ,130,0);

createLabel(13,"total buy profit" ,stat[stat.TotalBuy] ,150);

createLabel(14,"total buy profit (pips)" ,stat[stat.TotalBuyPips] ,160,0);

createLabel(15,"total sell profit" ,stat[stat.TotalSell] ,170);

createLabel(16,"total sell profit (pips)" ,stat[stat.TotalSellPips] ,180,0);

createLabel(17,"total profit" ,stat[stat.TotalTotal] ,190);

createLabel(18,"total profit (pips)" ,stat[stat.TotalTotalPips] ,200,0);

WindowRedraw();

}

//

//

//

//

//

void createLabel(string lname, string text, double value,int ypos,int decimals=2)

{

string name = "stat."+lname;

if (ObjectFind(name) == -1)

{

ObjectCreate(name,OBJ_LABEL,0,0,0);

ObjectSet(name,OBJPROP_CORNER ,0);

ObjectSet(name,OBJPROP_XDISTANCE,5);

ObjectSet(name,OBJPROP_YDISTANCE,ypos+5);

}

ObjectSetText(name,text,9,"Arial",Gray);

//

//

//

//

//

name = name+"value";

if (ObjectFind(name) == -1)

{

ObjectCreate(name,OBJ_LABEL,0,0,0);

ObjectSet(name,OBJPROP_CORNER ,0);

ObjectSet(name,OBJPROP_XDISTANCE,145);

ObjectSet(name,OBJPROP_YDISTANCE,ypos+5);

}

color theColor = DimGray;

if (value < 0) theColor = Orange;

if (value > 0) theColor = Lime;

ObjectSetText(name,DoubleToStr(value,decimals),9,"Arial",theColor);

}

you have an opened, daily and total stats covered in this one. Adding weekly and monthly shouln't be to difficult (just follow the logic of the daily data collection)

sbwent:
I'm having trouble with some coding. I'm trying to create an indicator that displays the daily closed gains, weekly closed and monthly closed gains.

Does anyone have a function that will calculate the gains from these periods?

ie.

Today Closed : 5.3%

Week Closed : 13.7%

Month Closed: 41.3%

Year Closed: 79.5%

I kinda know what needs to be done but having trouble with getting it right. If someone has the functions that will do this can you please help me out?
 

Thanx, I will give it a try

mladen:
Try using this as a basis :
//+------------------------------------------------------------------+

//| |

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

//

//

//

// show statistics

//

//

//

double stat[18];

#define stat.OTodayBuy 0

#define stat.OTodaySell 1

#define stat.OTodayTotal 2

#define stat.OTodayBuyPips 3

#define stat.OTodaySellPips 4

#define stat.OTodayTotalPips 5

#define stat.TodayBuy 6

#define stat.TodaySell 7

#define stat.TodayTotal 8

#define stat.TodayBuyPips 9

#define stat.TodaySellPips 10

#define stat.TodayTotalPips 11

#define stat.TotalBuy 12

#define stat.TotalSell 13

#define stat.TotalTotal 14

#define stat.TotalBuyPips 15

#define stat.TotalSellPips 16

#define stat.TotalTotalPips 17

//

//

//

//

//

void stat.colect()

{

int pointRatio = MathPow(10,Digits%2);

int pipMultiplier = MathPow(10,Digits);

double temp;

//

//

//

//

//

ArrayInitialize(stat,0);

for(int i = 0; i < OrdersTotal(); i++)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) break;

if(OrderMagicNumber() != MagicNumber) continue;

if(OrderSymbol() != Symbol()) continue;

if(OrderType()==OP_BUY || OrderType()==OP_SELL)

{

double tempa = OrderProfit()+OrderSwap();

double tempp = 0;

if (OrderType()==OP_BUY)

{

tempp = (Bid-OrderOpenPrice())*pipMultiplier/pointRatio;

stat[stat.OTodayBuy] += tempa;

stat[stat.OTodayBuyPips] += tempp;

}

else

{

tempp = (OrderOpenPrice()-Ask)*pipMultiplier/pointRatio;

stat[stat.OTodaySell] += tempa;

stat[stat.OTodaySellPips] += tempp;

}

}

stat[stat.OTodayTotal] += tempa;

stat[stat.OTodayTotalPips] += tempp;

}

//

//

//

// now check the history

//

//

//

datetime startTime = StrToTime(StringSubstr(TimeToStr(TimeCurrent()),0,10)+" 00:00");

datetime endTime = StrToTime(StringSubstr(TimeToStr(TimeCurrent()),0,10)+" 24:00");

//

//

//

//

//

for(i = 0; i < OrdersHistoryTotal(); i++)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) == false) break;

if(OrderMagicNumber() != MagicNumber) continue;

if(OrderSymbol() != Symbol()) continue;

//

//

//

//

//

bool isOutOfToday = (OrderCloseTime()endTime);

if(OrderType()==OP_BUY || OrderType()==OP_SELL)

{

tempa = OrderProfit()+OrderSwap();

tempp = 0;

if (OrderType()==OP_BUY)

{

tempp = (OrderClosePrice()-OrderOpenPrice())*pipMultiplier/pointRatio;

stat[stat.TotalBuy] += tempa;

stat[stat.TotalBuyPips] += tempp;

if (!isOutOfToday)

{

stat[stat.TodayBuy] += tempa;

stat[stat.TodayBuyPips] += tempp;

}

}

else

{

tempp = (OrderOpenPrice()-OrderClosePrice())*pipMultiplier/pointRatio;

stat[stat.TotalSell] += tempa;

stat[stat.TotalSellPips] += tempp;

if (!isOutOfToday)

{

stat[stat.TodaySell] += tempa;

stat[stat.TodaySellPips] += tempp;

}

}

//

//

//

//

//

if (!isOutOfToday)

{

stat[stat.TodayTotal] += tempa;

stat[stat.TodayTotalPips] += tempp;

}

stat[stat.TotalTotal] += tempa;

stat[stat.TotalTotalPips] += tempp;

}

}

}

void showStatistics()

{

if (!showStatistics) return;

//

//

//

//

//

stat.colect();

createLabel( 1,"opened buy profit" ,stat[stat.OTodayBuy] , 10);

createLabel( 2,"opened buy profit (pips)" ,stat[stat.OTodayBuyPips] , 20,0);

createLabel( 3,"opened sell profit" ,stat[stat.OTodaySell] , 30);

createLabel( 4,"opened sell profit (pips)",stat[stat.OTodaySellPips] , 40,0);

createLabel( 5,"opened profit" ,stat[stat.OTodayTotal] , 50);

createLabel( 6,"opened profit (pips)" ,stat[stat.OTodayTotalPips], 60,0);

createLabel( 7,"daily buy profit" ,stat[stat.TodayBuy] , 80);

createLabel( 8,"daily buy profit (pips)" ,stat[stat.TodayBuyPips] , 90,0);

createLabel( 9,"daily sell profit" ,stat[stat.TodaySell] ,100);

createLabel(10,"daily sell profit (pips)" ,stat[stat.TodaySellPips] ,110,0);

createLabel(11,"daily profit" ,stat[stat.TodayTotal] ,120);

createLabel(12,"daily profit (pips)" ,stat[stat.TodayTotalPips] ,130,0);

createLabel(13,"total buy profit" ,stat[stat.TotalBuy] ,150);

createLabel(14,"total buy profit (pips)" ,stat[stat.TotalBuyPips] ,160,0);

createLabel(15,"total sell profit" ,stat[stat.TotalSell] ,170);

createLabel(16,"total sell profit (pips)" ,stat[stat.TotalSellPips] ,180,0);

createLabel(17,"total profit" ,stat[stat.TotalTotal] ,190);

createLabel(18,"total profit (pips)" ,stat[stat.TotalTotalPips] ,200,0);

WindowRedraw();

}

//

//

//

//

//

void createLabel(string lname, string text, double value,int ypos,int decimals=2)

{

string name = "stat."+lname;

if (ObjectFind(name) == -1)

{

ObjectCreate(name,OBJ_LABEL,0,0,0);

ObjectSet(name,OBJPROP_CORNER ,0);

ObjectSet(name,OBJPROP_XDISTANCE,5);

ObjectSet(name,OBJPROP_YDISTANCE,ypos+5);

}

ObjectSetText(name,text,9,"Arial",Gray);

//

//

//

//

//

name = name+"value";

if (ObjectFind(name) == -1)

{

ObjectCreate(name,OBJ_LABEL,0,0,0);

ObjectSet(name,OBJPROP_CORNER ,0);

ObjectSet(name,OBJPROP_XDISTANCE,145);

ObjectSet(name,OBJPROP_YDISTANCE,ypos+5);

}

color theColor = DimGray;

if (value < 0) theColor = Orange;

if (value > 0) theColor = Lime;

ObjectSetText(name,DoubleToStr(value,decimals),9,"Arial",theColor);

}

you have an opened, daily and total stats covered in this one. Adding weekly and monthly shouln't be to difficult (just follow the logic of the daily data collection)

Thanks, you've been a big help. I'll see if I can work it out from this.

 

Mtf cci hook

Guys, can someone take a look and help me out with attached CCI hook indicator, I added MTF function in it but I would like to see dots horizontally aligned and I can't manage it .. or just one dot from closed bar of higher TF.

Thank you in advance.

ccihookmtf.mq4

Files:
 

...

Try something like this. This one shows all the dots of the target time frame horizontally aligned

altoronto:
Guys, can someone take a look and help me out with attached CCI hook indicator, I added MTF function in it but I would like to see dots horizontally aligned and I can't manage it .. or just one dot from closed bar of higher TF.

Thank you in advance.

ccihookmtf.mq4
Files:
 
mladen:
Try something like this. This one shows all the dots of the target time frame horizontally aligned

Thank you Mladen, you really know how to torture data

 

...

If you want to limit it to just one dot per target time frame bar (first bar belonging to the target time frame bar in this case), then you could do something like what have been done in this version (on the example it is one hour cci hook on 15 minute chart - option added to indicator so yu can choose)

altoronto:
Thank you Mladen, you really know how to torture data
Files:
cci_hk.gif  28 kb
 

hi guys

how can i get the time of the upcoming bar

i tried

datetime Time[-1];

which didnt work

greets

 

Future bar time ....

Try like this :
datetime futureBarTime = Time[0]+Period()*60;
Deorn:
hi guys

how can i get the time of the upcoming bar

i tried

datetime Time[-1];

which didnt work

greets
Reason: