Another Beginner Script (I need Help)

 

here is the problem, I wanted my positions to stack as they get profits and as well do a "martingale" I know this is not martingale because this is not doubling the lots on wrong trades but here is what it is supposed to do.

- Open an order in both sides buy/sell for the currency with a take profit of 50 pips.

-Then when it notices there is only a losing trade (exemple buy -60 pips) it opens 2x sell and 1x buy so if there is a long term trend it will not stack more losing but stack more winning.

- Maybe there is a simpler way to make this anyways I'm sure this is a good way to start programming eas.

here is the code

//+------------------------------------------------------------------+
//|                                                        stacker.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, "


int    Magic        = 123456;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+


int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| EA program start function                                        |
//+------------------------------------------------------------------+
void start()
  //----
{
if (OrdersTotal() == 0)
   {
      OpenMore();
   }
else
   {
   CheckLoss();
   }
return(0);
}

void CheckLoss()
{
   RefreshRates();
      if (AccountProfit() <= (-50 * OrdersTotal()))
         {
            CheckOpen();
            OpenMore();
         }
   return(0);
   }
   
//+------------------------------------------------------------------+

   
void OpenMore()
   {
      RefreshRates();
      OrderSend("CADJPY", OP_SELL, 0.1, Bid, 3, Bid+3000*Point, Bid-500*Point, "", Magic, 0);
      Sleep(15000);
      RefreshRates();
      OrderSend("CADJPY", OP_BUY, 0.1, Ask, 3, Ask-3000*Point, Ask+500*Point, "", Magic, 0);
      Sleep(900000);
      CheckLoss();
   }

void CheckOpen()
   {
      OrderSelect(1, SELECT_BY_POS, MODE_TRADES);
      int OT = OrderType();
         if (OT == OP_BUY)
            {
               RefreshRates();
               OrderSend("CADJPY", OP_SELL, 0.1, Bid, 3, Bid+3000*Point, Bid-500*Point, "", Magic, 0);
               Sleep(15000);
            }
         if (OT == OP_SELL)
            {
               RefreshRates();
               OrderSend("CADJPY", OP_BUY, 0.1, Ask, 3, Ask-3000*Point, Ask+500*Point, "", Magic, 0);
               Sleep(15000);
            }
   }