Repeated execution of OnTick

 
Hello,
I am learning mql5. I have developed a module that validates the inputs and numerous indicators that confirm it, or not.
In the strategy tester I can manually run the module one by one with each of the indicators/oscillators.

I want to develop something from OnTick that allows me to execute the module with each of the indicators from the program. But I don't see how to do it.

Could someone give me some idea?
Thanks in advance.
Juan Luis


 
febrero59: I am learning mql5. I have developed a module that validates the inputs and numerous indicators that confirm it, or not. In the strategy tester I can manually run the module one by one with each of the indicators/oscillators. I want to develop something from OnTick that allows me to execute the module with each of the indicators from the program. But I don't see how to do it. Could someone give me some idea?

Make your modules self contained and give each one an the equivalent of an OnTick event handler, and then loop through all the modules calling each of them in turn from the EA's OnTick event. That is standard OOP event handling 101.

 
Fernando Carreiro #:

Make your modules self contained and give each one an the equivalent of an OnTick event handler, and then loop through all the modules calling each of them in turn from the EA's OnTick event. That is standard OOP event handling 101.

I have not been able to find specific information on the web about what you are telling me, which I appreciate.

Could you provide me with a related link?

Excuse the ignorance.

 
febrero59 #: I have not been able to find specific information on the web about what you are telling me, which I appreciate. Could you provide me with a related link? Excuse the ignorance.
It's just simple logic. MQL's own Standard Library has the Strategy Modules that serve as the example in this case. For example the CExpert class has Event Processing Methods like for example OnTick().
Documentation on MQL5: Standard Library / Strategy Modules
Documentation on MQL5: Standard Library / Strategy Modules
  • www.mql5.com
Strategy Modules - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
febrero59 #: I have not been able to find specific information on the web about what you are telling me, which I appreciate.

There is nothing to find. You just do that. That is like someone telling you how to drive from A to B, and you're asking about how to start the car.

  1. MT4: Learn to code it.

    MT5: Begin learning to code it.

    If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into your code.

  2. Or pay (Freelance) someone to code it. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2019)

We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help (2017)

 
Hello,
The situation I am in is very summed up in the attached code: An entry signal defined by an MA indicator and an entry confirmed by an oscillator.
In the presented case I have 2 oscillators and in the strategy tester I can test the 2 separately or both together.
What I propose is being able to execute both individually from the strategy simulator with a single execution of the simulator. The data would already be extracted individually with Print, Alert, or .txt.
I only request some more specificity to be able to continue with the idea, since I do not know how to find something that allows me to do so.
Thanks in advance,
Juan Luis.
PS: With a link that could be directly related could also be enough
#include<Trade\Trade.mqh>
CTrade  trade;

input double Lotes=0.01;
input double TP=0.0001; //TakeProfit
input double SL=0.0001; //StopLoss

input bool BUL=false;
input bool CCI=false;

string senal, entrada;
double Ask, Bid;
      
void OnInit()
{
 
}

void OnTick()
{
   Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); 
   Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
   senal=SenalIMA();

   if(BUL==true){ 
                   entrada=EntradaBUL();
                   if(senal=="buy" && entrada=="buy") OpenBuy();
                   if(senal=="sell" && entrada=="sell") OpenSell();
                }  

   if(CCI==true){ 
                   entrada=EntradaCCI();
                   if(senal=="buy" && entrada=="buy") OpenBuy();
                   if(senal=="sell" && entrada=="sell") OpenSell();
                }
}
 
string SenalIMA()
  {             
     MqlRates PriceInfo[]; 
     ArraySetAsSeries(PriceInfo,true);   
     int PriceData =CopyRates(Symbol(),Period(),0,3,PriceInfo);   
     senal="";
     double myPriceArray[];  
     int AdaptiveMovingAverageDefinition = iAMA (_Symbol,_Period,9,2,30,0,PRICE_CLOSE);
     ArraySetAsSeries(myPriceArray,true);
     CopyBuffer(AdaptiveMovingAverageDefinition,0,0,3,myPriceArray); 
     double AdaptiveMovingAverageValue=NormalizeDouble(myPriceArray[0],6); 
      
     if (AdaptiveMovingAverageValue> PriceInfo[0].close) senal ="buy";
     if (AdaptiveMovingAverageValue< PriceInfo[0].close) senal ="sell";
          
          return senal;
  }

string EntradaBUL()
  {   
      entrada="";
      static double BullsPowerValueOld;
      double myPriceArray[];
      int BullsPowerDefinition =iBullsPower(_Symbol,_Period,13); 
      ArraySetAsSeries(myPriceArray,true);
      CopyBuffer(BullsPowerDefinition,0,0,3,myPriceArray);

      double BullsPowerValue=(myPriceArray[0]); 
       
      if ((BullsPowerValue>0)&&(BullsPowerValueOld<0)) {entrada="buy";}
      BullsPowerValueOld=BullsPowerValue;
      
      return entrada;   
  }

string EntradaCCI()
  {   
      entrada="";
      double myPriceArray[];
      int ICCIDefinition = iCCI (_Symbol,_Period,14,PRICE_TYPICAL); 
      ArraySetAsSeries(myPriceArray,true);
      CopyBuffer(ICCIDefinition,0,0,3,myPriceArray);

      double ICCIVal=(myPriceArray[0]); 

      if (ICCIVal>100) entrada="sell";
      if (ICCIVal<-100) entrada="buy";         
      
      return entrada;   
  }


void OpenBuy() {trade.Buy(Lotes,NULL,Ask,Ask-SL,Ask+SL,NULL);}

void OpenSell() {trade.Sell(Lotes,NULL,Bid,Bid+SL,Bid-SL,NULL);}


Reason: