Problem: status of all trades for the current day?

 

I would like to implement my EA so that I need to get only one winning trade for the day, and then just wait for tomorrow. Or, to put it otherway; EA should stop trading, if sum of all winning trades for the day is bigger than sum of all losing trades for that day, i.e. we are about one trade's "take profit" on the winning side.


An example:

- if first trade hits take profit; that's it for the day and next trade will be done tomorrow

- if first trade hits stop loss, and next two trades hit take profit, same thing


I've tried to implement that but I just can't get it working. Does anyone have a hint for how this should be implemented?


Thanks already!

 
AlliumPorrum:

I would like to implement my EA so that I need to get only one winning trade for the day, and then just wait for tomorrow. Or, to put it otherway; EA should stop trading, if sum of all winning trades for the day is bigger than sum of all losing trades for that day, i.e. we are about one trade's "take profit" on the winning side.


An example:

- if first trade hits take profit; that's it for the day and next trade will be done tomorrow

- if first trade hits stop loss, and next two trades hit take profit, same thing


I've tried to implement that but I just can't get it working. Does anyone have a hint for how this should be implemented?


Thanks already!

Hi i am having a similair problem. My post is under yours, only difference with mine is I need it for month not day.

Maybe if we share a few ideas we might figure it out?

I have tried to use this:


for(int i = 1;i<OrdersTotal();i++)
{
  OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
         {
           if (TimeMonth(TimeCurrent()) == TimeMonth(OrderCloseTime()))
           {
              if (OrderProfit() > 0)
              {
                 bool Ordermadeprofit = true
              }
           }
         }
        }
}

// then for my trade descision i would see if Ordermadeprofit is true or false. If its false then it can make a trade....

if(OrdersTotal() < 1 && Ordermadeprofit == false)
{
  //trade information here
}

Only problem Im having with this is that it dont work LOL!

It is like its always returning false even if a profitable trade has been made.

Anyway its somthing maybe to think about.

How are you going about it?

 

Update:

I have kind of got my code working, I used = static bool, instead of just a bog standard bool, because I was using it outside of a function.

I have no idea how you would calculate once you start using more than one trade for the day. The only thing I cud think is that you need to count the loosing trades and compare to the profitable trades, if profit >= (loss * 2) then stop trading.

I think you might need to look into storing data and retrieving it to find the profit/loss for the past trades. Or maybe you could use a counter for each and everytrades profit.

So:

double OrderLoss = 0.0, profOrder = 0.0;
double OrderLossDoubled = OrderLoss * 2;

if(OrderProfit() < 0)
{
  double OrderLoss = OrderLoss + OrderProfit()
}

if(OrderProfit() > 0)
{
  profOrder = profOrder + OrderProfit();
  if (profOrder >= OrderLossDoubled)       
  {
    // Code to stop trading for the day
  }
  else
  {
    //Continue Trading
  }
}

You could physically count the number of loosing trades and 
 win trades, just use interger instead of the physical profit/loss 
 and keep adding to it. Then when profOrder >= OrderLoss stop trading 


Obvoisly this is rough, you would need to select the order first. But would be interested to hear your thoughts on this as this is what i am struggling with myself.

 
fryfly:

Update:

I have kind of got my code working, I used = static bool, instead of just a bog standard bool, because I was using it outside of a function.

I have no idea how you would calculate once you start using more than one trade for the day. The only thing I cud think is that you need to count the loosing trades and compare to the profitable trades, if profit >= (loss * 2) then stop trading.

I think you might need to look into storing data and retrieving it to find the profit/loss for the past trades. Or maybe you could use a counter for each and everytrades profit.

So:


Obvoisly this is rough, you would need to select the order first. But would be interested to hear your thoughts on this as this is what i am struggling with myself.


In fact, I got it working:


int currentDay = 0;
int tradesWon = 0;

...

int checkWinsForDay()
{

currentDay = Day();
tradesWon = 0;
datetime orderOpenTime;
for(int i=0;i<OrdersHistoryTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("OrderSelect returned the error of ",GetLastError());
break;
}
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
orderOpenTime = OrderOpenTime();
if(TimeDay(orderOpenTime) != currentDay)
continue;
if(OrderProfit() > 0)
tradesWon++;
else if(OrderProfit() < 0)
tradesWon--;
}

}
return(tradesWon);
}


The problem previously was just that I did not understand to use OrdersHistoryTotal() in the loop, I used the OrderTotal() like in "normal" cases.

Reason: