Code:switch( Name() ) { case "CCC": datecond = dn <= 1140201; break; case "EEE": datecond = dn >= 1141101; break; default: datecond = true; break; } period = 20; m = MA( Close, period ); Buy = Cross( Close, m ) AND datecond; Sell = Cross( m, Close ) AND datecond; Short = Cover = 0;
Variable dn stands for
Code:dn = DateNum();
datecond = dn < 1140101 OR dn > 1141231;
datecond = ( dn >= 1100101 AND dn < 1140101 ) OR dn >= 1150101;
I'm not sure whether I understand correctly.
But if you wanna exclude a certain period then simply extend upper mentioned datecond variable.
For example if you wanna exclude year 2014:
Code:datecond = dn < 1140101 OR dn > 1141231;
Or if you wanna set a specific date range before 2015 and then wanna proceed from 2015 onwards:
Code:datecond = ( dn >= 1100101 AND dn < 1140101 ) OR dn >= 1150101;
I'm not sure whether I understand correctly.
But if you wanna exclude a certain period then simply extend upper mentioned datecond variable.
For example if you wanna exclude year 2014:
Code:datecond = dn < 1140101 OR dn > 1141231;
Or if you wanna set a specific date range before 2015 and then wanna proceed from 2015 onwards:
Code:datecond = ( dn >= 1100101 AND dn < 1140101 ) OR dn >= 1150101;
dn = DateNum();
switch( Name() ) {
case "ACR": datecond = ( dn >= 1110302 AND dn < 1120821 ) ; break;
default: datecond = true; break;
}
period = 20;
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond;
Sell = Cross( m, Close ) AND datecond;
Short = Cover = 0;
Hi Trash, could I get some more help here, your code has given me 98% of my objective.
Code:dn = DateNum(); switch( Name() ) { case "ACR": datecond = ( dn >= 1110302 AND dn < 1120821 ) ; break; default: datecond = true; break; } period = 20; m = MA( Close, period ); Buy = Cross( Close, m ) AND datecond; Sell = Cross( m, Close ) AND datecond; Short = Cover = 0;
When I run this backtest for a period that goes after 21 August 2012, a trade initiated with a buy on 13 August 2012 does not close out and remains open.
How can I get the trade to close immediately after the symbol is removed, in this case on 21 August 2012.
dn = DateNum();
switch( Name() ) {
case "ACR":
enddate = 1120821;
datecond = ( dn >= 1110302 AND dn < enddate );
exitdatecond = dn >= enddate;
break;
default:
datecond = true;
exitdatecond = false;
break;
}
period = 20;
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond;
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond;
Short = Cover = 0;
Code:dn = DateNum(); switch( Name() ) { case "ACR": enddate = 1120821; datecond = ( dn >= 1110302 AND dn < enddate ); exitdatecond = dn >= enddate; break; default: datecond = true; exitdatecond = false; break; } period = 20; m = MA( Close, period ); Buy = Cross( Close, m ) AND datecond; Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond; Short = Cover = 0;
Thanks for that - it works a treat. Will continue with my testing but that has helped me out no end.
I will see whether I can develop this concept to allow me a second entry and exit.
dn = DateNum();
switch( Name() ) {
case "ACR":
enddate = 1120821;
datecond = ( dn >= 1110302 AND dn < enddate );
exitdatecond = dn >= enddate;
break;
case "ACR":
enddate1 = 1141231;
datecond1 = ( dn >= 1140101 AND dn < enddate1 );
exitdatecond1 = dn >= enddate1;
break;
default:
datecond = true;
exitdatecond = false;
datecond1 = true;
exitdatecond1 = false;
break;
}
period = 20;
m = MA( Close, period );
Buy = Cross( Close, m ) AND (datecond OR datecond1);
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond OR exitdatecond1;
Short = Cover = 0;
Hi TJW11,
Did you have any luck here, I've tried a number of attempts at coding the second entry/exit but with no success. I would be interested if you have an outcome.
CNHTractor - no I haven't been able to figure this out
// example by trash
// https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=122&p=878422&viewfull=1#post878422
dn = DateNum();
switch( Name() ) {
case "ACR":
enddate1 = 1120821;
reentry = 1140101;
enddate2 = 1141231;
//
datecond = ( dn >= 1110302 AND dn < enddate1 ) OR
( dn >= reentry AND dn < enddate2 );
//
exitdatecond1 = dn >= enddate1 AND dn < reentry;
exitdatecond2 = dn >= enddate2;
//
exitdatecond = exitdatecond1 OR exitdatecond2;
break;
default:
datecond = true;
exitdatecond = false;
break;
}
SetPositionSize( 1, spsShares );
period = 20;
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond;
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond;
Short = Cover = 0;
You have to use OR but not AND.
Code:// example by trash // https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=122&p=878422&viewfull=1#post878422 dn = DateNum(); switch( Name() ) { case "ACR": enddate1 = 1120821; reentry = 1140101; enddate2 = 1141231; // datecond = ( dn >= 1110302 AND dn < enddate1 ) OR ( dn >= reentry AND dn < enddate2 ); // exitdatecond1 = dn >= enddate1 AND dn < reentry; exitdatecond2 = dn >= enddate2; // exitdatecond = exitdatecond1 OR exitdatecond2; break; default: datecond = true; exitdatecond = false; break; } SetPositionSize( 1, spsShares ); period = 20; m = MA( Close, period ); Buy = Cross( Close, m ) AND datecond; Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond; Short = Cover = 0;
You have to use OR but not AND.
Code:// example by trash // https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=122&p=878422&viewfull=1#post878422 dn = DateNum(); switch( Name() ) { case "ACR": enddate1 = 1120821; reentry = 1140101; enddate2 = 1141231; // datecond = ( dn >= 1110302 AND dn < enddate1 ) OR ( dn >= reentry AND dn < enddate2 ); // exitdatecond1 = dn >= enddate1 AND dn < reentry; exitdatecond2 = dn >= enddate2; // exitdatecond = exitdatecond1 OR exitdatecond2; break; default: datecond = true; exitdatecond = false; break; } SetPositionSize( 1, spsShares ); period = 20; m = MA( Close, period ); Buy = Cross( Close, m ) AND datecond; Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond; Short = Cover = 0;
Entry1 AND Exit1 followed by ReEntry2 AND Exit2
Hello,
I have a small query in regards to downloading data for Indices through yahoo finance.
I have downloaded the data for australian stocks through Amiquote.
However, I wanted data for index such as - XAO.
I am not sure what ticker should be used. I have tried XAO.AX , AORD.AX, but it doesn't work. Amiquote still gives the error symbol not found.
Could someone please assist with this?
I just want to play around with some basic strategies, before I subscribe to Norgate's premium data.
Thank You
^AORD
Others :
^AXHJ
^AXFJ
^AXSO
Minor adjustment:
Replace line
if ( ! IsNull( fc[ 0 ] ) )
with
if ( ! IsNull( fc[ 0 ] ) && symbol != Name_ )
to avoid repeated symbol plotting
can this formula be scanned..??
Do you wanna output closes of a watchlist in Analysis or what do you mean?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?