• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 3:57pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 3:57pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Print Thread

Similar Threads

How to code an EA that's only available on strategy tester? 3 replies

Strategy Tester stops with green bar at about 40% 4 replies

Debug code in strategy tester 1 reply

Strategy Tester not running at full speed. 8 replies

2009.03.11 15:41:15Tester memory handler: tester stopped because not enough memory 19 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe

Strategy tester just stops when running this code and idk why

  • Post #1
  • Quote
  • First Post: Aug 13, 2018 6:31am Aug 13, 2018 6:31am
  •  AntiVi
  • | Joined Dec 2015 | Status: Member | 277 Posts
Hey guys,

I have this code that I wrote and in my mind it works perfectly however my mind seems to be wrong and it doesn't know why.
So I tracked the issue to a specific part but I still have no idea what is causing it to fail.
There are no errors of any significance either.

Here is the part where it seems to fail at:
Inserted Code
      if(Trades[7,RowNumber2] == 1)
        {
         if(Ask <= Trades[2,RowNumber2] && Trades[6,RowNumber] == 0)
           {
            int Ticket = OrderSend(Symbol(), OP_SELL, Lots, Ask, Slippage, Trades[4,RowNumber2], 0, NULL, Trades[1,RowNumber], 0, Blue);
            Trades[6,RowNumber] = 1;
            //Print("---MagicNumber = ", MagicNumber, "---");
            
            ArrayCounter2 = 0;
            RowNumber2 = 0;
           }
        }
      else
        {
         ArrayCounter2 = ArrayCounter2 + 1;
         RowNumber2 = RowNumber2 + 1;
        }

Here is the full code:
Inserted Code
//+------------------------------------------------------------------+
//|                                                          FTB.mq4 |
//|                                                           AntiVi |
//|                                             https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "AntiVi"
#property strict
extern int     MagicNumber       = 10001;
extern double  Lots              = 0.1;
extern double  TrailingStop      = 0;
extern int     Slippage          = 3;
extern double  EntryGap          = 0.00500;
extern int     BrokerDigits      = 5;
extern int     AllowableDrawdown = 25;
extern int     MaxDrawdown       = 610;
extern bool    MoneyManagement   = false;
double Entry;
double StopLoss;
double TakeProfit;
double HalfCandleSize;
double Middle;
double OpenCheck;
double CloseCheck;
double Trades [8][20]; //ArrayNumber | MagicNumber | Entry | Stoploss | WaitCounter | ExpirationTime | Entered | Populated
int SignalTime;
int BarsOnChart = Bars;
int IsNewCandle;
int OrderError = 0;
int RowNumber = 0;
int RowNumber2 = 0;
int ArrayCounter = 0;
int ArrayCounter2 = 0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Trades[0,0]  = 1;  Trades[0,1]  = 2;  Trades[0,2]  = 3;  Trades[0,3]  = 4;  Trades[0,4]  = 5;
   Trades[0,5]  = 6;  Trades[0,6]  = 7;  Trades[0,7]  = 8;  Trades[0,8]  = 9;  Trades[0,9]  = 10;
   Trades[0,10] = 11; Trades[0,11] = 12; Trades[0,12] = 13; Trades[0,13] = 14; Trades[0,14] = 15;
   Trades[0,15] = 16; Trades[0,16] = 17; Trades[0,17] = 18; Trades[0,18] = 19; Trades[0,19] = 20;
   
   Print("-----------");
   Print("ArrayNumber = ",    Trades[0,RowNumber]);
   Print("MagicNumber = ",    Trades[1,RowNumber]);
   Print("Entry = ",          Trades[2,RowNumber]);
   Print("Stoploss = ",       Trades[3,RowNumber]);
   Print("WaitCounter = ",    Trades[4,RowNumber]);
   Print("ExpirationTime = ", Trades[5,RowNumber]);
   Print("Entered = ",        Trades[6,RowNumber]);
   Print("Populated = ",      Trades[7,RowNumber]);
   Print("-----------");
   
   return(INIT_SUCCEEDED);
  }
 
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   
  }
 
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(BarsOnChart != Bars) //Checking for new closed candles
     {
      BarsOnChart = Bars;
      IsNewCandle = 1;
     }
   else
     {
      IsNewCandle = 0;
     }
     if(IsNewCandle == 1) //Checking if a new candle has closed
       {
        SignalTime = Hour() - 1;
       
        if((SignalTime > 8) && (SignalTime < 14) && (High[1] > High[2])) //Check to see if signal candle has a higher high than the candle before and is within the timeframe
           {
            
            HalfCandleSize = (High[1] - Low[1]) / 2; //Calculates half of the candle size
            Middle = Low[1] + HalfCandleSize; //Calculates the middle of the candle
            OpenCheck = Middle - Open[1]; //Calculates distance between open and middle
            CloseCheck = Middle - Close[1]; //Calculates distance between close and middle
                 
           if(OpenCheck > 0 && CloseCheck > 0) //checks to see if candle closes in lower half
              {
               Entry = NormalizeDouble(Low[1] - 0.0001, 5); //Reason for OrderSend Error 130 is that the Entry Entry is too close to Current Market Entry
               StopLoss = NormalizeDouble(High[1] + 0.0005, 5);
               
               while(ArrayCounter < 20)
                    {
                     if(Trades[7,RowNumber] == 0)
                       {
                        Trades[1,RowNumber] = MagicNumber;
                        Trades[2,RowNumber] = Entry;
                        Trades[3,RowNumber] = StopLoss;
                        Trades[4,RowNumber] = 0;
                        Trades[5,RowNumber] = 0;
                        Trades[6,RowNumber] = 0;
                        Trades[7,RowNumber] = 1;
                        MagicNumber = MagicNumber + 1;
                        
                           Print("-----------");
                           Print("ArrayNumber = ",    Trades[0,RowNumber]);
                           Print("MagicNumber = ",    Trades[1,RowNumber]);
                           Print("Entry = ",          Trades[2,RowNumber]);
                           Print("Stoploss = ",       Trades[3,RowNumber]);
                           Print("WaitCounter = ",    Trades[4,RowNumber]);
                           Print("ExpirationTime = ", Trades[5,RowNumber]);
                           Print("Entered = ",        Trades[6,RowNumber]);
                           Print("Populated = ",      Trades[7,RowNumber]);
                           Print("-----------");
                        
                        break;
                       }
                     else
                       {
                        ArrayCounter = ArrayCounter + 1;
                        RowNumber = RowNumber + 1;
                       }
                    }
                    
               ArrayCounter = 0;
               RowNumber = 0;
              }
           }
       }
       
   while(ArrayCounter2 < 20)
     {
      if(Trades[7,RowNumber2] == 1)
        {
         if(Ask <= Trades[2,RowNumber2] && Trades[6,RowNumber] == 0)
           {
            int Ticket = OrderSend(Symbol(), OP_SELL, Lots, Ask, Slippage, Trades[4,RowNumber2], 0, NULL, Trades[1,RowNumber], 0, Blue);
            Trades[6,RowNumber] = 1;
            //Print("---MagicNumber = ", MagicNumber, "---");
            
            ArrayCounter2 = 0;
            RowNumber2 = 0;
           }
        }
      else
        {
         ArrayCounter2 = ArrayCounter2 + 1;
         RowNumber2 = RowNumber2 + 1;
        }
     }
   if(ArrayCounter2 == 20)
     {
      ArrayCounter2 = 0;
      RowNumber2 = 0;
     }  
  }


