Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, dr_panther), 1,211 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Trading several assets with grid algo #436185
01/21/14 11:28
01/21/14 11:28
Joined: Jul 2013
Posts: 110
B
bfleming Offline OP
Member
bfleming  Offline OP
Member
B

Joined: Jul 2013
Posts: 110
I'm trying to adapt the grid algo to trade several assets and have tried looping the assets and calling the assets, but can't get it to work. This is the standard grid algo:

Code:
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();

  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);
  }
}



How do I get it to trade several assets?

Also, is it possible to set a grid entry or stop loss or take profit as a % of current price? If so, how?

Thanks for the help!!

Re: Trading several assets with grid algo [Re: bfleming] #436219
01/21/14 18:37
01/21/14 18:37
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
For several assets you can use a loop function as in workshop 6. All asset dependent code, such as the "var Current" line and probably also the grid size, must be inside the loop.

Also, the "findTrade" function now must compare the asset, too. F.i. with strstr(Asset,TradeAsset).

Setting the grid entry/exit lines dependent on a percentage of the price would produce a variable grid, not a fixed grid. In our Z4/Z5 tests a fixed grid was more profitable than a variable grid.

Re: Trading several assets with grid algo [Re: jcl] #436243
01/22/14 08:00
01/22/14 08:00
Joined: Jul 2013
Posts: 110
B
bfleming Offline OP
Member
bfleming  Offline OP
Member
B

Joined: Jul 2013
Posts: 110
Ok, so I have this code now, but I don't have the "findTrade" function comparing the asset yet:

Code:
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 tradeGrid ()
{
  var Price;
  var Grid = 100*PIP;
  var Current = priceClose();
  EntryTime = ExitTime = 500; 

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);
  }
 
function run() 
{
  BarPeriod = 1440;
  Hedge = 2; 

while(asset(loop("SPX500","US30")))
while(algo(loop("GRD")))
  {
    if(Algo == "GRD") 
      tradeGrid();
  }
}



What's the code for the "findTrade" function to compare the asset? I can't figure that out.
Does the "findTrade" function stay where it is?

Regarding grid as percent of price, a variable grid is exactly what I want. I've played around with grids based on ATR, which suits my purposes, but I want to play around with variable grids based on percent of price as I'm looking at this as more of an investment tool to trade indexes. If it's possible, how would I set the grid based on percent of price?

Many thanks!

Re: Trading several assets with grid algo [Re: bfleming] #436248
01/22/14 10:33
01/22/14 10:33
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
For comparing the asset:

Code:
if((TradeIsShort == IsShort)
      and strstr(TradeAsset,Asset)
      and between(TradeEntryLimit,Price-Grid/2,Price+Grid/2))
...



and the 'Algo' comparison and second while loop is not needed when you have only one algo.

For a variable grid, you could for instance set the grid distance to 0.1% of price(), or better, to a multiple of ATR().

Re: Trading several assets with grid algo [Re: jcl] #436252
01/22/14 11:21
01/22/14 11:21
Joined: Jul 2013
Posts: 110
B
bfleming Offline OP
Member
bfleming  Offline OP
Member
B

Joined: Jul 2013
Posts: 110
Many thanks!! Am slowly getting incrementally better at this coding business, but it's slow going.

Will play around with this.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1