3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
query past values
#475089
11/22/18 16:59
11/22/18 16:59
|
Joined: Jun 2018
Posts: 16
Paul_der_Zweite
OP
Newbie
|
OP
Newbie
Joined: Jun 2018
Posts: 16
|
Sorry i'm a newbie ... I have a small problem, which is probably very easy to solve: How can I query past values, here the indicator value KAMA from before n candles correctly and then use it again? My state of knowledge: I define a series (here: vars kama = KAMA(Price,10) and can then address a certain point in time n (shift or candles in the past) with series[n] (here: kama[n]). The following part of my script:
vars Price = series(priceClose());
vars kama = KAMA(Price,10);
var close_kama(int n)
{
return kama[n] / priceClose(n);
}
vars cycle = DominantPeriod(Price,100);
var cycle_multi = 2;
var close_res(int n)
{
return priceClose(n) / HH(cycle[n]*cycle_multi,n+1);
}
var close_sup(int n)
{
return priceClose(n) / LL(cycle[n]*cycle_multi,1);
}
causes the following error:
Error 111: Crash in function: close_kama() at bar 0
What am I doing wrong? Everything?
|
|
|
Re: query past values
[Re: Dalla]
#475091
11/22/18 18:51
11/22/18 18:51
|
Joined: Jun 2018
Posts: 16
Paul_der_Zweite
OP
Newbie
|
OP
Newbie
Joined: Jun 2018
Posts: 16
|
Hi, thank you so much for your answer: I changed the script as follows:
vars Price = series(priceClose());
vars kama = series(KAMA(Price,10));
var close_kama(int n)
{
return kama[n] / priceClose(n);
}
vars cycle = series(DominantPeriod(Price,100));
var cycle_multi = 2;
var close_res(int n)
{
return priceClose(n) / HH(cycle[n]*cycle_multi,n+1);
}
var close_sup(int n)
{
return priceClose(n) / LL(cycle[n]*cycle_multi,n+1);
}
But the error output remains the same.
Last edited by Paul_der_Zweite; 11/22/18 18:52.
|
|
|
Re: query past values
[Re: Dalla]
#475095
11/22/18 23:14
11/22/18 23:14
|
Joined: Jun 2018
Posts: 16
Paul_der_Zweite
OP
Newbie
|
OP
Newbie
Joined: Jun 2018
Posts: 16
|
Sure, here's the whole script:
#include <r.h>
vars Price = series(priceClose());
vars kama = series(KAMA(Price,10));
var close_kama(int n)
{
return kama[n] / priceClose(n);
}
vars cycle = series(DominantPeriod(Price,100));
var cycle_multi = 2;
var close_res(int n)
{
return priceClose(n) / HH(cycle[n]*cycle_multi,n+1);
}
var close_sup(int n)
{
return priceClose(n) / LL(cycle[n]*cycle_multi,n+1);
}
///////////////////////////////////////////////////////////////////////
function run()
{
StartDate = 20160101;
BarPeriod = 120;
LookBack = 100;
WFOPeriod = 22*288;
DataSplit = 90;
NumCores = -1;
if(is(TRADEMODE|TESTMODE))
Hedge = 5;
else
Hedge = 2; // full hedging in train mode
set(RULES|LOGFILE|TESTNOW|PLOTNOW);
//set(PARAMETERS|LOGFILE|TESTNOW|PLOTNOW);
//LifeTime = 140;
//Capital = 1000; // reinvestment mode
//Margin = 0.01 * OptimalF * Capital * sqrt(1 + ProfitClosed/Capital);
//Stop = MedPrice(1) + 3 * ATR(14);
//TakeProfit = 3 * ATR(14);
//TrailStep = 3 * ATR(14);
//Trail = ATR(14);
//TrailLock = 80;
///////////////////////////////////////////////////////////
if(adviseLong(NEURAL,0,
close_kama(1),close_kama(2),close_kama(3),close_kama(4),
close_res(1),close_res(2),close_res(3),close_res(4),
close_sup(1),close_sup(2),close_sup(3),close_sup(4)) > 0.5)
enterLong();
if(adviseShort() > 0.5)
enterShort();
PlotWidth = 800;
PlotHeight1 = 340;
ColorUp = ColorDn = ColorWin = ColorLoss = 0;
}
|
|
|
Re: query past values
[Re: Dalla]
#475145
11/25/18 17:34
11/25/18 17:34
|
Joined: Jun 2018
Posts: 16
Paul_der_Zweite
OP
Newbie
|
OP
Newbie
Joined: Jun 2018
Posts: 16
|
Mmh, the basic idea of the script or the basic structure comes from financial-hacker.com. The original script can be downloaded there [x] and looks like this:
///////////////////////////////////////////////////////////////////////
#include <r.h>
var change(int n)
{
return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}
var range(int n)
{
return scale((HH(n) - LL(n))/priceClose(0),100)/100;
}
///////////////////////////////////////////////////////////////////////
function run()
{
StartDate = 20140601;
BarPeriod = 60; // 1 hour
LookBack = 100;
WFOPeriod = 252*24; // 1 year
DataSplit = 90;
NumCores = -1;
set(RULES|LOGFILE|TESTNOW|PLOTNOW);
Spread = RollLong = RollShort = Commission = Slippage = 0;
LifeTime = 3;
if(Train) Hedge = 2;
///////////////////////////////////////////////////////////
if(adviseLong(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4)) > 0.5)
enterLong();
if(adviseShort() > 0.5)
enterShort();
PlotWidth = 800;
PlotHeight1 = 340;
ColorUp = ColorDn = ColorWin = ColorLoss = 0;
}
The corresponding part of the script runs in a run function, but some functions are outside this function, but are queried from it. Not okay? Not okay? [x] http://financial-hacker.com/scripts2016.zip
|
|
|
|