Gamestudio Links
Zorro Links
Newest Posts
FXCM => AVA Trade Plugin???
by Martin_HH. 11/23/26 20:38
No connection to MT4
by Martin_HH. 11/23/26 06:38
MinMax function on History t6 file
by LucasJoshua. 11/21/26 14:28
What are you working on?
by rayp. 11/20/26 18:10
contractUpdate() is filtering if >2 rows
by mistery. 11/09/26 12:06
New Zorro version 3.15
by jcl. 11/09/26 09:24
Removing outliers from files
by jcl. 11/04/26 10:30
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (EW_bytes, Martin_HH), 15,149 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EvanTJ, rht, MaliceTheMaker, Haitao_Ren, JimSimons
19250 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Trade loop recursion #483032
04/25/21 17:05
04/25/21 17:05
Joined: Dec 2020
Posts: 27
Italy
D
dpn Offline OP
Newbie
dpn  Offline OP
Newbie
D

Joined: Dec 2020
Posts: 27
Italy
Hello,

I'm trying to test the "grid trading" script from the online manual, on chapter "Tips & Tricks", but its output is "Warning 048 : trade loop recursion";
Someone can help me to find the faulty action?

(Note: ExitTime is no more valid so I changed it in LifeTime)

Thanks


Code
// helper function for finding trades at a grid line
bool findTrade(var Price,var Grid,bool IsShort) 
{
  for(open_trades)
    if((TradeIsShort == IsShort)
      and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2))
        return true;
  return false;
}
  
function run() 
{
  BarPeriod = 1440;
  Hedge = 2; 
  EntryTime = ExitTime = 500;  
  var Price;
  var Grid = 100*PIP; // grid spacing
  var Current = priceClose();
// place pending trades at 5 grid lines  
// above and below the current price
  for(Price = 0; Price < Current+5*Grid; Price += Grid) {
    if(Price < Current-5*Grid)
      continue;
    if(Price < Current and !findTrade(Price,Grid,true))
      enterShort(0,Price,0,Grid);      
    else if(Price > Current and !findTrade(Price,Grid,false))
      enterLong(0,Price,0,Grid);
  }
}

Re: Trade loop recursion [Re: dpn] #483033
04/25/21 18:04
04/25/21 18:04
Joined: Feb 2017
Posts: 1,839
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,839
Chicago
One should never prematurely exit a for(open_trades) loop prematurely without using the break_trades macro. Otherwise, you will see lots of strange side effects that will ruin your trading algorithm.

So basically, the function needs to be re-written. Something like this (untested):
Code
bool findTrade(var Price,var Grid,bool IsShort) 
{
  bool out = false;
  for(open_trades)
    if((TradeIsShort == IsShort)
      and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2)){
        out = true;
        break_trades;
      }
  return out;
}

Last edited by AndrewAMD; 04/25/21 18:40. Reason: rev1 - fixed code
Re: Trade loop recursion [Re: AndrewAMD] #483034
04/25/21 19:03
04/25/21 19:03
Joined: Dec 2020
Posts: 27
Italy
D
dpn Offline OP
Newbie
dpn  Offline OP
Newbie
D

Joined: Dec 2020
Posts: 27
Italy
Thank you AndrewAMD for the prompt response;

I've re-tested the script with your suggestions and it runs correctly (Great!!);

thank you very much for the help;

Ciao


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1