EA but without making trades, Exit strategy

 

Hello,

I am making an exit strategy automation code, I started it as script but then thought that it much better to be EA to use OnTick() event handler

but the problem is that it keep opening trades when I run it or when a trade is close !!!!

I think this comes from auto generated code in  OnInit() so I commented it, but got error >>>> 2020.04.11 20:33:34.259 SL_TP_Steps (BTCUSDm,H1) invalid pointer access in 'Expert.mqh' (551,8)


Any advice 

Thanks in advance 

 
if it keeps opening trades you should put this condition that only put trade if the total amount of orders on this chart is equal to zero, then after the first trade is opened the the ea stops putting more trades.
 
What is the condition you talking about? 
 
MOHAMED AMR MOHAMED OSAMA I ABDELWAHAB:
What is the condition you talking about? 

He is talking about monitoring number of open trade.

Since you are working on exit strategy only, why don't you set your code to be executed only after a trade was opened (manually or programmatically). 


I think this comes from auto generated code in  OnInit() so I commented it,

why don't you share your code or at least show which part of code you've commented out.

 

Yes I run it after opening a trade 

and user provide the ticket number for the trade he want the ea to work on 

last line in the following code is where I catch the position/trade 

void OnTick()
  {
   ExtExpert.OnTick();
// Rates Structure for the data of the Last incomplete BAR
   MqlRates BarData[1];
   CopyRates(Symbol(), Period(), 0, 1, BarData); // Copy the data of last incomplete BAR
// Copy latest close prijs.
   double Latest_Close_Price = BarData[0].close;
// ticket=OrderSelect(OrderGetTicket(0));
   ticket=OrderSelect(ticketNum);


here is the default code which I didn't wort put it is there and I can't remove it for the error I mentioned 

//+------------------------------------------------------------------+
//| Initialization function of the expert                            |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- Initializing expert
   if(!ExtExpert.Init(Symbol(),Period(),Expert_EveryTick,Expert_MagicNumber))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing expert");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Creating signal
  CExpertSignal *signal=new CExpertSignal;
   if(signal==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating signal");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//---
   ExtExpert.InitSignal(signal);
// signal.ThresholdOpen(Signal_ThresholdOpen);
// signal.ThresholdClose(Signal_ThresholdClose);
//signal.PriceLevel(Signal_PriceLevel);
// signal.StopLevel(Signal_StopLevel);
//signal.TakeLevel(Signal_TakeLevel);
// signal.Expiration(Signal_Expiration);
//--- Creating filter CSignalAC
   CSignalAC *filter0=new CSignalAC;
   if(filter0==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating filter0");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
   signal.AddFilter(filter0);
//--- Set filter parameters
//  filter0.Weight(Signal_AC_Weight);
//--- Creation of trailing object
 //  CTrailingNone *trailing=new CTrailingNone;
  // if(trailing==NULL)
  //   {
      //--- failed
   //   printf(__FUNCTION__+": error creating trailing");
    //  ExtExpert.Deinit();
    //  return(INIT_FAILED);
   //  }
//--- Add trailing to expert (will be deleted automatically))
  // if(!ExtExpert.InitTrailing(trailing))
   //  {
      //--- failed
   //   printf(__FUNCTION__+": error initializing trailing");
    //  ExtExpert.Deinit();
   //   return(INIT_FAILED);
   //  }
//--- Set trailing parameters
//--- Creation of money object
   CMoneyFixedLot *money=new CMoneyFixedLot;
   if(money==NULL)
     {
      //--- failed
      printf(__FUNCTION__+": error creating money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Add money to expert (will be deleted automatically))
   if(!ExtExpert.InitMoney(money))
     {
      //--- failed
      printf(__FUNCTION__+": error initializing money");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Set money parameters
// money.Percent(Money_FixLot_Percent);
// money.Lots(Money_FixLot_Lots);
//--- Check all trading objects parameters
   if(!ExtExpert.ValidationSettings())
     {
      //--- failed
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- Tuning of all necessary indicators
   if(!ExtExpert.InitIndicators())
     {
      //--- failed
      printf(__FUNCTION__+": error initializing indicators");
      ExtExpert.Deinit();
      return(INIT_FAILED);
     }
//--- ok
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Deinitialization function of the expert                          |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ExtExpert.Deinit();
  }