"array out of range" error #zohair - page 2

 
Joseph Kachimba # :

The download above has 96 lines see below

***

Align the indexes:

   if(prev_calculated==0)
     {
      ExtMapBuffer1[0]=0.0;
      ExtMapBuffer2[0]=0.0;
      ExtMapBuffer1[1]=0.0;
      ExtMapBuffer2[1]=0.0;
      limit=2;
     }

Version 1.001

Files:
 
Vladimir Karputov #:

Align the indexes:

Version 1.001

Thank you very much

 
Joseph Kachimba #:

Thank you very much

//+------------------------------------------------------------------+
//|                                                SmartScalp EA.mq5 |
//|                             Copyright 2022, Smart Invest Zambia. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, Smart Invest Zambia."
#property link      "https://www.mql5.com"
#property version   "1.00"
#include <Trade/Trade.mqh>
//+------------------------------------------------------------------+
input double    Lot              =0.01;          //
input int       Step             =1; 
input double    UpLot            =1.1;
input double    TP_Valuta        =2;
input string    t1               ="=== Indicators ===";
input int       Otstup           =1;         //Signal offset from the top of the bar
input int       CountBars        =2000;      //The number of bars on which the signal will be displayed   
input double    Exponenta     =1;
input int       BarShift         =0;
input int       Magic            =2017; 
//+------------------------------------------------------------------+
CTrade trade;
ulong posTicket;

string comment ="SmartInvest";
int r, D;
datetime NewBar =0;
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
     D=1;
     if (Digits()==5 || Digits()==3)D=10;

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick(){
   
     if(NewBar!= iTime(Symbol(),0,0) ) 
        NewBar = iTime(Symbol(),0,0) ;
//+------------------------------------------------------------------+
if(NewBar!= iTime(Symbol(),0,0) ) 
{NewBar = iTime(Symbol(),0,0) ;
//+------------------------------------------------------------------+
bool Sell=false; bool Buy=false;
if(iCustom(Symbol(),0,"ScalpBar",Otstup,CountBars,Exponenta,0,BarShift)!=0) {Sell=true;}
if(iCustom(Symbol(),0,"ScalpBar",Otstup,CountBars,Exponenta,1,BarShift)!=0) {Buy=true;}
//+------------------------------------------------------------------+
if(Count(-1)==0 && Sell)
  {r=OrderSend(Symbol(),OP_SELL,Lot,Bid,10,0,0,comment,Magic,0,Red);}
if(Count(-1)==0 && Buy)
  {r=OrderSend(Symbol(),OP_BUY,Lot,Ask,10,0,0,comment,Magic,0,Green);}
  }
//+------------------------------------------------------------------+
double NewLot=Lot*(MathPow(UpLot,Count(-1)));

if(Count(OP_BUY)>0 &&  Ask+Step*Point<=BuyPric())
   {r=OrderSend(Symbol(),OP_BUY,NewLot,Ask,10,0,0,comment,Magic,0,Green);}  
if(Count(OP_SELL)>0 &&  Bid-Step*Point>=SellPric())
   {r=OrderSend(Symbol(),OP_SELL,NewLot,Bid,10,0,0,comment,Magic,0,Red);} 
//+------------------------------------------------------------------+
if(Profit(-1)>=TP_Valuta && Count(-1)>0)
  {CloseSell();
  CloseBuy();}
//+------------------------------------------------------------------+
}
//+------------------------------------------------------------------+ 
//|Counting the number of orders by type                               | 
//+------------------------------------------------------------------+
      int Count(int type)
      {int count=0;
       for(int i=OrdersTotal()-1;i>=0;i--)
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {if(Symbol()==OrderSymbol() && Magic==OrderMagicNumber() && (type==-1 || OrderType()==type)) count++;}
         return(count);}
      
      int CountH(int type)
      {int count=0;
       for(int i=OrdersTotal()-1;i>=0;i--)
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {if(Symbol()==OrderSymbol() && Magic==OrderMagicNumber() && OrderOpenTime()>=iTime(Symbol(),0,0) && (type==-1 || OrderType()==type)) count++;}
         return(count);}
//+------------------------------------------------------------------+ 
//| Function of closing orders                                         |
//+------------------------------------------------------------------+
void CloseBuy()
      {double priceB;
      for(int i=OrdersTotal()-1;i>=0;i--)
      {if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {if(Symbol()==OrderSymbol() && OrderType()==OP_BUY && Magic==OrderMagicNumber())
      {priceB=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID), Digits);
      bool clos=OrderClose(OrderTicket(),OrderLots(),priceB,100,0);}}}
      return;}
//+------------------------------------------------------------------+
void CloseSell()
      {double priceS;
      for(int i=OrdersTotal()-1;i>=0;i--)
      {if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {if(Symbol()==OrderSymbol() && OrderType()==OP_SELL && Magic==OrderMagicNumber())
      {priceS=NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK), Digits);
      bool clos=OrderClose(OrderTicket(),OrderLots(),priceS,100,0);}}}
      return;}
//----------We count the number of passed points by buy----------------+
double BuyPric() {
      double oldorderopenprice;
      int oldticketnumber;
      double unused = 0;
      bool clos;
      int ticketnumber = 0;
      for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
         clos=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY) {
            oldticketnumber = OrderTicket();
            if (oldticketnumber > ticketnumber) {
               oldorderopenprice = OrderOpenPrice();
               unused = oldorderopenprice;
               ticketnumber = oldticketnumber;}}}
      return (oldorderopenprice);}
//----------We count the number of passed points by sell---------------+
double SellPric() {
         double oldorderopenprice;
         int oldticketnumber;
         double unused = 0;
         bool clos;
         int ticketnumber = 0;
         for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
            clos=OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magic) continue;
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL) {
               oldticketnumber = OrderTicket();
               if (oldticketnumber > ticketnumber) {
                  oldorderopenprice = OrderOpenPrice();
                  unused = oldorderopenprice;
                  ticketnumber = oldticketnumber;}}}
         return (oldorderopenprice);}
//--------------------------------------------------------------------+
double Profit(int type) 
      {double Profit = 0;
         for (int cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {
            if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
            {if (OrderMagicNumber()==Magic && (OrderType() == type || type==-1)) Profit += OrderProfit()+OrderSwap()+OrderCommission();}}
             return (Profit);} }

This the code am working on for the indicator you helped fixing the martingale is what i want 

 
Joseph Kachimba #:

This the code am working on for the indicator you helped fixing the martingale is what i want 

Throw away all 'OrderSend' and never remember again. Use m_trade.Buy(... and m_trade(Sell...).

Link to documentation:

Buy

Opens a long position with specified parameters

Sell

Opens a short position with specified parameters


Throw away all functions: 'Count(int type)', 'CloseBuy()', 'CloseSell()', 'BuyPric()', 'SellPric()' and 'Profit(int type') - these functions have nothing to do to MQL5.

Show the result.

Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
  • www.mql5.com
Buy(double,const string,double,double,double,const string) - CTrade - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5