Coding help - page 290

 
mladen:
It is simple :

Place something like this at the beginning of the start() procedure of your EA and it will prevent it from working if the loss (or profit) already made that day exceeds some ammount :

double totalProfit=0;

for (int i =OrdersHistoryTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;

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

if (OrderMagicNumber() != someMagicNumber) continue;

if (iBarShift(Symbol(),PERIOD_D1,OrderCloseTime())==0)

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

totalProfit += OrderProfit()+OrderCommission()+OrderSwap();

}

if (totalProfit < someProfitLossLimit) return(0);

[/PHP]

Dear Sir MLADEN....

THANKSSSSS A LOT for the above codes.... IOU 2 credits.....

[PHP]

double totalProfit=0;

for (int i =OrdersHistoryTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

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

if (OrderMagicNumber() == someMagicNumber) continue;

if (iBarShift(Symbol(),PERIOD_D1,OrderCloseTime())==0)

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

totalProfit += OrderProfit()+OrderCommission()+OrderSwap();

}

if (totalProfit < someProfitLossLimit) return(0);

Just to check..... will this code prevent any more orders from a specific currency pair and MagicNumber.... if today's ACCUMULATED LOSS exceed someProfitLossLimit....

Thanks for the very-very fast reply....

best regrads

AZRUL...

 
12BPRO:
Dear Sir MLADEN....

THANKSSSSS A LOT for the above codes.... IOU 2 credits.....

double totalProfit=0;

for (int i =OrdersHistoryTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

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

if (OrderMagicNumber() == someMagicNumber) continue;

if (iBarShift(Symbol(),PERIOD_D1,OrderCloseTime())==0)

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

totalProfit += OrderProfit()+OrderCommission()+OrderSwap();

}

if (totalProfit < someProfitLossLimit) return(0);

[/PHP]

Just to check..... will this code prevent any more orders from a specific currency pair and MagicNumber.... if today's ACCUMULATED LOSS exceed someProfitLossLimit....

Thanks for the very-very fast reply....

best regrads

AZRUL...

Yes

It will prevent further code processing if the accumulated profit of closed orders is less than some amount. You can replace the last line with this :

[PHP]if (totalProfit < 0 && totalProfit < someProfitLossLimit) return(0);

To make sure that it is done only in cases when the cumulated "profit" is negative (when there were loses)

 
mladen:
Yes

It will prevent further code processing if the accumulated profit of closed orders is less than some amount. You can replace the last line with this :

if (totalProfit < 0 && totalProfit < someProfitLossLimit) return(0);
To make sure that it is done only in cases when the cumulated "profit" is negative (when there were loses)

Dear Sir MLADEN...

So Sorry Sir... I think I didn't make it clear enough for you.....

My intention is that a code for keeping tabs on the ACCUMULATED LOSS only for a specific currency pair and MagicNumber.... Not including the profit that it is makings... ONLY LOSS counts...

SORRY FOR THE CONFUSION..

Best regards..

AZRUL...

 
12BPRO:
Dear Sir MLADEN...

So Sorry Sir... I think I didn't make it clear enough for you.....

My intention is that a code for keeping tabs on the ACCUMULATED LOSS only for a specific currency pair and MagicNumber.... Not including the profit that it is makings... ONLY LOSS counts...

SORRY FOR THE CONFUSION..

Best regards..

AZRUL...

AZRUL

Profit can be negative (==loss) In closed otrders list there is a filed called Order() profit that keep the "profit" : positive for wining orders and negative for losing trades. That peace of code does exactly what you need

 

Dear Sir MLADEN,

The Theory is this.... if today happens to be a SIDEWAY market, I will end up losing some of the profit (if any) that has been made and X$ RISK on my capital.... That is not a protection against a very BAD DAY of trading.....

The reason for this is that I am willing to RISK at X$ per day from today's trading....

The above codes will eat up all the profits (if any) for the day plus it will also eat up my RISK (capital)...

THANKS

Best regards...

AZRUL...

 
mladen:
AZRUL Profit can be negative (==loss) In closed otrders list there is a filed called Order() profit that keep the "profit" : positive for wining orders and negative for losing trades. That peace of code does exactly what you need