If you guys could give me your wisdom that'd be much appreciated.
Thanks!
  • Post #2
  • Quote
  • Aug 13, 2018 6:36am Aug 13, 2018 6:36am
  •  braintheboss
  • Joined Nov 2012 | Status: Coder | 8,507 Posts
Quoting AntiVi
Disliked
Hey guys, I have this code that I wrote and in my mind it works perfectly however my mind seems to be wrong and it doesn't know why. So I tracked the issue to a specific part but I still have no idea what is causing it to fail. There are no errors of any significance either. Here is the part where it seems to fail at: if(Trades[7,RowNumber2] == 1) { if(Ask <= Trades[2,RowNumber2] && Trades[6,RowNumber] == 0) { int Ticket = OrderSend(Symbol(), OP_SELL, Lots, Ask, Slippage, Trades[4,RowNumber2], 0, NULL, Trades[1,RowNumber], 0, Blue); Trades[6,RowNumber]...
Ignored
Backtester cant run code like terminal. Then its normal a code works in terminal fails in backtester
Try don't lose pants never...
 
 
  • Post #3
  • Quote
  • Aug 13, 2018 6:38am Aug 13, 2018 6:38am
  •  AntiVi
  • | Joined Dec 2015 | Status: Member | 277 Posts
Quoting braintheboss
Disliked
{quote} Backtester cant run code like terminal. Then its normal a code works in terminal fails in backtester
Ignored
What would make this fail in the tester though?
I haven't tested this on actual live charts.
 
 
  • Post #4
  • Quote
  • Aug 13, 2018 8:00am Aug 13, 2018 8:00am
  •  braintheboss
  • Joined Nov 2012 | Status: Coder | 8,507 Posts
Quoting AntiVi
Disliked
{quote} What would make this fail in the tester though? I haven't tested this on actual live charts.
Ignored
If you didnt test the code how you know works really? You check it in live charts and when you see works try it in backtester. Simple codes should run but if you use complex code its common not run in backtester without big code adaptations.

