Tester stopped because OnInit returns non-zero code 1 - page 2

 
Keith Watford #:

No braces mean that init will always fail!

It should be

I was thinking of trying it this way 

   CCI=new CiCCI();      
   if(CheckPointer(CCI)==POINTER_INVALID || !CCI.Create(Symb.Name(),TimeFrame,CCIPeriod,CCIPrice))
      return INIT_FAILED;

I'll try it your way as well

 
Keith Watford #:

No braces mean that init will always fail!

It should be

Using your method i was able to identify the problem

   float temp1, temp2;
   if(!StudyNet.Load(FileName + ".nnw", dError, temp1, temp2, dtStudied, true)){
      printf("STUDYNET FILE ");
      return INIT_FAILED;}

Now all thats left is to solve it.

Thank you everybody 

 
Keith Watford #:

No braces mean that init will always fail!

It should be

Of course.

A simple case of Inattentional Blindness! I'll pay more attention next time.

 
//+------------------------------------------------------------------+
//|                                                    My Trading EA |
//|                        Copyright 2023, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.0"
#property strict

// Input parameters
input int leverage = 20;
input double stopLoss = 0.01;
input double entryLotSize = 10;

// ZigZag indicator settings
input int zigzagDepth = 12;
input int zigzagDeviation = 5;
input int zigzagBackstep = 3;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
    // Set the leverage
    double leverageRatio = 1.0 / leverage;
    if (!AccountSetLeverage(leverageRatio))
    {
        Print("Failed to set leverage to ", leverage);
        return INIT_FAILED;
    }

    return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
    // Only execute on bar close
    if (TimeCurrent() != Time[0])
    {
        return;
    }

    // Check if there is already an open position
    int positionType = PositionsTotal() == 0 ? 0 : PositionGetInteger(POSITION_TYPE);
    if (positionType != 0)
    {
        // If there is an open position, check if it should be closed
        double positionProfit = PositionGetDouble(POSITION_PROFIT);
        double positionStopLoss = PositionGetDouble(POSITION_SL);
        double positionTakeProfit = PositionGetDouble(POSITION_TP);

        double zigzagHigh = iCustom(_Symbol, PERIOD_H4, "ZigZag", zigzagDepth, zigzagDeviation, zigzagBackstep, 0, 1);
        double zigzagLow = iCustom(_Symbol, PERIOD_H4, "ZigZag", zigzagDepth, zigzagDeviation, zigzagBackstep, 1, 1);

        bool shouldClosePosition = false;
        if (positionType == POSITION_TYPE_BUY)
        {
            if (zigzagLow > 0)
            {
                shouldClosePosition = true;
            }
            else if (positionStopLoss > 0 && Bid < positionStopLoss)
            {
                shouldClosePosition = true;
            }
            else if (positionTakeProfit > 0 && Bid > positionTakeProfit)
            {
                shouldClosePosition = true;
            }
        }
        else if (positionType == POSITION_TYPE_SELL)
        {
            if (zigzagHigh > 0)
            {
                shouldClosePosition = true;
            }
            else if (positionStopLoss > 0 && Ask > positionStopLoss)
            {
                shouldClosePosition = true;
            }
            else if (positionTakeProfit > 0 && Ask < positionTakeProfit)
            {
                shouldClosePosition = true;
            }
        }

        if (shouldClosePosition)
        {
            OrderClose(PositionGetTicket(), PositionGetDouble(POSITION_VOLUME), Bid, 5, White);
            return;
        }

        return;
    }

    // If there is no open position,// Check for a new entry signal
    double zigzagHigh = iCustom(_Symbol, PERIOD_H4, "ZigZag", zigzagDepth, zigzagDeviation, zigzagBackstep, 0, 1);
    double zigzagLow = iCustom(_Symbol, PERIOD_H4, "ZigZag", zigzagDepth, zigzagDeviation, zigzagBackstep, 1, 1);

    if (zigzagHigh > 0)
    {
        // Open a sell position
        double entryPrice = Bid;
        double stopLossPrice = entryPrice + stopLoss * entryPrice;
        double takeProfitPrice = zigzagHigh;

        int ticket = OrderSend(_Symbol, OP_SELL, entryLotSize, entryPrice, 5, stopLossPrice, takeProfitPrice, "My Trading EA", 0, 0, Red);
        if (ticket < 0)
        {
            Print("Failed to open a sell position: ", GetLastError());
        }
    }
    else if (zigzagLow > 0)
    {
        // Open a buy position
        double entryPrice = Ask;
        double stopLossPrice = entryPrice - stopLoss * entryPrice;
        double takeProfitPrice = zigzagLow;

        int ticket = OrderSend(_Symbol, OP_BUY, entryLotSize, entryPrice, 5, stopLossPrice, takeProfitPrice, "My Trading EA", 0, 0, Green);
        if (ticket < 0)
        {
            Print("Failed to open a buy position: ", GetLastError());
        }
    }
} 
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.04.17
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 

error   (!AccountSetLeverage(leverageRatio))

 
Mohammad Tajvidi #:

error   (!AccountSetLeverage(leverageRatio))

I fail to understand what is it you trying to achieve 
 

Please test the following code in MetaTrader 5, it gives me an error

 
Kekeletso Mofokeng #:
I fail to understand what is it you trying to achieve 

Please test the following code in MetaTrader 5, it gives me an error

 
Mohammad Tajvidi #:

Please test the following code in MetaTrader 5, it gives me an error

I'll get back to you once I've tested it 
 
Kekeletso Mofokeng #:
I'll get back to you once I've tested it 

Thank you