Dear Sir MLADEN...

Thanks for enlighten me on the above suggestion...

I will try and search for any result....

best regards

AZRUL...

 

Dear Sir MLADEN,

Will the following codes do the trick...

Keeping tabs on the ACCUMULATED LOSS only for a specific currency pair and MagicNumber.... Not including the profit that it is makings... ONLY LOSS counts...

extern double LossAmount = -500.00

...............

int start()

if(LossRisk()<=LossAmount)

return(0);

...............

void LossRisk()

double totalLoss=0;

{

for (int i =OrdersHistoryTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

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

if (OrderMagicNumber() == someMagicNumber) continue;

if (iBarShift(Symbol(),PERIOD_D1,OrderCloseTime())==0)

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

totalLoss -= OrderProfit()+OrderCommission()+OrderSwap();

}

return(totalLoss);

}

Your Knowledge is highly appreciated...

yours truly

AZRUL....

 
12BPRO:
Dear Sir MLADEN,

Will the following codes do the trick...

Keeping tabs on the ACCUMULATED LOSS only for a specific currency pair and MagicNumber.... Not including the profit that it is makings... ONLY LOSS counts...

extern double LossAmount = -500.00

...............

int start()

if(LossRisk()<=LossAmount)

return(0);

...............

void LossRisk()

double totalLoss=0;

{

for (int i =OrdersHistoryTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

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

if (OrderMagicNumber() == someMagicNumber) continue;

if (iBarShift(Symbol(),PERIOD_D1,OrderCloseTime())==0)

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

totalLoss -= OrderProfit()+OrderCommission()+OrderSwap();

}

return(totalLoss);

}

[/PHP]

Your Knowledge is highly appreciated...

yours truly

AZRUL....

No it will not

If you want to add up only loses you have to add

&& (OrderProfit()+OrderCommission()+OrderSwap()<0)

So the function will look like this :

[PHP]void LossRisk()

double totalLoss=0;

{

for (int i =OrdersHistoryTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

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

if (OrderMagicNumber() == someMagicNumber) continue;

if (iBarShift(Symbol(),PERIOD_D1,OrderCloseTime())==0)

if (OrderType()==OP_BUY || OrderType()==OP_SELL && (OrderProfit()+OrderCommission()+OrderSwap())<0)

totalLoss += OrderProfit()+OrderCommission()+OrderSwap();

}

return(totalLoss);

}

 

Dear Sir MLADEN....

I am currently using this codes in my EA which is running on a M15 timeframe...

It will open a new order after M15 timeframe...

bool AddP()

{int _num=0; int _ot=0;

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

{if(OrderSelect(j,SELECT_BY_POS)==true && OrderSymbol()==Symbol() && OrderType()<3 && ((OrderMagicNumber()==Magic) || Magic==0))

{

_num++;if(OrderOpenTime()>_ot) _ot=OrderOpenTime();

}

}

if(_num==0) return(true);

if(_num>0 && ((Time[0]-_ot))>0)

return(true);

else return(false);

}

Could you alter this code to make an order for every 5 minute past the previous order....

although I am on a M15 timeframe....

HOPE YOU ARE NOT OFFENDED BY SENDING SO MANY QUESTION....

best regards

AZRUL...

 
mladen:
No it will not

If you want to add up only loses you have to add

&& (OrderProfit()+OrderCommission()+OrderSwap()<0)

So the function will look like this :

void LossRisk()

double totalLoss=0;

{

for (int i =OrdersHistoryTotal()-1; i>=0; i--)

{

if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;

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

if (OrderMagicNumber() == someMagicNumber) continue;

if (iBarShift(Symbol(),PERIOD_D1,OrderCloseTime())==0)

if (OrderType()==OP_BUY || OrderType()==OP_SELL && (OrderProfit()+OrderCommission()+OrderSwap())<0)

totalLoss += OrderProfit()+OrderCommission()+OrderSwap();

}

return(totalLoss);

}

Dear Sir MLADEN,

You do know your ways to get things done around here....

I am VERY-VERY GLAD to get some reply from you SIR....

PM me if there is anything that I could do in return... except for codings....

Thanks

Best regards

AZRUL...