Hello traders
I'm very new to coding, but here is my first code giving me an error "iCustom - Wrong parameters count". I appreciate if you can find the source of error. FYI I'm pasting my code down below, also I'm calling an indicator (Gann HiLo Activator SSL) which I have downloaded from this website (https://www.mql5.com/en/code/8032)
//+------------------------------------------------------------------+
//| My Strategy GannHiLo.mq4 |
//| MJ |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "MJ"
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+adding Gann HiLo --------------------
#property indicator_buffers 1
#property indicator_color1 Blue
extern int Lb=10;
double ssl[],Hld,Hlv,GannHiLo;
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,ssl);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
//----
for(int i=Bars-Lb;i>=0;i--)
{
if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1))
Hld=1;
else
{
if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1))
Hld=-1;
else
Hld=0;
}
if(Hld!=0)
Hlv=Hld;
if(Hlv==-1)
{ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1);
GannHiLo=ssl[i];}
else
{ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1);
GannHiLo=ssl[i];}
}
//----
return(0);
}
//+------------------------------------------------------------------+Adding Gann HiLo Ended here.
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
//int OnInit()
//{
//---
//---
//return(INIT_SUCCEEDED);
//}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
//void OnDeinit(const int reason)
// {
//---
//}
input double TakeProfit =10000;
input double Lots =0.1;
input double TrailingStop =0;
input int MovingPeriod =10;
input int MovingShift =0;
input int MATrendPeriod =10;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double MyTL;
// double MaCurrent,MaPrevious;
int cnt,ticket,total;
//---
// initial data checks
// it is important to make sure that the expert works with a normal
// chart and the user did not make any mistakes setting external
// variables (Lots, StopLoss, TakeProfit,
// TrailingStop) in our case, we check TakeProfit
// on a chart of less than 100 bars
//---
if(Bars<100)
{
Print("bars less than 100");
return;
}
if(TakeProfit<10)
{
Print("TakeProfit less than 10");
return;
}
//--- to simplify the coding and speed up access data are put into internal variables
//--------------------------------------------------------------------------
MyTL=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0)-iCustom(Symbol(),0,"Gann HiLo Activator SSL");
total=OrdersTotal();
if(total<1)
{
//--- no opened orders identified
if(AccountFreeMargin()<(1000*Lots))
{
Print("We have no money. Free Margin = ",AccountFreeMargin());
return;
}
//--- check for long position (BUY) possibility
if(MyTL>0)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My sample",16384,0,Green);
//Ask+TakeProfit*Point
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else
Print("Error opening BUY order : ",GetLastError());
return;
}
//--- check for short position (SELL) possibility
if(MyTL<0 )
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"My sample",16384,0,Red);
//Bid-TakeProfit*Point
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("SELL order opened : ",OrderOpenPrice());
}
else
Print("Error opening SELL order : ",GetLastError());
}
//--- exit from the "no opened orders" block
return;
}
//--- it is important to enter the market correctly, but it is more important to exit it correctly...
for(cnt=0;cnt<total;cnt++)
{
if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
//--- long position is opened
if(OrderType()==OP_BUY)
{
//--- should it be closed?
if(MyTL<0 )
{
//--- close order and exit
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),0,MarketInfo(Symbol(),MODE_BID),0,Green);
//TakeProfit==(MarketInfo(Symbol(),MODE_BID)-OrderOpenPrice());
if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet))
Print("OrderClose error ",GetLastError());
return;
}
//--- check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
else // go to short position
{
//--- should it be closed?
if(MyTL>0)
{
//--- close order and exit
ticket=OrderModify(OrderTicket(),OrderOpenPrice(),0,MarketInfo(Symbol(),MODE_ASK),0,Red);
//TakeProfit==(MarketInfo(Symbol(),MODE_ASK)-OrderOpenPrice());
if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet))
Print("OrderClose error ",GetLastError());
return;
}
//--- check for trailing stop
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
//--- modify order and exit
if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red))
Print("OrderModify error ",GetLastError());
return;
}
}
}
}
}
}
//---
}
//+------------------------------------------------------------------+
Calling an iCustom on a period higher than the current requires a few things :
- Storing the higher period values with the original shift to a buffer
- creating a 'transposed' shift from the higher TF to the smaller one; using Time[i] & iBarShift
- filling the values to another buffer with the 'transposed' shift
- .... then you can do a valid comparison.
hth
I'm not coder, i 'm unable to do what you said but i bypassed the issue using MTF_Laguerre.mq4 ...
Solved.
Didn't know that. Yes MTF will solve that....
Hello traders I'm very new to coding, but here is my first code giving me an error "iCustom - Wrong parameters count". I appreciate if you can find the source of error. FYI I'm pasting my code down below, also I'm calling an indicator (Gann HiLo Activator SSL) which I have downloaded from this website (https://www.mql5.com/en/code/8032) //+------------------------------------------------------------------+ //| My Strategy GannHiLo.mq4 | //| MJ | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "MJ" #property link "https://www.mql5.com" #property version "1.00" #property strict //+adding Gann HiLo -------------------- #property indicator_buffers 1 #property indicator_color1 Blue extern int Lb=10; double ssl[],Hld,Hlv,GannHiLo; #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexBuffer(0,ssl); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- for(int i=Bars-Lb;i>=0;i--) { if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1)) Hld=1; else { if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1)) Hld=-1; else Hld=0; } if(Hld!=0) Hlv=Hld; if(Hlv==-1) {ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1); GannHiLo=ssl[i];} else {ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1); GannHiLo=ssl[i];} } //---- return(0); } //+------------------------------------------------------------------+Adding Gann HiLo Ended here. //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ //int OnInit() //{ //--- //--- //return(INIT_SUCCEEDED); //} //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ //void OnDeinit(const int reason) // { //--- //} input double TakeProfit =10000; input double Lots =0.1; input double TrailingStop =0; input int MovingPeriod =10; input int MovingShift =0; input int MATrendPeriod =10; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnTick() { double MyTL; // double MaCurrent,MaPrevious; int cnt,ticket,total; //--- // initial data checks // it is important to make sure that the expert works with a normal // chart and the user did not make any mistakes setting external // variables (Lots, StopLoss, TakeProfit, // TrailingStop) in our case, we check TakeProfit // on a chart of less than 100 bars //--- if(Bars<100) { Print("bars less than 100"); return; } if(TakeProfit<10) { Print("TakeProfit less than 10"); return; } //--- to simplify the coding and speed up access data are put into internal variables //-------------------------------------------------------------------------- MyTL=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0)-iCustom(Symbol(),0,"Gann HiLo Activator SSL"); total=OrdersTotal(); if(total<1) { //--- no opened orders identified if(AccountFreeMargin()<(1000*Lots)) { Print("We have no money. Free Margin = ",AccountFreeMargin()); return; } //--- check for long position (BUY) possibility if(MyTL>0) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"My sample",16384,0,Green); //Ask+TakeProfit*Point if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print("Error opening BUY order : ",GetLastError()); return; } //--- check for short position (SELL) possibility if(MyTL<0 ) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"My sample",16384,0,Red); //Bid-TakeProfit*Point if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } else Print("Error opening SELL order : ",GetLastError()); } //--- exit from the "no opened orders" block return; } //--- it is important to enter the market correctly, but it is more important to exit it correctly... for(cnt=0;cnt<total;cnt++) { if(!OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderType()<=OP_SELL && // check for opened position OrderSymbol()==Symbol()) // check for symbol { //--- long position is opened if(OrderType()==OP_BUY) { //--- should it be closed? if(MyTL<0 ) { //--- close order and exit ticket=OrderModify(OrderTicket(),OrderOpenPrice(),0,MarketInfo(Symbol(),MODE_BID),0,Green); //TakeProfit==(MarketInfo(Symbol(),MODE_BID)-OrderOpenPrice()); if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet)) Print("OrderClose error ",GetLastError()); return; } //--- check for trailing stop if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { //--- modify order and exit if(!OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green)) Print("OrderModify error ",GetLastError()); return; } } } } else // go to short position { //--- should it be closed? if(MyTL>0) { //--- close order and exit ticket=OrderModify(OrderTicket(),OrderOpenPrice(),0,MarketInfo(Symbol(),MODE_ASK),0,Red); //TakeProfit==(MarketInfo(Symbol(),MODE_ASK)-OrderOpenPrice()); if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet)) Print("OrderClose error ",GetLastError()); return; } //--- check for trailing stop if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { //--- modify order and exit if(!OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red)) Print("OrderModify error ",GetLastError()); return; } } } } } } //--- } //+------------------------------------------------------------------+Your post is unreadable (illegible)
The iCustom is not correct, extern of the indicator are missing, so do the required buffer, and the shift,
have a look in the documentation
Play video
For large amounts of code, attach it.