Incorrect iCustom function outcomes

 

Hi all!


So i have been trying to implement a simple trading strategy based on a custom indicator. If "Forexprofits" prints any value then go Long, if "Value 2" prints anything then open a short position and close all long positions. (attachment 2)


Unfortunately, although I think i applied the iCustom function correctly (attachment 1 from the indicator parameters and line 26/27 from code), instead of printing necessary values, what I receive is this number:

2022.06.29 12:10:28.803 2022.06.17 00:00:00  Strzałki EURUSD,Daily: forexSignal = 21474836472147483647


I am sure there is a minor mistake somewhere, however I cannot indentify it, could you please help me with this?

Is the problem somehow related to buffers? 


All the best,

Sebastian 

double forexSignalHandle0, forexSignalHandle1;


double forexSignalBuffer0[],forexSignalBuffer1[],forexSignalBuffer2[],forexSignalBuffer3[],forexSignalBuffer4[],forexSignalBuffer5[],forexSignalBuffer6[],forexSignalBuffer7[];


double LastHigh; 
double LastLow; 

int OnInit() 
   {
   Print("Version 1.1");

   return(INIT_SUCCEEDED);
   }                   
int start()
  {  
  LastHigh = iHigh (NULL,0,1);
  LastLow = iLow(NULL,0,1);
  
  Print("Previous High/Low =" ,  iTime(NULL,0,1),",",
                                 iHigh(NULL, 0,1),",",
                                 iLow(NULL,0,1));
                                

   forexSignalHandle0=iCustom(NULL,0,"Forexprofitsupreme Signal",8,0,1,0,21,0,1,0,"",true,true,true,true,false,"","","","","","",2,4,0,1);
   forexSignalHandle1=iCustom(NULL,0,"Forexprofitsupreme Signal",8,0,1,0,21,0,1,0,"",true,true,true,true,false,"","","","","","",2,2,1,1);
  
   Print("forexSignal = ",forexSignalHandle0, forexSignalHandle1);  

   CheckForOpen();
   Print ("InsideStartAfterCheckForOpen");
   return (0);
   }
      
      

void CheckForOpen()
{
   int res;
   Print ("InsideCheckForOpen");   
   if (Volume[0]>1) return;
   if (forexSignalHandle0 >0 )
   {
      res=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-50000*Point,Ask+100000*Point,"SEMA",0,0,Blue);
      CloseSellPositions();
   }                          
   if (forexSignalHandle1 > 0)
   {  
     res=OrderSend(Symbol(),OP_SELL,1,Bid,3,Ask+50000*Point,Ask-100000*Point,"SEMA",0,0,Blue);
     CloseBuyPositions();
   }
}      
void CloseBuyPositions()   
{ 
   int res;  
   for (int i=OrdersTotal()-1; i >= 0; i--)
   {    
      res=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);      
      string CurrencyPair=OrderSymbol();
      if ((OrderType ()==OP_BUY)&& (_Symbol== CurrencyPair))       
      {
         res=OrderClose(OrderTicket(), OrderLots(),Bid,3,NULL);
         Print ("Pozycje Buy Zamknięte");
      }
   }
}  
void CloseSellPositions()   
{ 
   int res;  
   for (int i=OrdersTotal()-1; i >= 0; i--)
   {
      res=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);      
      string CurrencyPair=OrderSymbol();   
      if ((OrderType ()==OP_SELL)&& (_Symbol== CurrencyPair))    
      {
         res=OrderClose(OrderTicket(), OrderLots(),Ask,3,NULL);
         Print ("Pozycje Sell Zamknięte");   
      } 
   }
} 


Comparative Analysis of 10 Trend Strategies
Comparative Analysis of 10 Trend Strategies
  • www.mql5.com
The article provides a brief overview of ten trend following strategies, as well as their testing results and comparative analysis. Based on the obtained results, we draw a general conclusion about the appropriateness, advantages and disadvantages of trend following trading.
 
  1.    forexSignalHandle0=iCustom(NULL,0,"Forexprofitsupreme Signal",8,0,1,0,21,0,1,0,"",true,true,true,true,false,"","","","","","",2,4,0,1);
       forexSignalHandle1=iCustom(NULL,0,"Forexprofitsupreme Signal",8,0,1,0,21,0,1,0,"",true,true,true,true,false,"","","","","","",2,2,1,1);
    

    MT4 does not have handles.

  2. Without providing the indicator code, or a link to the exact version, no one can verify that.

  3.       res=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-50000*Point,Ask+100000*Point,"SEMA",0,0,Blue);

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  4.    if (Volume[0]>1) return;
    

    For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
              MT4: New candle - MQL4 programming forum #3 (2014)
              MT5: Accessing variables - MQL4 programming forum #3 (2022)

    I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
              Running EA once at the start of each bar - MQL4 programming forum (2011)

Reason: