Writing a profitable trading bot - page 2

 
input double Lots  = 0.01;
input int MyTF = 1440;
input int RSILen = 2;



void OnTick()
  {


   int   ticket,currBar;
   double rsi_2,rsi_2_prev;


   if(Bars - currBar > 0)
     {
      rsi_2 = iRSI("GBPJPY",MyTF,RSILen,PRICE_CLOSE,1);
      rsi_2_prev = iRSI("GBPJPY",MyTF,RSILen,PRICE_CLOSE,2);


      currBar = Bars;
      if(countOrders() == 0)
        {



         if(rsi_2 >=70 && rsi_2_prev < 70)
           {

            ticket=OrderSend("GBPJPY",OP_BUY,Lots,Ask,3,0.0,0.0,"LOL Long",1000,0,Green);

            

            return;
           }

         else
            if(rsi_2 <= 30 && rsi_2_prev > 30)
              {

               ticket=OrderSend("GBPJPY",OP_SELL,Lots,Bid,3,0.0,0.0,"LOL Short",1000,0,Red);

               

               return;

              }

        




        }
      else
         if(countOrders() > 0)
           {


            closingOrders(rsi_2,rsi_2_prev);


           }

     }

  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void closingOrders(double rsi, double rsi_prev)
  {

   if(OrdersTotal() >0)
     {
      for(int i=OrdersTotal(); i>=0; i--)
        {
         if(OrderSelect(i-1,SELECT_BY_POS)==true)
           {
            if(OrderSymbol() == "GBPJPY" && OrderMagicNumber()>0)
              {
               if(OrderType()==OP_BUY && rsi <30 && rsi_prev >= 30)
                 {
                  OrderClose(OrderTicket(),Lots,Bid,2,Yellow);

                 }
               else
                  if(OrderType()==OP_SELL && rsi > 70 && rsi_prev <= 70)
                    {

                     OrderClose(OrderTicket(),Lots,Ask,2,Gray);

                    }

              }


           }

        }

     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int countOrders()
  {
   int orderSum = 0;
   if(OrdersTotal() >0)
     {
      for(int i=OrdersTotal(); i>=0; i--)
        {
         if(OrderSelect(i-1,SELECT_BY_POS)==true)
           {
            if(OrderSymbol() == "GBPJPY" && OrderMagicNumber()>0)
              {
               orderSum += 1;
              }
           }
        }
     }

   return orderSum;
  }

Just implemented the 2-Period RSI strategy maximo quoted. It looks good and could be proven positive expectancy.

The author shares the strategy for free so it's a bit slow and the drawdown may scare you to unplug. 


Tested From 2020.1.1 till now at 0.01 lots

Spread is 20 (Some brokers offer a lower spread for a commision fee)

Profit: 272 USD

Profit Factor: 1.56

Maximum Drawdown: 113 USD

Longs: 53 (53% won)

Shorts: 53 (35% won)

 
William William #:

Just implemented the 2-Period RSI strategy maximo quoted. It looks good and could be proven positive expectancy.

The author shares the strategy for free so it's a bit slow and the drawdown may scare you to unplug. 


Tested From 2020.1.1 till now at 0.01 lots

Spread is 20 (Some brokers offer a lower spread for a commision fee)

Profit: 272 USD

Profit Factor: 1.56

Maximum Drawdown: 113 USD

Longs: 53 (53% won)

Shorts: 53 (35% won)


Thank you for sharing.

Is that an average win rate of 44%?

Why is there such an imbalance between buy and sell?

 
Dominik Christian Egert #: Why is there such an imbalance between buy and sell?

Probably because the symbol in question has a longer-term up-trend bias for the test period.

EDIT: Confirmed. GBP/JPY does have a up-trend bias since the beginning of 2020.


 
Fernando Carreiro #: Probably because the symbol in question has a longer-term up-trend bias for the test period.

EDIT: Confirmed. GBP/JPY does have a up-trend bias since the beginning of 2020.

Thank you for clarifying. That's what I suspected.
 
Dominik Christian Egert #:

Thank you for sharing.

Is that an average win rate of 44%?

Why is there such an imbalance between buy and sell?

No problem. The imbalance could be the uptrend bias like Fernando said. In the video the guy tested it from 2011 till now and the result was impressive.   

I tested it again from March 2017(max I can have on MT4) in Every Tick mode, and the overall winrate is about 38%, with Long winrate 42% and Short 34%. 

Files:
TesterGraph.gif  26 kb