New to Coding need a little Help - page 2

 
Yohana Parmi:

I have sent you first error identification above.

Did you updated it and try again (^̮^)

----

Did you know, work in programming is exciting. But sometimes it can be frustrating if our logic has not got there yet.

Happy coding and never give up.

--- or you can easily use this service : Freelance here: https://www.mql5.com/en/job, by requesting the source code.

Yes I applied it now only issue when I run it on strategy tester is order close error 4051 "invalid ticket for order close function". And yes I love programming I'm actually going to school this semester for it. Thank you for your help I really appreciate you taking your time out to help me on this.

 
Angel Dickinson:

Yes I applied it now only issue when I run it on strategy tester is order close error 4051 "invalid ticket for order close function. And yes I love programming I'm actually going to school this semester for it. Thank you for your help I really appreciate you taking your time out to help me on this


Yes, good luck.

The world needs more programmers in the coming years (^̮^)

 
Yohana Parmi:

Yes, good luck.

The world needs more programmers in the coming years (^̮^)


Can you direct me where I can figure out how to fix this error please?

 
Angel Dickinson:

Can you direct me where I can figure out how to fix this error please?


Okay, wait a moment please.

 
Angel Dickinson:

Can you direct me where I can figure out how to fix this error please?


//+------------------------------------------------------------------+
//|                                              Angel Dickinson.mq4 |
//|                                  Copyright 2017, Angel Dickinson |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Angel Dickinson"
#property link      ""
#property version   "1.00"
#property strict
input int MagicNumber = 12345;
input double lots = 0.10;
input int stopLoss = 1000;
input int takeProfit = 2000;
input int Slippage = 0;

int ticket, error;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
   if (TotalNoOfOrders() > 0) 
        return;
    
     
    double ema = iMA(NULL, 0, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
    double ema2 = iMA(NULL, 0, 200, 0, MODE_EMA, PRICE_CLOSE, 0);
    double adx = iADX(NULL, 0, 14, PRICE_CLOSE, 0, 0);    
    
     
    if ((ema > ema2)&&(adx > 50))
    {
     ResetLastError();
     ticket=OrderSend(Symbol(),OP_BUY,NormalizeDouble(lots,2), Ask, Slippage, Ask - stopLoss * Point, Ask + takeProfit * Point, "BossPips" ,MagicNumber,0, clrBlue);
     if(ticket<=0)
     {
      
      error=GetLastError();     
      //-- do something for errors ....

     }
     else 
     { 
       Print("Buy order succeeded!");
       //-- do something for succesful order
     }
    }//-- end if ema


    if (ema<ema2 && adx>50) 
    {
     ResetLastError();
     ticket=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lots,2),Bid, Slippage, Bid + stopLoss * Point, Bid - takeProfit * Point, "BossPips" ,MagicNumber,0,clrRed);
     if(ticket<=0)
     {
      
      error=GetLastError();     
      //-- do something for errors ....
     }
     else 
     { 
       Print("Sell order succeeded!");
       //-- do something for succesful order
     }
    }//-- end if ema
    

  
         if(OrderType()==OP_BUY)  
         {
             if((iRSI(NULL,0,14,PRICE_HIGH,0)>70)) //here is your close buy rule
             {
                ResetLastError();
                ticket=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slippage,clrRed);
                if(ticket<=0)
                {
                  error=GetLastError();     
                  //-- do something for errors ....
                }
                else 
                { 
                  Print("Close buy order succeeded!");
                 //-- do something for succesful close order
                }   
                   
             }//--end if iRSI
              
         }//--end if OP_BUY
         else 
         if(OrderType()==OP_SELL)
         {
             if((iRSI(NULL,0,14,PRICE_LOW,0)<30)) // here is your close sell rule
             {
               ResetLastError();
               ticket=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slippage,clrRed);
               if(ticket<=0)
               {
                  error=GetLastError();     
                  //-- do something for errors ....
               }
               else 
               { 
                  Print("Close sell order succeeded!");
                  //-- do something for succesful close order
               }   
             }//--end if iRSI
         }//--end if OP_SELL
        
}//---end ontick
//+------------------------------------------------------------------+
int TotalNoOfOrders()
{ 
   int cnt=0, total; 
   total = OrdersTotal(); 
   for(int i=total-1; i>=0; i--)
   {
      ticket=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()>=2 || OrderMagicNumber()!=MagicNumber) continue;
      
      cnt++; 
   }
   return(cnt);
}

Done (^̮^)

 
Yohana Parmi:

Okay, wait a moment please.


What I'm guessing the issue is is that the order close function does have a Orderselect function is that right?

 

Please realize that what you call 'a little' can be many hours, days, or years, or even a lifetime.

 
Yohana Parmi:

Done (^̮^)


Wow thank You.!!!! I was going to try and figure this out myself but you helped me a lot you are a life saver !!!

 
Marco vd Heijden:

Please realize that what you call 'a little' can be days, or years, or even a lifetime.


Sorry mate I just felt like this EA was pretty simple its not too complex

 
Angel Dickinson:

Wow thank You.!!!! I was going to try and figure this out myself but you helped me a lot you are a life saver !!!


hehe.. God help me better than I did (✿´‿`)

Reason: