Indicator which triggers EA doesnt buy at Signal

 

Hey guys, 


i am new in coding and i just did a few days of research to write my own code. I want to trigger my EA when a arrow shows up. After looking hours for it I found out that my Indicator has a password which i have to consider as well. After aaall that i made my first trades with it.

But it seems that it buys and sells randon anywhere on the chart. 

Are you guys able to find my mistake? 


Look at the Picture

Are you willing to help me please?


Best Regards


OGI


#property copyright "OG LOC"
#property link     " www.pornhub.com "

// Definitions
#define MAX_TICKETS 6

// Input parameters
extern double Lots = 0.1;
extern double Slippage = 2.0;
extern double TakeProfit = 100;
extern double StopLoss = 15;
extern int    MagicNr=100;
extern string Please_Enter_Password = "mypassword";
extern int EnableNativeAlerts = true ;
extern int EnableSoundAlerts = true;
extern int EnableEmailAlerts = true;
extern int EnablePushAlerts = true ;



// Global variable
int giTicket[MAX_TICKETS];

int init() {
  // Reset all tickets
  for (int i=0; i<MAX_TICKETS;i++)
    giTicket[i]=-1;
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start() { 
  double ArrowUp, ArrowDown;
  static datetime tCurTime;
  int iFreeTicket=-1;
  int i;
  
  // Get Supersignal state
  ArrowUp = iCustom(NULL, 0, "NobleImpulseLicensed", Please_Enter_Password,EnableNativeAlerts, EnableSoundAlerts ,EnableEmailAlerts,EnablePushAlerts,1,0);
  ArrowDown = iCustom(NULL, 0, "NobleImpulseLicensed",Please_Enter_Password,EnableNativeAlerts, EnableSoundAlerts ,EnableEmailAlerts,EnablePushAlerts,2,0);
  // Open orders on new bar only
  if (tCurTime != Time[0]) {
    tCurTime=Time[0];
    
    // Get the first free ticket
    iFreeTicket=GetFreeTicket();
    
    // Open Buy order if previous bar has arrow up signal
    if  (ArrowUp!=EMPTY_VALUE && iFreeTicket>-1) {
      giTicket[iFreeTicket]=OrderSend(Symbol(),OP_BUY,Lots, Ask, Slippage, 
                0, 0, "Supersignal", MagicNr+i, NULL, LimeGreen);    
    }
    // Open Sell order if previous bar has arrow up signal
    if  (ArrowDown!=EMPTY_VALUE && iFreeTicket>-1) {
      giTicket[iFreeTicket]=OrderSend(Symbol(),OP_SELL,Lots, Bid, Slippage, 
                0, 0, "Supersignal", MagicNr+i, NULL, LimeGreen);    
    }
  }
  
  // Check SL and TP for each ticket
  for ( i=0; i<MAX_TICKETS;i++) {    
    if (OrderSelect( giTicket[i], SELECT_BY_TICKET)==True) {
      // Check SL and TP for BUY ticket
      if (OrderType()==OP_BUY) {
        // Close position if SL is Hit
        if (ToPips(Bid,OrderOpenPrice())<=-StopLoss)
          if ( OrderClose(giTicket[i],Lots,Bid,Slippage)==True)
            giTicket[i]=-1; 
        // Close position if TP is Hit     
        if (ToPips(Bid,OrderOpenPrice())>=TakeProfit)
          if ( OrderClose(giTicket[i],Lots,Bid,Slippage)==True)
            giTicket[i]=-1;       
        //Print("Buy. Current Pips=",dPips(OrderOpenPrice(),Bid));  
      }
      // Check SL and TP for SELL ticket
      if (OrderType()==OP_SELL ) {
        // Close position if SL is Hit
        if (ToPips(OrderOpenPrice(),Ask)>=StopLoss)
          if ( OrderClose(giTicket[i],Lots,Ask,Slippage)==True)
            giTicket[i]=-1;   
        // Close position if TP is Hit
        if (ToPips(OrderOpenPrice(),Ask)<=-TakeProfit)
          if ( OrderClose(giTicket[i],Lots,Ask,Slippage)==True)
            giTicket[i]=-1;   
        //Print("Sell. Current Pips=",dPips(OrderOpenPrice(),Bid));  
      }
    }
  }
  
  return(0);
}

//---------------------------------------------------------------
// function: GetFreeTicket()
// Description: Return the index of the first free ticket, or -1
//---------------------------------------------------------------
int GetFreeTicket() {
  for (int i=0; i<MAX_TICKETS;i++)
    if (giTicket[i]==-1)
      return(i);
  return(-1);      
} 

//----------------------------------------------------------------
// function: ToPips()
// Description: Convert a price difference to pips.
//----------------------------------------------------------------
double ToPips(double dPrice1,double dPrice2,bool bAbs=false) {
  double dPipValue=(dPrice1-dPrice2)/Point; 
  if (bAbs) return( MathAbs(dPipValue));
  else return(dPipValue);
} 
Files:
FAIL.PNG  42 kb
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
Keith Watford:
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
Thank you, im sorry for that 
 
OGGITV:

Do not double post!!

I have deleted your duplicated topic.

Reason: