EA Time function

 

Can anyone help with this.....

I am trying to calculate the the % growth for the day. The problem is I cannot seem to set the begining balance variable.

Here is what I tried

double DailystartBal;

int CurrentTime = TimeCurrent();

if (CurrentTime == StartHour) { //Start hour = 17

DailystartBal = AccountEquity();

}

double DailyGrowth = ((AccountEquity() - DailystartBal)/DailystartBal);

I Just need to set DailystartBal to AccountEquity() @ a specified time. Anyone here know what I am doing wrong ?

Thanks,

KK

 

Try this:

double DailystartBal;

int CurrentTime = TimeHour(TimeCurrent());

if (CurrentTime == StartHour-1) {DailystartBal = AccountEquity();}

double DailyGrowth = ((AccountEquity() - DailystartBal)/DailystartBal);

 
Maji:
Try this:

double DailystartBal;

int CurrentTime = TimeHour(TimeCurrent());

if (CurrentTime == StartHour-1) {DailystartBal = AccountEquity();}

double DailyGrowth = ((AccountEquity() - DailystartBal)/DailystartBal);

[/PHP]

No go. it still Resets the DailystartBal everytime AccountEquity() changes. returning a dailygrowth of 0.

Here is the entire function ...

[PHP]//ChartComment

void ChartComment() {

double DailystartBal;

int CurrentTime = TimeHour(TimeCurrent());

if (CurrentTime == StartHour-1) {DailystartBal = AccountBalance();}

double DailyGrowth = ((AccountBalance() - DailystartBal)/DailystartBal);

string sComment = "";

string sLine = "--------------------------------------------------------------";

string sNewLine = "\n";

sComment = sComment + sLine + sNewLine;

sComment = sComment + "- KURKA TRADER, My 2 ipps - "+ sNewLine;

sComment = sComment + sLine + sNewLine;

sComment = sComment + "Account Name : " + " KURKA FUND " + sNewLine;

sComment = sComment + "Current Balance : $ " + DoubleToStr(AccountBalance(),2) + sNewLine;

sComment = sComment + "Account Equity : $ " + DoubleToStr(AccountEquity(),2) + sNewLine;

sComment = sComment + "Account FreeMargin : $ " + DoubleToStr(AccountFreeMargin(),2) + sNewLine;

sComment = sComment + "Floating P&L : $ " + DoubleToStr(AccountProfit(),2) + sNewLine;

sComment = sComment + "Percentage Growth : % " + DoubleToStr(DailystartBal,4) + sNewLine;

sComment = sComment + sLine + sNewLine;

sComment = sComment + "OPEN POSITIONS : " + DoubleToStr(OrdersTotal(), 2)+ sNewLine;

sComment = sComment + sLine + sNewLine;

sComment = sComment + ": Type "+ ": Ticket " + " : Lots "+" : Swap "+" : Profit "+sNewLine;

int total = OrdersTotal();

for(int cnt=0;cnt<total;cnt++){

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderType() == OP_BUY){

sComment = sComment + ": Buy :"+" # "+ DoubleToStr(OrderTicket( ),0)+" : "+DoubleToStr(OrderLots( ),2)+" : $ "+DoubleToStr(OrderSwap(),2)+" : $ "+DoubleToStr(OrderProfit(),2)+sNewLine;

}

if (OrderType() == OP_SELL){

sComment = sComment + ": Sell :"+" # "+ DoubleToStr(OrderTicket( ),0)+" : "+DoubleToStr(OrderLots( ),2)+" : $ "+DoubleToStr(OrderSwap(),2)+" : $ "+DoubleToStr(OrderProfit(),2)+sNewLine;

}

}

sComment = sComment + sLine + sNewLine;

sComment = sComment + "Upper Trigger : " + DoubleToStr(HighTrigger, 4) + " BID : " + DoubleToStr(Bid, 4)+ sNewLine;

sComment = sComment + "Lower Trigger : " + DoubleToStr(LowTrigger, 4) + " ASK : " + DoubleToStr(Ask, 4)+ sNewLine;

sComment = sComment + sLine + sNewLine;

Comment(sComment);

}

I like the chart comment for backtesting. it helps allot to see exactly what your EA is doing espically with multiple open positions. The ability to see the % growth would be great...

 

You should describe DailystartBal in global variables.

I tried, and it works.

 

You may well want to keep the value as a global variable, as it then would survive EA invocations, as long as the MT4 program i running. In either case, you need two variables: one for the value, and another to tell whether the value has been assigned today or not.

You could use the following code snippet would make the assignment once with the first tick of the selected StartHour:

void ChartComment() {

if ( TimeHour(TimeCurrent()) == StartHour ) {

if ( GlobalVariableGet( "DailystartBalAssigned" ) == 0 ) {

GlobalVariableSet( "DailystartBal", AccountEquity() );

GlobalVariableSet( "DailystartBalAssigned", 1 );

}

} else {

GlobalVariableSet( "DailystartBalAssigned", 0 );

}

double DailystartBal = GlobalVariableGet( "DailystartBal" );

....

}