Call function with TimeFrame

Posted By: Grat

Call function with TimeFrame - 09/30/16 12:08

Hi,
I'm trying understand the TimeFrame and have this simple code:

Quote:

//--------------- Frame 10 ---------------
int Frame10(){
TimeFrame= 10;
static int nCount=0;
nCount++;

if (nCount > 6) { // <== line 7 order
enterShort();
nCount = 0;
}

return 0;
}

function run()
{
StartDate = 20160101;
EndDate=20160131;
set(LOGFILE);
BarPeriod = 1; // 1 minute bars
Hedge = 2;
Stop=1000*PIP;
TakeProfit=1000*PIP;

Frame10();
}


a) in code change on line 7:
with number 3-5-7... system not open orders...
with number 2-4-6... system open orders...
b) with 6 open but first order is a wrong time:

Quote:

Name,Type,Asset,ID,Lots,Open,Close,Entry,Exit,Profit,Roll,ExitType
xtest,Short,EUR/USD,9001,1,2016-01-04 00:30,2016-01-31 23:58,1.0848,1.0826,1.90,0.02,Sold
xtest,Short,EUR/USD,16002,1,2016-01-04 01:40,2016-01-31 23:58,1.0841,1.0826,1.30,0.02,Sold
xtest,Short,EUR/USD,23003,1,2016-01-04 02:50,2016-01-31 23:58,1.0868,1.0826,3.64,0.02,Sold
xtest,Short,EUR/USD,30004,1,2016-01-04 04:00,2016-01-31 23:58,1.0872,1.0826,4.00,0.02,Sold

Posted By: Grat

Re: Call function with TimeFrame - 10/03/16 02:51

HI,
from the manual
Workshop 6: Portfolio strategies. Money management.

Quote:
What does this mean? The trend trading strategy from workshop 4 used 60-minutes bars, while counter trend trading was based on 240-minutes bars. When we trade both together in the same script, we'll need both types of bars. The BarPeriod variable must not be changed at runtime, as it determines the sampling of the price curves. But the TimeFrame variable does the job. Alice has set BarPeriod to 60 minutes, so it needs a TimeFrame of 4 bars for getting the 240 minutes period for the counter trend strategy. TimeFrame affects all subsequent price and series calls, all indicators using those series, and the ATR function.


I have this code:

Quote:

//--------------- Frame 10 ---------------
int Frame10(){
TimeFrame= 60; // 60 minute ???

if (AlgoVar[0] > -2){
AlgoVar[0]--;
printf("\nDNT minute %d AlgoVar %.1f", minute(),AlgoVar[0]);

}else AlgoVar[0]=5;
return 0;
}

function run()
{
StartDate = 20160101;
EndDate=20160131;
set(LOGFILE);
BarPeriod = 1; // 1 minute bars
Hedge = 2;
Stop=1000*PIP;
TakeProfit=1000*PIP;
Frame10();
}


I got this result:

Quote:

DNT minute 3 AlgoVar 2.0
DNT minute 4 AlgoVar 1.0
DNT minute 5 AlgoVar 0.0
DNT minute 6 AlgoVar -1.0
DNT minute 7 AlgoVar -2.0
DNT minute 9 AlgoVar 4.0
DNT minute 10 AlgoVar 3.0
DNT minute 11 AlgoVar 2.0
DNT minute 12 AlgoVar 1.0
DNT minute 13 AlgoVar 0.0
DNT minute 14 AlgoVar -1.0
DNT minute 15 AlgoVar -2.0


function Frame10() is called every 1 minute bar and execute code inside. Except the indicator - this is a correct - call every 60 minute.
Posted By: jcl

Re: Call function with TimeFrame - 10/03/16 17:08

Working with time frames is described here: http://manual.zorro-project.com/barperiod.htm. If you want to call a function not at any bar, but only at the end of a time frame, use the frame() function.
Posted By: Grat

Re: Call function with TimeFrame - 10/03/16 17:58

Super,

thank's

laugh
© 2024 lite-C Forums