Download MetaTrader 5
To add comments, please log in or register
You can test an application before buying it. Find out how to do that!
remix919
85
remix919 2015.11.24 22:18 
Trying to figure this out has got my brain in a bundle, lol, so my thinking would be to pull the trade information for the last 4 trades made and IF all of them resulted in loss, then SLEEP until the month = (currentmonth) + 1, would this work and anyone want to possibly offer a good structured code instead of my sloppiness? =D
remix919
85
remix919 2015.11.25 11:46  

Here is the code so far, I'm trying to find a good way to calculate the time to sleep until end of month though:

 

int LosCount=0; // ,ProfCout=0;
   int OrdHistory=OrdersHistoryTotal();
   if(OrdHistory>0 && OrderSymbol()==Symbol())
   { for(int cntl=MaxLosses;cntl>=1;cntl--)
      {
         if(OrderSelect(OrdHistory-cntl,SELECT_BY_POS,MODE_HISTORY) && OrderProfit()>=0)LosCount=0;//ProfCout++;
         if(OrderSelect(OrdHistory-cntl,SELECT_BY_POS,MODE_HISTORY) && OrderProfit()<0)LosCount++;
      }
   }
   //Comment(LosCount); // check counter in live

if(LosCount > MaxLosses) {
Sleep();
}
Keith Watford
Moderator
7870
Keith Watford 2015.11.25 11:56  
   if(OrdHistory>0 && OrderSymbol()==Symbol())

You have not selected an order yet so OrderSymbol() could be anything.

I your loop, you are assuming that the history is in a certain order. Also you are assuming that they are of the correct symbol

whroeder1
13593
whroeder1 2015.11.25 13:08  
remix919: I'm trying to find a good way to calculate the time to sleep until end of month though:
Don't sleep, just ignore ticks
void OnTick(){
   static int ignoreMonth = 0;
   if(Month() == ignoreMonth) return;
   ignoreMonth = 0; // Clear for next year.
   :
   if(condition){ ignoreMonth = Month(); return; } // Stop trading
remix919
85
remix919 2015.11.27 01:42  
Slight issue with that code, or perhaps rather my original code. The problem is once next month hits, then it re-calculates how many trades lost in a row, but it still shows the same 4 from last month so it just doesn't trade at all =\ any ideas?
whroeder1
13593
whroeder1 2015.11.27 12:58  
Fix your code. If the trades are not the current month/current year, why are you counting them?
/
To add comments, please log in or register