A request for help to modify my EA

 

Hi all, i would appreciate your help to modify my EA to open 5x positions when my prescribed conditions are met. Moreover, i would like my EA to open a new position to the opposite direction should a new condition arise in that direction and/or close the initial trade as a result of the new signal generated.

Here's my source code: 

void OnTick(){

   int bars = iBars(_Symbol,Timeframe);

   if(barsTotal != bars){

      barsTotal = bars;

         

      double rsi[];

      CopyBuffer(handleRsi,MAIN_LINE,1,1,rsi);

      

      double Stoch[];

      CopyBuffer(handleStoch,MAIN_LINE,1,1,Stoch);

      

      double macdMain[], macdSignal[];

      CopyBuffer(handleMacd,MAIN_LINE,1,1,macdMain);

      CopyBuffer(handleMacd,SIGNAL_LINE,1,1,macdSignal);

      

      double bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);

      double ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);

      

if(posTicket > 0){

   if(PositionSelectByTicket(posTicket)){

      double PosPriceOpen = PositionGetDouble(POSITION_PRICE_OPEN);

      double PosTp = PositionGetDouble(POSITION_TP);

      double PosSl = PositionGetDouble(POSITION_SL);

      if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY){

         if(IsFilterMacd){

            if(macdMain[0] < macdSignal[0]){

               if(trade.PositionClose(posTicket)){

                  Print(__FUNCTION__," > Pos #",posTicket,"was closed because of macd...");

                  posTicket = 0;

                  }

               }

            }

            if(TslPercent > 0){

               if(bid > PosPriceOpen + PosPriceOpen * TslTriggerPercent / 100){

                  double sl = bid - bid * TslPercent / 100;

                     if(sl > PosSl){

                        if(trade.PositionModify(posTicket,sl,PosTp)){

                       }

                    }

                }

             }

        }else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL){

            if(IsFilterMacd){

               if(macdMain[0] > macdSignal[0]){

                  if(trade.PositionClose(posTicket)){

                     Print(__FUNCTION__," > Pos #",posTicket,"was closed becasue of macd...");

                     posTicket = 0;

                      }

                   }

                }

            if(TslPercent > 0){

               if(ask < PosPriceOpen - PosPriceOpen * TslTriggerPercent / 100){

                  double sl = ask + ask * TslPercent / 100;

                     if(sl < PosSl  || PosSl == 0){

                        if(trade.PositionModify(posTicket,sl,PosTp)){

                      

                        

                       }

                     }

                   }

                 }

               }

            //The body of if statement

            }else{

               Print(__FUNCTION__," > #",posTicket,"Was closed...");

               posTicket = 0;

            }

            

       }

         if(posTicket <= 0){

            if(rsi[0] > RsiTriggerSell){

               if(Stoch[0] > StochTriggerSell){

                  if(macdMain[0] < macdSignal[0]){

                     double entry = SymbolInfoDouble(_Symbol,SYMBOL_BID);

                     double tp = entry - entry * TpPercent / 100;

                     double sl = entry + entry * SlPercent / 100;

                     if(trade.Sell(Lots,_Symbol,entry,sl,tp)){

                        posTicket = trade.ResultOrder();

                           Print("Sell");

                        }

                      }

                  }

             }  

         

         if(rsi[0] < RsiTriggerBuy){

            if(Stoch[0] < StochTriggerBuy){

               if(macdMain[0] > macdSignal[0]){

                  double entry = SymbolInfoDouble(_Symbol,SYMBOL_ASK);

                  double tp = entry + entry * TpPercent / 100;

                  double sl = entry -  entry * SlPercent / 100;

                  if(trade.Buy(Lots,_Symbol,entry,sl,tp)){

                      posTicket = trade.ResultOrder();

                         Print("Buy");            

                       }

      

                     }

                   }

                 }

               }

            }

         }

Please bear with me for a poorly choreographed question! I really appreciate your help in advance.

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties
  • www.mql5.com
Position Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
amaluleke:

Hi all, i would appreciate your help to modify my EA to open 5x positions when my prescribed conditions are met. Moreover, i would like my EA to open a new position to the opposite direction should a new condition arise in that direction and/or close the initial trade as a result of the new signal generated.



Post your code properly, use the code button, edit your existing post, do not repost.
 
Dominik Egert #

Post your code properly, use the code button, edit your existing post, do not repost.
Done. Thanks, Dominik!