datetime todaynight=TimeCurrent()-TimeCurrent()%(PERIOD_D1*60); tom_moro=t0daynight+Startfrom*3600;
where does t0daynight get its value?
if(OrdCls==true && TimeDayOfYear(TimeCurrent())>=tmoro) trade_disabled=false; // start trading again at this time
where does tmoro get its value?Why is it only called when an OrderClose() fails?
where does t0daynight get its value?
where does tmoro get its value?Why is it only called when an OrderClose() fails?
Thanks Keith watford: for your replies I made a mistake it should be...
int Startfrom=9; //my day start int Stop_on=20; //my day to end trading double Ppt=10; double AcctBalance = AccountBalance(); double Equity = AccountEquity(); double bal = AcctBalance+Ppt; datetime todaynight=TimeCurrent()-TimeCurrent()%(PERIOD_D1*60); tom_moro=todaynight+Startfrom*3600; bool trade_disabled=false; //close both buy and sell in profits if(UseDailyTarget==true && Equity>=bal && Hour()>Startfrom) { for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderType()==OP_BUY || OrderType()==OP_SELL) { OrdClose=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3); if(OrdClose && UseDailyTarget) { trade_disabled=true; //stop expert for now break; //stop } else { if(OrdCls==true && TimeDayOfYear(TimeCurrent())>=tom_moro) trade_disabled=false; // start trading again at this time } } } } } }
But my problem is getting it to work...just correct the lines..pls assist me if I got it correct now.thanks
seems your post is down the drain as usual, have you consider using OrderProfit to get the profit of the selected pair and close your trade after a certain profit is made, just my opinion though.
if(UseDailyTarget==true && Equity>=bal && Hour()>Startfrom) {
for(int i=OrdersTotal()-1; i>=0; i--)
{ if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{ if(OrderType()==OP_BUY || OrderType()==OP_SELL)
{ OrdClose=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3);
if(OrdClose && UseDailyTarget) //THIS MUST BE TRUE AS IT HAS ALREADY BEEN CHECKED SO IS SAME AS if(OrdClose)
{
trade_disabled=true; //stop expert for now
break; //stop
}
else
{
if(OrdCls==true && TimeDayOfYear(TimeCurrent())>=tom_moro) trade_disabled=false; // start trading again at this time
} } } } }
Your last section of code equates to
if(OrdClose) { // } else if(OrdClose) { // }
which of course makes no sense whatsoever.
Think about what you want your code to do.
seems your post is down the drain as usual, have you consider using OrderProfit to get the profit of the selected pair and close your trade after a certain profit is made, just my opinion though.
Nkechi Sonia KANU, did I tell you am look for orderprofit() for the selected pair
This is beyond your scope,allow professionals to answer my question, you have no
Idea what you suggested
if(UseDailyTarget==true && Equity>=bal && Hour()>Startfrom) {
for(int i=OrdersTotal()-1; i>=0; i--)
{ if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{ if(OrderType()==OP_BUY || OrderType()==OP_SELL)
{ OrdClose=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3);
if(OrdClose && UseDailyTarget) //THIS MUST BE TRUE AS IT HAS ALREADY BEEN CHECKED SO IS SAME AS if(OrdClose)
{
trade_disabled=true; //stop expert for now
break; //stop
}
else
{
if(OrdCls==true && TimeDayOfYear(TimeCurrent())>=tom_moro) trade_disabled=false; // start trading again at this time
} } } } }
Your last section of code equates to
which of course makes no sense whatsoever.
Think about what you want your code to do.
Thanks Keith Watford, I will check on your corrections later , thanks..
I think I want the EA to stop trading once profit or takeprofit is hit and resume nextday
Am also considering using OrderTakeprofit() and orderCloseTime() ,with time(), however I will notify if needed any corrections .thanks
static bool trade_disabled=false;
Thanks @Ernst van Den Merwe ,noted
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
pls i have this difficulty fix fixing this code to stop trading for the day if profit is made
my problem is it not working,looks like am missing something .thanks