Anyways its a waste of time try something in MT4 backtester. If you want use backtester should go to MT5. That backtester is able to run code like terminal without any modification and even debug it
Try don't lose pants never...
 
 
  • Post #5
  • Quote
  • Edited at 11:39am Aug 13, 2018 10:17am | Edited at 11:39am
  •  Nicholishen
  • Joined Jul 2005 | Status: zzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzz | 1,289 Posts
Lesson to learn: don't ever omit the "strict" directive. Uncomment it, fix your code, and more than likely you will have fixed your issue.

My bad, I just came from coding a bunch of python where "#" is how you comment a line... I didn't think the deprecated syntax array[i,j] would even compile using the strict directive. TIL.
 
 
  • Post #6
  • Quote
  • Aug 13, 2018 11:46am Aug 13, 2018 11:46am
  •  AntiVi
  • | Joined Dec 2015 | Status: Member | 277 Posts
Quoting braintheboss
Disliked
{quote} If you didnt test the code how you know works really? You check it in live charts and when you see works try it in backtester. Simple codes should run but if you use complex code its common not run in backtester without big code adaptations. Anyways its a waste of time try something in MT4 backtester. If you want use backtester should go to MT5. That backtester is able to run code like terminal without any modification and even debug it
Ignored
There is a big flaw with testing code on a live chart. It takes time... a lot of time. I could not have a signal for this for a month or more which isn't viable at all.
Plus it's a strategy only traded during certain times of the day.
On top of that if I want to backtest it I'll have to use the strategy tester anyway.

There must be an issue in the code somewhere that won't let it continue but I can't seem to find it.
I get what you're saying about MT5 however currently everything I run is still on MT4.
Switching over isn't as easy as just downloading it.


Quoting Nicholishen
Disliked
Lesson to learn: don't ever omit the "strict" directive. Uncomment it, fix your code, and more than likely you will have fixed your issue. My bad, I just came from coding a bunch of python where "#" is how you comment a line... I didn't think the deprecated syntax array[i,j] would even compile using the strict directive. TIL.
Ignored
Hehe it's all good. I did try removing it and it only prevents errors from appearing (Like data type conversion ending up in possible loss which it won't do in this code). Still the same issue though.
 
 
  • Post #7
  • Quote
  • Edited at 12:40pm Aug 13, 2018 12:00pm | Edited at 12:40pm
  •  Nicholishen
  • Joined Jul 2005 | Status: zzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzz | 1,289 Posts
Quoting AntiVi
Disliked
{quote} There is a big flaw with testing code on a live chart. It takes time... a lot of time. I could not have a signal for this for a month or more which isn't viable at all. Plus it's a strategy only traded during certain times of the day. On top of that if I want to backtest it I'll have to use the strategy tester anyway. There must be an issue in the code somewhere that won't let it continue but I can't seem to find it. I get what you're saying about MT5 however currently everything I run is still on MT4. Switching over isn't as easy as just...
Ignored
So I just wanted to point out a few things that will help your code moving forward. It might help looking at some C++ style guides and use common development conventions. Your code is very hard to read because you don't follow them. For example, there is an entire code-block that isn't indented, you're using CamelCase for variable names when that style is typically only used for classes, and you're also using integers instead in place of boolean types.

Additionally, you're using multi-dimensional arrays wrong. You only need to use them for linear algebra, everything else you need to be using structs or objects. For example you have
Inserted Code
Trades[1,RowNumber] = MagicNumber

  1. This is impossible to make sense of
  2. Magic numbers are integer type not double

 
 
  • Post #8
  • Quote
  • Last Post: Aug 15, 2018 7:19am Aug 15, 2018 7:19am
  •  AntiVi
  • | Joined Dec 2015 | Status: Member | 277 Posts
Quoting Nicholishen
Disliked
{quote} So I just wanted to point out a few things that will help your code moving forward. It might help looking at some C++ style guides and use common development conventions. Your code is very hard to read because you don't follow them. For example, there is an entire code-block that isn't indented, you're using CamelCase for variable names when that style is typically only used for classes, and you're also using integers instead in place of boolean types. Additionally, you're using multi-dimensional arrays wrong. You only need to use them for...
Ignored
I understand what you're saying. I'm pretty much self taught by playing around with code and never really had any sort of class or proper structure while learning it. It would probably be best to look into more conventional coding practices.

Now regardless of that everything did still work and I did end up finding the issue thanks to a hint someone gave me and I found an infinite loop and resolved it.


Thanks for the help!
 
 
  • Platform Tech
  • /
  • Strategy tester just stops when running this code and idk why
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2022