Download MetaTrader 5
To add comments, please log in or register
Publish your article to let the traders see it in MetaTrader 5!
kankrz 2016.04.28 22:33 

I am new here and I am not programmer (yet). I have an idea I want to share  with you all and finally check it in practice / test. 
I found interesting piece of program (autor Joni) which I  modified a little bit.
Originally ROBOT buys or sells when RSI riches levels 30 or 70.
 It buys a few times at 30 and finally closes all buy-op at   70. Same for sell op at 70 RSI level. 
This tactic unfortunately leads to big looses so I decided to change this.

Practice shows that usually the very last operations from continuing buying/selling are profitable. That is why lot is variable. Robot changes it , Lot starts from 0.01 and increase it *2 or according to simple function (or factor).  
Generally I also don't want to trade with lot >2 so I put the limit:

if (lotb>=2) lotb=0.2 ;
 if (lotss>=2) lotss=0.2;

   if(_typeTrade==1){lotss=0.01; openOrder(OP_BUY,(lotb),SL,TP); closeAllSell();lotb=lotb*2;}
   if(_typeTrade==-1){lotb=0.01;  openOrder(OP_SELL,lotss,SL,TP); closeAllBuy();lotss=lotss*2;}


(typeTrade = 1 if RSI <=30.... so on

It works perfectly...

To avoid keeping loose ops too long I would like to control them at every bar close or thick. Let's say if all opened ops loos is about to 50$  I would like to close all ops straight away:

Very often trading goes 'in wrong direction' from the beginning. In that case I don't want to increase lot and closeAllSell / closeAllBuy at assuming loss level  . Let's say : 
if SellProfit > -10$ - close all ops.

And finally :

I found a piece of code what can control opened positions :

 //  int j;
 //  int ordersTotal1=OrdersTotal();
//   for(j=ordersTotal1-1; j>=0; j --)
//      if(OrderSelect(j,SELECT_BY_POS,MODE_TRADES))
//         if(OrderMagicNumber()==magic && OrderType()==OP_SELL)
//         {
//           SellProfit += OrderProfit();

The problem is : I don't know how to us it :) Where to paste it :)

I tried here :

  if(_typeTrade==-1){lotb=0.01; {XXXXXXXXXXXXXXX}; openOrder(OP_SELL,lotss,SL,TP); closeAllBuy();lotss=lotss*2;}

It checks opened positions but only if RSI is at 70 / 30. It doesn't satisfy  me...

I am sorry for my broken English. I hope that everyone who wanted understand my idea could understand...
Any help ? :)

Kind regards
Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
Alain Verleyen
Alain Verleyen 2016.04.30 20:38  

Forum on trading, automated trading systems and testing trading strategies


Please use the SRC button when you post code. Thank you.

This time, I edited it for you.

kankrz 2016.05.03 21:48  
Alain Verleyen:

Thank you very much Dude :)


Kind Regards


To add comments, please log in or register