question about RSI bot

 

Hello traders, I have a question regarding scripting in Metaeditor. I have an rsi bot that buys under 30 rsi only it does this once. Does anyone here know how to place a buy order every new candle under 30rsi? I'm not a scripter myself, so I can't figure it out.

i put a file with it, i think it most be somewhere here?

Hopefully somebody can help me ;D

 
You are unlikely to get much help in the forum with code created by an EA builder.
 

Thanks for the reply! 

Fond two scripts on the forum. can you put those 2 together? 




#include <Trade\Trade.mqh>
#include <Trade\PositionInfo.mqh>

int pos=0;
int myRSIDefinition;

CTrade trade; // To send orders and close positions
CPositionInfo positionInfo; // to get info about current positions

int OnInit()
  {
// Define the handler once at EA Init, not every tick
   myRSIDefinition=iRSI(Symbol(),Period(),14,PRICE_CLOSE);
// If is not posible to get indicator handler print some error information and return with error code
   if(myRSIDefinition==INVALID_HANDLE)
     {
      Print("There was an error creating RSI handler!");
      return(INIT_FAILED);
     }
   return INIT_SUCCEEDED;
  }

void OnTick()
  {
  
  
   string signal="";
   double  Ask=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_ASK),Digits());
   double  Bid=NormalizeDouble(SymbolInfoDouble(Symbol(),SYMBOL_BID),Digits());
   double myRSIArray[];
   ArraySetAsSeries(myRSIArray,true);
   CopyBuffer(myRSIDefinition,0,0,3,myRSIArray);
   double myRSIValue=NormalizeDouble(myRSIArray[0],2);
   if(myRSIValue>70)
      signal="sell";
   if(myRSIValue<30)
      signal="buy";

   if(signal=="buy")
     {
      //First close all Sell positions
      for(pos=0; pos<PositionsTotal(); pos++)
        {
         //Select the position to load info
         if(positionInfo.SelectByIndex(pos))
           {
            // Get the position type, if sell then close it
            if(positionInfo.PositionType()==POSITION_TYPE_SELL)
              {
               trade.PositionClose(positionInfo.Ticket());
              }
           }
        }
        if (signal =="buy" && PositionsTotal()<1)
      trade.Buy(0.01,Symbol());
     Comment ("The current signal is: ",signal);
     }

   if(signal=="sell")
     {
      //First close all Buy positions
      for(pos=0; pos<PositionsTotal(); pos++)
        {
         //Select the position to load info
         if(positionInfo.SelectByIndex(pos))
           {
            // Get the position type, if buy then close it
            if(positionInfo.PositionType()==POSITION_TYPE_BUY)
              {
               trade.PositionClose(positionInfo.Ticket());
              }
           }
        }
        
        if (signal =="sell" && PositionsTotal()<1)
      trade.Sell(0.01,Symbol());
     Comment ("The current signal is: ",signal);
     }
     


  }



bool isNewBar=IsNewBar(); // new bar check
signal="";

if(isNewBar)
  {
   static double myRSIArray[2];
   int shift=1;
   int amount=2;
   if(CopyBuffer(myRSIDefinition,MAIN_LINE,shift,amount,myRSIArray)!=amount) { Print("CopyBuffer failed, error: ",_LastError); return; }
   double rsi1=myRSIArray[1];
   double rsi2=myRSIArray[0];
   if(rsi2<=70 && rsi1>70)
      signal="sell";
   if(rsi2>=30 && rsi1<30)
      signal="buy";
  }
 
Learn to code or hire a freelancer. Why anyone should do it for you for free?
 
Jan pieter #: can you put those 2 together? 

Yes.
     How To Ask Questions The Smart Way. (2004)
          Only ask questions with yes/no answers if you want “yes” or “no” as the answer.