Metatrader 5 coding questions / issues - page 13

 
dr.house7:
I need to try a bit...

by the way, I did delete all the StopCycle filter from the first code, that is probably the main problem, but I thought it was useless with OpenBuySignal condition...

A normal mind, find the C + + language really stupid, now I know why it has been replaced by many other languages ​​leaner and more dynamic

Doc

I don't think tat the StopCycle is causing that problem. I think that the main problem is that metatrader 5 versions tend to be very complicated and that easily leads to problems. The way how that "macd" EA is written it hides most of the things we actually do not need to see and leaves the essential - that way only what is really important is left and can help in building an error free EA

 
mladen:
Doc I don't think tat the StopCycle is causing that problem. I think that the main problem is that metatrader 5 versions tend to be very complicated and that easily leads to problems. The way how that "macd" EA is written it hides most of the things we actually do not need to see and leaves the essential - that way only what is really important is left and can help in building an error free EA

Thanks Mladen,

I have this doubt:

I need to place in your code this part for calculate my pips earning during a deal:

double TotalProfit(int mode)

{

int total = PositionsTotal();

double profit = 0;

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

{

string sSymbol=PositionGetSymbol(cnt);

if(PositionSelect(sSymbol) == true && sSymbol == _Symbol && PositionGetInteger(POSITION_MAGIC) == Magic)

{

double open = PositionGetDouble(POSITION_PRICE_OPEN);

double close = PositionGetDouble(POSITION_PRICE_CURRENT);

if(mode == 1)

{

if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY ) profit = (close - open)/_point;

else

if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) profit = (open - close)/_point;

}

else

profit = PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP) + PositionGetDouble(POSITION_COMMISSION);

}

}

return(profit);

}

Is there a simpler way to code it?

 
dr.house7:
Thanks Mladen,

I have this doubt:

I need to place in your code this part for calculate my pips earning during a deal:

double TotalProfit(int mode)

{

int total = PositionsTotal();

double profit = 0;

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

{

string sSymbol=PositionGetSymbol(cnt);

if(PositionSelect(sSymbol) == true && sSymbol == _Symbol && PositionGetInteger(POSITION_MAGIC) == Magic)

{

double open = PositionGetDouble(POSITION_PRICE_OPEN);

double close = PositionGetDouble(POSITION_PRICE_CURRENT);

if(mode == 1)

{

if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY ) profit = (close - open)/_point;

else

if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) profit = (open - close)/_point;

}

else

profit = PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP) + PositionGetDouble(POSITION_COMMISSION);

}

}

return(profit);

}
Is there a simpler way to code it?

Doc

No, there is no simpler way to do that

 
mladen:
Doc No, there is no simpler way to do that

Mladen,

I tried but probably there is something wrong with the getLastOrderType function because it doesn't open any position

doc

Files:
my_try.mq5  8 kb
 
dr.house7:
Mladen,

I tried but probably there is something wrong with the getLastOrderType function because it doesn't open any position

doc

Doc

Just replace the "-1" in the following line :

trade.PositionOpen(_Symbol,-1,getLots(Lots,Risk,StopLossPips*pip),SymbolInfoDouble(_Symbol,signal==ORDER_TYPE_SELL ? SYMBOL_BID:SYMBOL_ASK),sl,tp);

with "signal" and it will work

 

Good morning Mladen,

I started to code what should be my close...but I don't know what condition is necessary here

void ManageOpened()

{

int doWhat = checkExit(); if (doWhat==_doNothing) return;

//

//

//

//

ENUM_ORDER_TYPE signal2;

if (doWhat==_doCloseBuy) signal2 = ORDER_TYPE_SELL;

if (doWhat==_doCloseSell) signal2 = ORDER_TYPE_BUY;

Could you please tell me the right and proper way?

Thanks

doc

Files:
my_try_3.mq5  11 kb
 
dr.house7:
Good morning Mladen,

I started to code what should be my close...but I don't know what condition is necessary here

void ManageOpened()

{

int doWhat = checkExit(); if (doWhat==_doNothing) return;

//

//

//

//

ENUM_ORDER_TYPE signal2;

if (doWhat==_doCloseBuy) signal2 = ORDER_TYPE_SELL;

if (doWhat==_doCloseSell) signal2 = ORDER_TYPE_BUY;

Could you please tell me the right and proper way? Thanks

doc

Doc

Try to do something like in the one attached

_________________

PS: even though it is closing the position when signaled so, maybe you should check for the conditions to close in the checkExit() function

Files:
my_try_3_1.mq5  10 kb
 

Mladen,

I have a problem with the time filter...I cannot have 0 neither have minutes.

Another thing is that I cannot delete it from close opened because otherwise it doesn't work the checkexit condition.

How could I combine together ct.hour && ct.min ? I need to write something like double date(int Hour, int Min) etc.?

Thanks

doc

 
dr.house7:
Mladen,

I have a problem with the time filter...I cannot have 0 neither have minutes.

Another thing is that I cannot delete it from close opened because otherwise it doesn't work the checkexit condition.

How could I combine together ct.hour && ct.min ? I need to write something like double date(int Hour, int Min) etc.?

Thanks

doc

Doc,

To effectively turn the time filter off set the start time to 0 and end time to 24

To add minutes, it would need to have minutes specified in the parameters and then used in the time filter

 
dr.house7:
Mladen,

I have a problem with the time filter...I cannot have 0 neither have minutes.

Another thing is that I cannot delete it from close opened because otherwise it doesn't work the checkexit condition.

How could I combine together ct.hour && ct.min ? I need to write something like double date(int Hour, int Min) etc.?

Thanks

doc

Doc,

In order to allow combinations of hour like from 22 to 03 (just one example) and to include the starting and ending our in the time filter, the code for time checking should look like this :

bool allowedHours;

if (EndingHour<StartHour)

allowedHours = (ct.hour>=StartHour || ct.hour<=EndingHour);

else allowedHours = (ct.hour>=StartHour && ct.hour<=EndingHour);

if you want to include minutes too then they should be declared in parameters and a ct.min>=SomeMinute or ct.min<=SomeOtherMinte can be added to conditions