Stop trading until end of month if 4 losses in a row

Back to topics list To post a new topic, please log in or register
avatar
29
remix919 2015.11.24 23: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
avatar
29
remix919 2015.11.25 12: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();
}

 

avatar
Moderator
3407
GumRai 2015.11.25 12: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

avatar
12985
WHRoeder 2015.11.25 14: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

avatar
29
remix919 2015.11.27 02: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?
avatar
12985
WHRoeder 2015.11.27 13:58 #
 
Fix your code. If the trades are not the current month/current year, why are you counting them?
Back to topics list  

To add comments, please log in or register