Gamestudio Links
Zorro Links
Newest Posts
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
M1 Oversampling
by 11honza11. 04/30/24 08:16
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (lijoyi2011), 1,034 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Strategy, Algo not taking long trades? #433321
11/27/13 21:39
11/27/13 21:39
Joined: Apr 2013
Posts: 107
UK
G
Geek Offline OP
Member
Geek  Offline OP
Member
G

Joined: Apr 2013
Posts: 107
UK
I'm still in the learning phase but attempting to design / write a trading strategy for Gold using multiple algo's.

This below algo is causing me problems - it does not open any Long trades, and i think it should. I am not sure why this is??

The TimeFrame is a strange one but seems to work on backtest.

Any views as to the possible cause would be greatly appreciated.

Thanks..

Quote:
function Algo4() // Support/Resistance...
{

TimeFrame = 16;

Stop = 3.10*ATR(8);
Trail = 1.55*ATR(6);
//TrailStep = 3.43; // optimize(5,2,7) * ATR(47);
//TrailSlope = 5;
TakeProfit = 2.98*ATR(18);

vars Price = series(price());
var High = dayHigh(UTC,1);
var Low = dayLow(UTC,1);
var Pivot = dayPivot(UTC,1);
var *SM = series(SMA(Price,210));
var *SM1 = series(RSI(Price,7));
int Max = 1; // Max Trades

var S1 = 2*Pivot - High;
var S2 = Pivot - (High - Low);
var S3 = 2*Pivot - (2*High - Low);
var R1 = 2*Pivot - Low;
var R2 = Pivot + (High - Low);
var R3 = 2*Pivot + (High - 2*Low);

{
if (Price >= SM && NumOpenLong <1 && rising(SM1))

Entry =(R3-50*PIP);
reverseLong(Max);

if (Price <= SM && NumOpenShort <1 && falling(SM1))

Entry = (S3-50*PIP);
reverseShort(Max);

}
}

function run()
{
BarPeriod = 240;
set(PARAMETERS+FACTORS);
LookBack = 3500;
//StartDate 20120101;
//EndDate = 20130101;
//set(LOGFILE);
//Margin = 75;
set(MUTE);
//Capital = 1000;
//Margin = OptimalF * Capital * sqrt(5 + (WinTotal-LossTotal)/Capital);
// Lots = 1;
//Detrend = 8; // inverse curve
//NumWFOCycles = 5;
//DataSplit = 70;
//Hedge = 2;
{
while(asset(loop("XAU/USD")))

//while(algo(loop("Algo1","Algo2","Algo3")))
while(algo(loop("Algo4")))

// if(Algo == "Algo1")
//
// Algo1();
//
// else if (Algo == "Algo2")
//
// Algo2();
//
// else if (Algo == "Algo3")
//
// Algo3();

if (Algo == "Algo4")

Algo4();
}

PlotWidth = 800;
set(PLOTNOW);
}


Quote:

Percent winning 48%
Max win/loss 62$ / -42$
Avg trade profit 4.13$ 565.6p (+24$ / -14$)
Avg trade slippage -0.06$ -7.8p (+0.04$ / -0.16$)
Avg trade bars 26 (+34 / -18)
Max trade bars 108 (26 days)
Time in market 80%
Max open trades 2
Max loss streak 6 (uncorrelated 7)

Annual return 136%
Profit factor 1.57 (PRR 1.11)
Sharpe ratio 1.21
Kelly criterion 1.09
Ulcer index 14.1%
Prediction error 65%

Portfolio analysis OptF ProF Win/Loss Wgt%

Algo4 avg .013 1.57 33/36 100.0

XAU/USD:Algo4 .027 1.57 33/36 100.0
XAU/USD:Algo4:L .000 ---- 0/0 0.0
XAU/USD:Algo4:S .027 1.57 33/36 100.0


Last edited by Geek; 11/27/13 21:42.
Re: Strategy, Algo not taking long trades? [Re: Geek] #433342
11/28/13 10:56
11/28/13 10:56
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Look at your script. Have you placed all brackets correctly?

Re: Strategy, Algo not taking long trades? [Re: jcl] #433354
11/28/13 13:14
11/28/13 13:14
Joined: Apr 2013
Posts: 107
UK
G
Geek Offline OP
Member
Geek  Offline OP
Member
G

Joined: Apr 2013
Posts: 107
UK
Sorry, my code is a bit messy, but from what i can see is the below what needed correcting?

Although with this change it now doesn't take any trades...

Quote:

if (Price >= SM && NumOpenLong <1 && rising(SM1))
{
Entry =(R3-50*PIP);
reverseLong(Max);
}

else if (Price <= SM && NumOpenShort <1 && falling(SM1))
{

Entry = (S3-50*PIP);
reverseShort(Max);
}


- Edit, what would be ideal is a debugger that could pick up on all my mistakes (such as incorrect bracket placing) so i can learn from them instead of having to ask here all the time laugh

Last edited by Geek; 11/28/13 14:08.
Re: Strategy, Algo not taking long trades? [Re: Geek] #433428
11/29/13 14:04
11/29/13 14:04
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Your if-conditions are wrong. Can you find the bug? It's in the first of the three comparisons.

A debugger is indeed useful in some cases. You can find a debugger script under "Tips&Tricks". If you can't see the bug at once, use the debugger for observing the values used for the if-conditions.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1