2 registered members (AndrewAMD, 7th_zorro),
1,285
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Trading several assets with grid algo
#436185
01/21/14 11:28
01/21/14 11:28
|
Joined: Jul 2013
Posts: 110
bfleming
OP
Member
|
OP
Member
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:
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: jcl]
#436243
01/22/14 08:00
01/22/14 08:00
|
Joined: Jul 2013
Posts: 110
bfleming
OP
Member
|
OP
Member
Joined: Jul 2013
Posts: 110
|
Ok, so I have this code now, but I don't have the "findTrade" function comparing the asset yet:
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!
|
|
|
|